60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
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 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";
|
|
|
|
export default function CaraouselHome() {
|
|
const { decryptToken, token } = useAuthSession()
|
|
const ref = React.useRef<ICarouselInstance>(null);
|
|
const width = Dimensions.get("window").width;
|
|
const progress = useSharedValue<number>(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) => dispatch(setEntities(data.data)))
|
|
}
|
|
|
|
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(() => {
|
|
handleBannerView()
|
|
}, [dispatch]);
|
|
|
|
useEffect(() => {
|
|
handleUser()
|
|
}, []);
|
|
|
|
return (
|
|
<View style={[Styles.mv15]}>
|
|
<Carousel
|
|
ref={ref}
|
|
width={width}
|
|
height={width / 2.5}
|
|
data={entities}
|
|
loop={true}
|
|
autoPlay={true}
|
|
autoPlayInterval={5000}
|
|
onProgressChange={progress}
|
|
renderItem={({ index }) => (
|
|
<Image
|
|
source={{ uri: `https://wibu-storage.wibudev.com/api/files/${entities[index].image}` }}
|
|
style={[Styles.caraoselContent]}
|
|
/>
|
|
)}
|
|
/>
|
|
</View>
|
|
)
|
|
} |