diff --git a/app/(application)/(user)/home.tsx b/app/(application)/(user)/home.tsx index 9d29187..b6c5996 100644 --- a/app/(application)/(user)/home.tsx +++ b/app/(application)/(user)/home.tsx @@ -12,23 +12,26 @@ import Home_ImageSection from "@/screens/Home/imageSection"; import TabSection from "@/screens/Home/tabSection"; import { tabsHome } from "@/screens/Home/tabsList"; import Home_FeatureSection from "@/screens/Home/topFeatureSection"; +import { apiJobGetAll } from "@/service/api-client/api-job"; import { apiUser } from "@/service/api-client/api-user"; import { apiVersion } from "@/service/api-config"; import { GStyles } from "@/styles/global-styles"; import { Ionicons } from "@expo/vector-icons"; import { Redirect, router, Stack, useFocusEffect } from "expo-router"; import { useCallback, useState } from "react"; -import { RefreshControl, TouchableOpacity, View } from "react-native"; +import { RefreshControl, View } from "react-native"; export default function Application() { const { token, user, userData } = useAuth(); const [data, setData] = useState(); const [refreshing, setRefreshing] = useState(false); const { syncUnreadCount } = useNotificationStore(); + const [listData, setListData] = useState(null); useFocusEffect( useCallback(() => { onLoadData(); + onLoadDataJob(); checkVersion(); userData(token as string).catch((error) => { console.log("[ERROR userData]", error?.message); @@ -50,6 +53,29 @@ export default function Application() { } } + const onLoadDataJob = async () => { + try { + const response = await apiJobGetAll({ + category: "beranda", + }); + const result = response.data + .sort( + (a: any, b: any) => + new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime() + ) + .slice(0, 2); + setListData(result); + } catch (error) { + console.log("[ERROR]", error); + } + }; + + useFocusEffect( + useCallback(() => { + onLoadData(); + }, []) + ); + const checkVersion = async () => { try { const response = await apiVersion(); @@ -62,12 +88,13 @@ export default function Application() { const onRefresh = useCallback(() => { setRefreshing(true); onLoadData(); + onLoadDataJob(); checkVersion(); setRefreshing(false); }, []); if (data && data?.active === false) { - console.log("User is not active"); + console.warn("User is not active"); return ( @@ -76,7 +103,7 @@ export default function Application() { } if (data && data?.Profile === null) { - console.log("Profile is null"); + console.warn("Profile is null"); return ( @@ -170,7 +197,7 @@ export default function Application() { )} {data ? ( - + ) : ( )} diff --git a/app/(application)/(user)/profile/[id]/index.tsx b/app/(application)/(user)/profile/[id]/index.tsx index a7eda85..06c3339 100644 --- a/app/(application)/(user)/profile/[id]/index.tsx +++ b/app/(application)/(user)/profile/[id]/index.tsx @@ -1,7 +1,6 @@ /* eslint-disable react-hooks/exhaustive-deps */ -import { LoaderCustom, StackCustom } from "@/components"; +import { NewWrapper, StackCustom } from "@/components"; import CustomSkeleton from "@/components/_ShareComponent/SkeletonCustom"; -import ViewWrapper from "@/components/_ShareComponent/ViewWrapper"; import LeftButtonCustom from "@/components/Button/BackButton"; import DrawerCustom from "@/components/Drawer/DrawerCustom"; import { MainColor } from "@/constants/color-palet"; @@ -17,8 +16,8 @@ import { GStyles } from "@/styles/global-styles"; import { IProfile } from "@/types/Type-Profile"; import { Ionicons } from "@expo/vector-icons"; import { Stack, useFocusEffect, useLocalSearchParams } from "expo-router"; -import React, { useCallback, useState } from "react"; -import { TouchableOpacity } from "react-native"; +import { useCallback, useState } from "react"; +import { RefreshControl, TouchableOpacity } from "react-native"; export default function Profile() { const { id } = useLocalSearchParams(); @@ -26,6 +25,7 @@ export default function Profile() { const [data, setData] = useState(); const [dataToken, setDataToken] = useState(); const [listPortofolio, setListPortofolio] = useState(); + const [refreshing, setRefreshing] = useState(false); const { token, logout, isAdmin, user, userData } = useAuth(); @@ -55,13 +55,21 @@ export default function Profile() { }; const onLoadData = async (id: string) => { - const response = await apiProfile({ id: id }); - setData(response.data); + try { + const response = await apiProfile({ id: id }); + setData(response.data); + } catch (error) { + console.log("[ERROR onLoadData]", error); + } }; const onLoadUserByToken = async () => { - const response = await apiUser(user?.id as string); - setDataToken(response?.data?.Profile); + try { + const response = await apiUser(user?.id as string); + setDataToken(response?.data?.Profile); + } catch (error) { + console.log("[ERROR onLoadUserByToken]", error); + } }; const onLoadPortofolio = async (id: string) => { @@ -75,10 +83,20 @@ export default function Profile() { .slice(0, 2); setListPortofolio(lastTwoByDate); } catch (error) { - console.log("[ERROR]", error); + console.log("[ERROR onLoadPortofolio]", error); } }; + const onRefresh = useCallback(() => { + setRefreshing(true); + onLoadData(id as string); + onLoadPortofolio(id as string); + onLoadUserByToken(); + isUserCheck(); + userData(token as string); + setRefreshing(false); + }, [id, token]); + return ( <> {/* Main View */} - + + } + > {!data || !dataToken ? ( @@ -114,7 +141,7 @@ export default function Profile() { /> )} - + {/* Drawer Komponen Eksternal */} (null); const [loadList, setLoadList] = useState(false); @@ -72,74 +54,30 @@ export default function AdminMaps() { } }; + const markers: MapMarker[] = list?.map((item) => ({ + id: item.id, + coordinate: [item.longitude, item.latitude] as [number, number], + imageId: item.Portofolio?.logoId, + onSelected: () => { + setOpenDrawer(true); + setSelected({ + id: item?.id, + bidangBisnis: item?.Portofolio?.MasterBidangBisnis?.name, + nomorTelepon: item?.Portofolio?.tlpn, + alamatBisnis: item?.Portofolio?.alamatKantor, + namePin: item?.namePin, + imageId: item?.imageId, + portofolioId: item?.Portofolio?.id, + latitude: item?.latitude, + longitude: item?.longitude, + }); + }, + })) || []; + return ( <> - {/* */} - - {loadList ? ( - - ) : ( - - {list?.map((item: any, index: number) => { - return ( - { - setOpenDrawer(true); - setSelected({ - id: item?.id, - bidangBisnis: - item?.Portofolio?.MasterBidangBisnis?.name, - nomorTelepon: item?.Portofolio?.tlpn, - alamatBisnis: item?.Portofolio?.alamatKantor, - namePin: item?.namePin, - imageId: item?.imageId, - portofolioId: item?.Portofolio?.id, - latitude: item?.latitude, - longitude: item?.longitude, - }); - }} - // Gunakan gambar kustom jika tersedia - > - - - - - ); - })} - - )} - + setOpenDrawer(false)} height={"auto"} > - + {selected.imageId && ( + + )} (null); - - const onLoadData = async () => { - try { - const response = await apiJobGetAll({ - category: "beranda", - }); - - console.log("[DATA JOB]", JSON.stringify(response.data, null, 2)); - const result = response.data - .sort( - (a: any, b: any) => - new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime() - ) - .slice(0, 2); - setListData(result); - } catch (error) { - console.log("[ERROR]", error); - } - }; - - useFocusEffect( - useCallback(() => { - onLoadData(); - }, []) - ); +export default function Home_BottomFeatureSection({ + listData, +}: { + listData: any[] | null; +}) { return ( <> router.push("/job")}> diff --git a/screens/UserSeach/MainView_V2.tsx b/screens/UserSeach/MainView_V2.tsx index 0be71d8..9632072 100644 --- a/screens/UserSeach/MainView_V2.tsx +++ b/screens/UserSeach/MainView_V2.tsx @@ -139,8 +139,8 @@ export default function UserSearchMainView_V2() { searchQuery: search, emptyMessage: "Tidak ada pengguna ditemukan", emptySearchMessage: "Tidak ada hasil pencarian", - skeletonCount: 5, - skeletonHeight: 150, + skeletonCount: PAGINATION_DEFAULT_TAKE, + skeletonHeight: 100, loadingFooterText: "Memuat lebih banyak pengguna...", isInitialLoad, });