From fb6508db9b07e52a77600842aaf810364d02ed19 Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Wed, 19 Mar 2025 10:31:38 +0800 Subject: [PATCH] fix admin: - API map --- .../admin/map/fun/fun_get_all_maps.ts | 1 + src/app_modules/admin/map/ui/ui_map_view.tsx | 144 ++++++++++-------- src/app_modules/admin/map/view/view.tsx | 3 - 3 files changed, 85 insertions(+), 63 deletions(-) diff --git a/src/app_modules/admin/map/fun/fun_get_all_maps.ts b/src/app_modules/admin/map/fun/fun_get_all_maps.ts index 67c79d0f..3c951824 100644 --- a/src/app_modules/admin/map/fun/fun_get_all_maps.ts +++ b/src/app_modules/admin/map/fun/fun_get_all_maps.ts @@ -9,6 +9,7 @@ export async function adminMap_funGetAllMaps() { }, where: { isActive: true, + }, include: { Portofolio: true, diff --git a/src/app_modules/admin/map/ui/ui_map_view.tsx b/src/app_modules/admin/map/ui/ui_map_view.tsx index 85a48d63..eaff941c 100644 --- a/src/app_modules/admin/map/ui/ui_map_view.tsx +++ b/src/app_modules/admin/map/ui/ui_map_view.tsx @@ -1,13 +1,16 @@ "use client"; -import { APIs } from "@/lib"; import { AccentColor } from "@/app_modules/_global/color/color_pallet"; +import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; +import { apiGetAllMap } from "@/app_modules/map/lib/api_map"; import { defaultLatLong, defaultMapZoom, } from "@/app_modules/map/lib/default_lat_long"; -import { MODEL_MAP } from "@/app_modules/map/lib/interface"; +import { IDataMap } from "@/app_modules/map/lib/type_map"; +import { APIs } from "@/lib"; import { Avatar, Stack } from "@mantine/core"; +import { useShallowEffect } from "@mantine/hooks"; import "mapbox-gl/dist/mapbox-gl.css"; import { useState } from "react"; import Map, { @@ -21,14 +24,31 @@ import { ComponentAdminMap_Drawer } from "../component"; export function UiAdminMap_MapBoxView({ mapboxToken, - dataMap, }: { mapboxToken: string; - dataMap: MODEL_MAP[]; }) { const [mapId, setMapId] = useState(""); const [openDrawer, setOpenDrawer] = useState(false); - const [data, setData] = useState(dataMap); + const [data, setData] = useState([]); + const [loading, setLoading] = useState(false); + + useShallowEffect(() => { + onLoadData(); + }, []); + + async function onLoadData() { + try { + setLoading(true); + const response = await apiGetAllMap(); + if (response) { + setData(response.data); + } + } catch (error) { + console.error(error); + } finally { + setLoading(false); + } + } if (!mapboxToken) return ; @@ -42,65 +62,69 @@ export function UiAdminMap_MapBoxView({ backgroundColor: "gray", }} > - - {data.map((e, i) => ( - - - { - setMapId(e.id); - setOpenDrawer(true); + {loading ? ( + + ) : ( + + {data.map((e, i) => ( + + - { + setMapId(e.id); + setOpenDrawer(true); }} - src={ - e.pinId === null - ? APIs.GET({ fileId: e.Portofolio.logoId, size: "300" }) - : APIs.GET({ fileId: e.pinId, size: "300" }) - } - /> - - - - ))} + > + + + + + ))} - - - - + + + + + )} );