Deskripsi:
- Di beranda diganti menggunakan API
- Skeleton beranda
- V 1.2.25
This commit is contained in:
2024-12-12 14:46:06 +08:00
parent 80b6d35fe9
commit d1f7966123
15 changed files with 253 additions and 168 deletions

View File

@@ -4,20 +4,24 @@ import { gs_jobTiggerBeranda } 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 { Center, Loader, Stack, TextInput } from "@mantine/core";
import { Box, 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 { useEffect, useState } from "react";
import { useState } from "react";
import {
Job_ComponentButtonUpdateBeranda,
Job_ComponentSkeletonBeranda,
} from "../../component";
import ComponentJob_BerandaCardView from "../../component/beranda/card_view";
import { job_getAllListPublish } from "../../fun/get/get_all_publish";
import { MODEL_JOB } from "../../model/interface";
import { Job_ComponentButtonUpdateBeranda } from "../../component";
import { API_RouteJob } from "@/app/lib/api_user_router/route_api_job";
export function Job_UiBeranda({ listData }: { listData: MODEL_JOB[] }) {
const [data, setData] = useState(listData);
export function Job_UiBeranda() {
const [data, setData] = useState<MODEL_JOB[] | null>(null);
const [activePage, setActivePage] = useState(1);
const [isSearch, setIsSearch] = useState("");
@@ -26,19 +30,16 @@ export function Job_UiBeranda({ listData }: { listData: MODEL_JOB[] }) {
const [isTriggerJob, setIsTriggerJob] = useAtom(gs_jobTiggerBeranda);
useShallowEffect(() => {
onLoadNewData({
onLoad(val) {
setData(val);
},
});
}, [setData]);
if (isTriggerJob == true) {
setIsShowUpdate(true);
}
}, [isTriggerJob]);
useShallowEffect(() => {
if (isTriggerJob) {
setIsShowUpdate(true);
// setIsTriggerJob(false);
}
}, [isTriggerJob, setIsShowUpdate]);
setIsTriggerJob(false);
setIsShowUpdate(false);
onLoadNewData();
}, []);
async function onSearch(text: string) {
setIsSearch(text);
@@ -50,9 +51,11 @@ export function Job_UiBeranda({ listData }: { listData: MODEL_JOB[] }) {
setActivePage(1);
}
async function onLoadNewData({ onLoad }: { onLoad: (val: any) => void }) {
const loadData = await job_getAllListPublish({ page: 1 });
onLoad(loadData);
async function onLoadNewData() {
const loadData = await fetch(API_RouteJob.get_all({ page: activePage }));
const res = await loadData.json();
setData(res.data);
}
return (
@@ -62,6 +65,7 @@ export function Job_UiBeranda({ listData }: { listData: MODEL_JOB[] }) {
<Job_ComponentButtonUpdateBeranda
onSetIsNewPost={(val) => {
setIsShowUpdate(val);
setIsTriggerJob(val);
}}
onSetData={(val: any[]) => {
setData(val);
@@ -85,7 +89,9 @@ export function Job_UiBeranda({ listData }: { listData: MODEL_JOB[] }) {
}}
/>
{_.isEmpty(data) ? (
{_.isNull(data) ? (
<Job_ComponentSkeletonBeranda />
) : _.isEmpty(data) ? (
<ComponentGlobal_IsEmptyData />
) : (
// --- Main component --- //
@@ -97,7 +103,7 @@ export function Job_UiBeranda({ listData }: { listData: MODEL_JOB[] }) {
</Center>
)}
data={data}
setData={setData}
setData={setData as any}
moreData={async () => {
const loadData = await job_getAllListPublish({
page: activePage + 1,

View File

@@ -1,10 +1,10 @@
import { MODEL_JOB } from "../../model/interface";
import { Job_UiBeranda } from "./ui_beranda";
export default function Job_ViewBeranda({ listJob }: { listJob: MODEL_JOB[] }) {
export default function Job_ViewBeranda() {
return (
<>
<Job_UiBeranda listData={listJob} />
<Job_UiBeranda />
</>
);
}