Fix: Job
Deskripsi: - Fix notifikasi admin to user - Fix trigger autoload
This commit is contained in:
@@ -8,17 +8,20 @@ export function Job_ComponentButtonUpdateBeranda({
|
||||
onSetData,
|
||||
onSetIsNewPost,
|
||||
}: {
|
||||
onSetData: (val: any) => void;
|
||||
onSetData: (val : {data: any[]}) => void;
|
||||
onSetIsNewPost: (val: any) => void;
|
||||
}) {
|
||||
const [scroll, scrollTo] = useWindowScroll();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
async function onLoadData() {
|
||||
setIsLoading(true)
|
||||
const loadData = await job_getAllListPublish({ page: 1 });
|
||||
|
||||
if (loadData) {
|
||||
onSetData(loadData);
|
||||
onSetData({
|
||||
data: loadData,
|
||||
});
|
||||
onSetIsNewPost(false);
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
@@ -1,33 +1,38 @@
|
||||
"use client";
|
||||
|
||||
import { gs_job_trigger } from "@/app/lib/global_state";
|
||||
import { RouterJob } from "@/app/lib/router_hipmi/router_job";
|
||||
import ComponentGlobal_CreateButton from "@/app_modules/_global/component/button_create";
|
||||
import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data";
|
||||
import {
|
||||
Affix,
|
||||
Button,
|
||||
Center,
|
||||
Loader,
|
||||
rem,
|
||||
Stack,
|
||||
TextInput,
|
||||
} from "@mantine/core";
|
||||
import { Center, Loader, Stack, TextInput } from "@mantine/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { IconSearch } from "@tabler/icons-react";
|
||||
import { useAtom } from "jotai";
|
||||
import _ from "lodash";
|
||||
import { ScrollOnly } from "next-scroll-loader";
|
||||
import { useState } from "react";
|
||||
import ComponentJob_BerandaCardView from "../../component/beranda/card_view";
|
||||
import { job_getAllListPublish } from "../../fun/get/get_all_publish";
|
||||
import { MODEL_JOB } from "../../model/interface";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import mqtt_client from "@/util/mqtt_client";
|
||||
import { Job_ComponentButtonUpdateBeranda } from "../../component";
|
||||
|
||||
export function Job_UiBeranda({ listData }: { listData: MODEL_JOB[] }) {
|
||||
const [data, setData] = useState(listData);
|
||||
const [activePage, setActivePage] = useState(1);
|
||||
const [isSearch, setIsSearch] = useState("");
|
||||
const [isNewPost, setIsNewPost] = useState(false);
|
||||
// const [isNewPost, setIsNewPost] = useState(false);
|
||||
const [triggerJob, setTriggerJob] = useAtom(gs_job_trigger);
|
||||
|
||||
useShallowEffect(() => {
|
||||
if (triggerJob) {
|
||||
// setIsNewPost(true);
|
||||
setTriggerJob(false);
|
||||
onLoadNewData({
|
||||
onLoad(val) {
|
||||
setData(val);
|
||||
},
|
||||
});
|
||||
}
|
||||
}, [triggerJob, setData]);
|
||||
|
||||
async function onSearch(text: string) {
|
||||
setIsSearch(text);
|
||||
@@ -39,21 +44,6 @@ export function Job_UiBeranda({ listData }: { listData: MODEL_JOB[] }) {
|
||||
setActivePage(1);
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
onLoadNewData({
|
||||
onLoad(val) {
|
||||
setData(val);
|
||||
},
|
||||
});
|
||||
|
||||
mqtt_client.subscribe("Job_new_post");
|
||||
mqtt_client.on("message", (topic, message) => {
|
||||
if (topic === "Job_new_post") {
|
||||
setIsNewPost(true);
|
||||
}
|
||||
});
|
||||
}, [setIsNewPost, setData]);
|
||||
|
||||
async function onLoadNewData({ onLoad }: { onLoad: (val: any) => void }) {
|
||||
const loadData = await job_getAllListPublish({ page: 1 });
|
||||
onLoad(loadData);
|
||||
@@ -62,12 +52,17 @@ export function Job_UiBeranda({ listData }: { listData: MODEL_JOB[] }) {
|
||||
return (
|
||||
<>
|
||||
<Stack my={1} spacing={30}>
|
||||
{isNewPost && (
|
||||
{/* {isNewPost && (
|
||||
<Job_ComponentButtonUpdateBeranda
|
||||
onSetIsNewPost={(val) => setIsNewPost(val)}
|
||||
onSetData={(val) => setData(val)}
|
||||
onSetIsNewPost={(val) => {
|
||||
setIsNewPost(val);
|
||||
}}
|
||||
onSetData={(val: { data: any[] }) => {
|
||||
setData(val.data);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
)} */}
|
||||
|
||||
<ComponentGlobal_CreateButton path={RouterJob.create} />
|
||||
|
||||
<TextInput
|
||||
@@ -102,6 +97,8 @@ export function Job_UiBeranda({ listData }: { listData: MODEL_JOB[] }) {
|
||||
page: activePage + 1,
|
||||
search: isSearch,
|
||||
});
|
||||
console.log(loadData, "load daat");
|
||||
|
||||
setActivePage((val) => val + 1);
|
||||
|
||||
return loadData;
|
||||
|
||||
Reference in New Issue
Block a user