import { ConstEnv } from "@/constants/ConstEnv"; import Styles from "@/constants/Styles"; import { apiGetBanner, apiGetProfile } from "@/lib/api"; import { setEntities } from "@/lib/bannerSlice"; import { setEntityUser } from "@/lib/userSlice"; import { useAuthSession } from "@/providers/AuthProvider"; import { useTheme } from "@/providers/ThemeProvider"; import { AntDesign, Feather, FontAwesome5, Ionicons, MaterialCommunityIcons, MaterialIcons, } from "@expo/vector-icons"; import { router } from "expo-router"; import React, { useEffect } from "react"; import { Dimensions, Image, View } from "react-native"; import { useSharedValue } from "react-native-reanimated"; import Carousel, { ICarouselInstance } from "react-native-reanimated-carousel"; import { useDispatch, useSelector } from "react-redux"; import { ButtonFiturMenu } from "../buttonFiturMenu"; import Text from "../Text"; export default function CaraouselHome2({ refreshing }: { refreshing: boolean }) { const { decryptToken, token } = useAuthSession() const { colors } = useTheme(); const ref = React.useRef(null); const width = Dimensions.get("window").width; const progress = useSharedValue(0); const dispatch = useDispatch() const entities = useSelector((state: any) => state.banner) const entityUser = useSelector((state: any) => state.user) async function handleBannerView() { const hasil = await decryptToken(String(token?.current)) apiGetBanner({ user: hasil }).then((data) => { if (data.data.length > 0) { dispatch(setEntities(data.data)) } else { dispatch(setEntities([])) } }) } async function handleUser() { const hasil = await decryptToken(String(token?.current)) const response = await apiGetProfile({ id: hasil }) dispatch(setEntityUser({ role: response.data.idUserRole, admin: false })) } useEffect(() => { if (refreshing) handleBannerView() }, [refreshing]); useEffect(() => { handleBannerView() }, [dispatch]); useEffect(() => { handleUser() }, []); return ( {/* WRAPPER CAROUSEL */} {entities.length > 0 ? ( ( )} /> ) : ( BANNER )} {/* FITUR */} } text="Divisi" onPress={() => router.push('/division?active=true')} /> } text="Kegiatan" onPress={() => router.push('/project?status=0')} /> } text="Pengumuman" onPress={() => router.push('/announcement')} /> } text="Semua" onPress={() => router.push('/feature')} /> ) }