import Styles from "@/constants/Styles"; import { apiGetDivisionOneFeature } from "@/lib/api"; import { useAuthSession } from "@/providers/AuthProvider"; import { useTheme } from "@/providers/ThemeProvider"; import { router, useLocalSearchParams } from "expo-router"; import { useEffect, useState } from "react"; import { View } from "react-native"; import Text from "../Text"; import DiscussionItem from "../discussionItem"; import Skeleton from "../skeleton"; type Props = { id: string; title: string; desc: string; user: string; date: string; }; export default function DiscussionDivisionDetail({ refreshing }: { refreshing: boolean }) { const { colors } = useTheme(); const { token, decryptToken } = useAuthSession(); const { id } = useLocalSearchParams<{ id: string }>(); const [data, setData] = useState([]); const [loading, setLoading] = useState(true) async function handleLoad(loading: boolean) { try { setLoading(loading) const hasil = await decryptToken(String(token?.current)); const response = await apiGetDivisionOneFeature({ user: hasil, id, cat: "new-discussion", }); setData(response.data); } catch (error) { console.error(error); } finally { setLoading(false) } } useEffect(() => { if (refreshing) handleLoad(false) }, [refreshing]) useEffect(() => { handleLoad(true) }, []) return ( Diskusi { loading ? <> : data.length > 0 ? ( data.map((item, index) => ( { router.push(`/division/${id}/discussion/${item.id}`); }} /> )) ) : ( Tidak ada diskusi ) } ); }