upd: load scroll
Deskripsi: - kegiatan - divisi - tugas divisi - diskusi - history kalender No Issues
This commit is contained in:
@@ -10,7 +10,7 @@ import { useAuthSession } from "@/providers/AuthProvider";
|
||||
import { AntDesign, Feather, Ionicons } from "@expo/vector-icons";
|
||||
import { router, useLocalSearchParams } from "expo-router";
|
||||
import { useEffect, useState } from "react";
|
||||
import { SafeAreaView, ScrollView, Text, View } from "react-native";
|
||||
import { Text, View, VirtualizedList } from "react-native";
|
||||
import { useSelector } from "react-redux";
|
||||
|
||||
|
||||
@@ -35,61 +35,97 @@ export default function DiscussionDivision() {
|
||||
const update = useSelector((state: any) => state.discussionUpdate);
|
||||
const [loading, setLoading] = useState(true)
|
||||
const arrSkeleton = Array.from({ length: 5 })
|
||||
const [page, setPage] = useState(1)
|
||||
const [waiting, setWaiting] = useState(false)
|
||||
|
||||
async function handleLoad(loading: boolean) {
|
||||
async function handleLoad(loading: boolean, thisPage: number) {
|
||||
try {
|
||||
setWaiting(true)
|
||||
setLoading(loading)
|
||||
setPage(thisPage)
|
||||
const hasil = await decryptToken(String(token?.current))
|
||||
const response = await apiGetDiscussion({ user: hasil, search, division: id, active })
|
||||
setData(response.data)
|
||||
const response = await apiGetDiscussion({ user: hasil, search, division: id, active, page: thisPage })
|
||||
if (thisPage == 1) {
|
||||
setData(response.data)
|
||||
} else if (thisPage > 1 && response.data.length > 0) {
|
||||
setData([...data, ...response.data])
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
setWaiting(false)
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
handleLoad(false)
|
||||
handleLoad(false, 1)
|
||||
}, [update.data])
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
handleLoad(true)
|
||||
handleLoad(true, 1)
|
||||
}, [active, search])
|
||||
|
||||
const loadMoreData = () => {
|
||||
if (waiting) return
|
||||
setTimeout(() => {
|
||||
handleLoad(false, page + 1)
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
const getItem = (_data: unknown, index: number): Props => ({
|
||||
id: data[index].id,
|
||||
title: data[index].title,
|
||||
desc: data[index].desc,
|
||||
status: data[index].status,
|
||||
user_name: data[index].user_name,
|
||||
img: data[index].img,
|
||||
total_komentar: data[index].total_komentar,
|
||||
createdAt: data[index].createdAt,
|
||||
isActive: data[index].isActive,
|
||||
})
|
||||
|
||||
return (
|
||||
<SafeAreaView>
|
||||
<ScrollView>
|
||||
<View style={[Styles.p15, Styles.mb100]}>
|
||||
<View style={[Styles.wrapBtnTab]}>
|
||||
<ButtonTab
|
||||
active={active == "false" ? "false" : "true"}
|
||||
value="true"
|
||||
onPress={() => { router.replace('./discussion?active=true') }}
|
||||
label="Aktif"
|
||||
icon={<Feather name="check-circle" color={active == "false" ? 'black' : 'white'} size={20} />}
|
||||
n={2} />
|
||||
<ButtonTab
|
||||
active={active == "false" ? "false" : "true"}
|
||||
value="false"
|
||||
onPress={() => { router.replace('./discussion?active=false') }}
|
||||
label="Arsip"
|
||||
icon={<AntDesign name="closecircleo" color={active == "true" ? 'black' : 'white'} size={20} />}
|
||||
n={2} />
|
||||
</View>
|
||||
<InputSearch onChange={setSearch} />
|
||||
<View>
|
||||
{
|
||||
loading ?
|
||||
arrSkeleton.map((item: any, i: number) => {
|
||||
<View style={[Styles.p15, { flex: 1 }]}>
|
||||
<View>
|
||||
<View style={[Styles.wrapBtnTab]}>
|
||||
<ButtonTab
|
||||
active={active == "false" ? "false" : "true"}
|
||||
value="true"
|
||||
onPress={() => { router.replace('./discussion?active=true') }}
|
||||
label="Aktif"
|
||||
icon={<Feather name="check-circle" color={active == "false" ? 'black' : 'white'} size={20} />}
|
||||
n={2} />
|
||||
<ButtonTab
|
||||
active={active == "false" ? "false" : "true"}
|
||||
value="false"
|
||||
onPress={() => { router.replace('./discussion?active=false') }}
|
||||
label="Arsip"
|
||||
icon={<AntDesign name="closecircleo" color={active == "true" ? 'black' : 'white'} size={20} />}
|
||||
n={2} />
|
||||
</View>
|
||||
<InputSearch onChange={setSearch} />
|
||||
</View>
|
||||
|
||||
<View style={[{ flex: 2 }]}>
|
||||
{
|
||||
loading ?
|
||||
arrSkeleton.map((item: any, i: number) => {
|
||||
return (
|
||||
<SkeletonContent key={i} />
|
||||
)
|
||||
})
|
||||
:
|
||||
data.length > 0 ?
|
||||
<VirtualizedList
|
||||
data={data}
|
||||
getItemCount={() => data.length}
|
||||
getItem={getItem}
|
||||
renderItem={({ item, index }: { item: Props, index: number }) => {
|
||||
return (
|
||||
<SkeletonContent key={i} />
|
||||
)
|
||||
})
|
||||
:
|
||||
data.length > 0 ?
|
||||
data.map((item, index) => (
|
||||
<BorderBottomItem
|
||||
key={index}
|
||||
width={55}
|
||||
@@ -112,15 +148,43 @@ export default function DiscussionDivision() {
|
||||
}
|
||||
rightBottomInfo={item.total_komentar + ' Komentar'}
|
||||
/>
|
||||
))
|
||||
:
|
||||
(
|
||||
<Text style={[Styles.textDefault, Styles.cGray, Styles.mv10, { textAlign: "center" }]}>Tidak ada diskusi</Text>
|
||||
)
|
||||
}
|
||||
</View>
|
||||
</View>
|
||||
</ScrollView>
|
||||
</SafeAreaView>
|
||||
}}
|
||||
keyExtractor={(item, index) => String(index)}
|
||||
onEndReached={loadMoreData}
|
||||
onEndReachedThreshold={0.5}
|
||||
showsVerticalScrollIndicator={false}
|
||||
/>
|
||||
// data.map((item, index) => (
|
||||
// <BorderBottomItem
|
||||
// key={index}
|
||||
// width={55}
|
||||
// onPress={() => { router.push(`./discussion/${item.id}`) }}
|
||||
// borderType="bottom"
|
||||
// icon={
|
||||
// <ImageUser src={`https://wibu-storage.wibudev.com/api/files/${item.img}`} size="sm" />
|
||||
// }
|
||||
// title={item.user_name}
|
||||
// subtitle={
|
||||
// active == "true" ? item.status == 1 ? <LabelStatus category='success' text='BUKA' size="small" /> : <LabelStatus category='error' text='TUTUP' size="small" /> : <></>
|
||||
// }
|
||||
// rightTopInfo={item.createdAt}
|
||||
// desc={item.desc}
|
||||
// leftBottomInfo={
|
||||
// <View style={[Styles.rowItemsCenter]}>
|
||||
// <Ionicons name="chatbox-ellipses-outline" size={18} color="grey" style={Styles.mr05} />
|
||||
// <Text style={[Styles.textInformation, Styles.cGray, Styles.mb05]}>Diskusikan</Text>
|
||||
// </View>
|
||||
// }
|
||||
// rightBottomInfo={item.total_komentar + ' Komentar'}
|
||||
// />
|
||||
// ))
|
||||
:
|
||||
(
|
||||
<Text style={[Styles.textDefault, Styles.cGray, Styles.mv10, { textAlign: "center" }]}>Tidak ada diskusi</Text>
|
||||
)
|
||||
}
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user