upd: skeleton loading

Deskripsi:
- home
- list lembaga desa
- list jabatan
- list member
- detail member

No Issues
This commit is contained in:
amel
2025-06-02 17:25:52 +08:00
parent d9a9c821ea
commit 36294ec4eb
13 changed files with 410 additions and 214 deletions

View File

@@ -6,6 +6,7 @@ import DrawerBottom from "@/components/drawerBottom";
import { InputForm } from "@/components/inputForm";
import InputSearch from "@/components/inputSearch";
import MenuItemRow from "@/components/menuItemRow";
import SkeletonTwoItem from "@/components/skeletonTwoItem";
import { ColorsStatus } from "@/constants/ColorsStatus";
import Styles from "@/constants/Styles";
import { apiDeleteGroup, apiEditGroup, apiGetGroup } from "@/lib/api";
@@ -30,6 +31,8 @@ export default function Index() {
const [isVisibleEdit, setVisibleEdit] = useState(false)
const [data, setData] = useState<Props[]>([])
const [search, setSearch] = useState('')
const arrSkeleton = Array.from({ length: 5 }, (_, index) => index)
const [loading, setLoading] = useState(true)
const [idChoose, setIdChoose] = useState('')
const [activeChoose, setActiveChoose] = useState(true)
@@ -67,19 +70,28 @@ export default function Index() {
}
}
async function handleLoad() {
async function handleLoad(loading: boolean) {
try {
setLoading(loading)
const hasil = await decryptToken(String(token?.current))
const response = await apiGetGroup({ user: hasil, active: String(active), search: search })
setData(response.data)
} catch (error) {
console.error(error)
} finally {
setLoading(false)
}
}
useEffect(() => {
handleLoad()
}, [active, search, update])
handleLoad(true)
}, [active, search])
useEffect(() => {
handleLoad(false)
}, [update])
return (
<SafeAreaView>
@@ -89,14 +101,14 @@ export default function Index() {
<ButtonTab
active={active == "false" ? "false" : "true"}
value="true"
onPress={() => { router.push('/group?active=true') }}
onPress={() => { router.replace('/group?active=true') }}
label="Aktif"
icon={<Feather name="check-circle" color={active == "true" ? 'white' : 'black'} size={20} />}
n={2} />
<ButtonTab
active={active == "false" ? "false" : "true"}
value="false"
onPress={() => { router.push('/group?active=false') }}
onPress={() => { router.replace('/group?active=false') }}
label="Tidak Aktif"
icon={<AntDesign name="closecircleo" color={active == "false" ? 'white' : 'black'} size={20} />}
n={2} />
@@ -104,6 +116,14 @@ export default function Index() {
<InputSearch onChange={setSearch} />
<View>
{
loading ?
arrSkeleton.map((item, index) => {
return (
<SkeletonTwoItem key={index} />
)
})
:
data.length > 0 ?
data.map((item, index) => {
return (

View File

@@ -1,12 +1,14 @@
import ButtonBackHeader from "@/components/buttonBackHeader";
import ImageUser from "@/components/imageNew";
import ItemDetailMember from "@/components/itemDetailMember";
import HeaderRightMemberDetail from "@/components/member/headerMemberDetail";
import Skeleton from "@/components/skeleton";
import { valueRoleUser } from "@/constants/RoleUser";
import Styles from "@/constants/Styles";
import { apiGetProfile } from "@/lib/api";
import { router, Stack, useLocalSearchParams } from "expo-router";
import { useEffect, useState } from "react";
import { Image, SafeAreaView, ScrollView, Text, View } from "react-native";
import { SafeAreaView, ScrollView, Text, View } from "react-native";
import { useSelector } from "react-redux";
type Props = {
@@ -29,14 +31,19 @@ export default function MemberDetail() {
const [error, setError] = useState(false)
const entityUser = useSelector((state: any) => state.user)
const [isEdit, setEdit] = useState(true)
const arrSkeleton = Array.from({ length: 5 }, (_, index) => index)
const [loading, setLoading] = useState(true)
async function handleLoad() {
try {
setLoading(true)
const response = await apiGetProfile({ id: id })
setData(response.data)
setEdit(valueRoleUser.filter((v) => v.login == entityUser.role)[0]?.data.some((i: any) => i.id == response.data.idUserRole))
} catch (error) {
console.error(error)
} finally {
setLoading(false)
}
}
@@ -59,24 +66,44 @@ export default function MemberDetail() {
<ScrollView>
<View style={{ flexDirection: 'column' }}>
<View style={[Styles.wrapHeadViewMember]}>
<Image
source={error ? require("../../../assets/images/user.jpg") : { uri: `https://wibu-storage.wibudev.com/api/files/${data?.img}` }}
onError={() => { setError(true) }}
style={[Styles.userProfileBig]}
/>
{
loading ?
<>
<Skeleton width={100} height={100} borderRadius={100} />
<Skeleton width={200} height={10} borderRadius={5} />
<Skeleton width={150} height={10} borderRadius={5} />
</>
:
<>
<ImageUser src={`https://wibu-storage.wibudev.com/api/files/${data?.img}`} size="lg" />
<Text style={[Styles.textSubtitle, Styles.cWhite, Styles.mt10]}>{data?.name}</Text>
<Text style={[Styles.textMediumNormal, Styles.cWhite]}>{data?.role}</Text>
</>
}
</View>
<View style={[Styles.p15]}>
<View style={[Styles.rowSpaceBetween]}>
<Text style={[Styles.textDefaultSemiBold]}>Informasi</Text>
</View>
{
loading ?
arrSkeleton.map((item, index) => {
return (
<Skeleton key={index} width={100} widthType="percent" height={25} borderRadius={5} />
)
})
:
<>
<ItemDetailMember category="nik" value={data?.nik} />
<ItemDetailMember category="group" value={data?.group} />
<ItemDetailMember category="position" value={data?.position} />
<ItemDetailMember category="phone" value={`+62${data?.phone}`} />
<ItemDetailMember category="email" value={data?.email} />
<ItemDetailMember category="gender" value={data?.gender == "F" ? "Perempuan" : "Laki-Laki"} />
</>
}
</View>
</View>
</ScrollView>

View File

@@ -2,6 +2,7 @@ import BorderBottomItem from "@/components/borderBottomItem";
import ButtonTab from "@/components/buttonTab";
import ImageUser from "@/components/imageNew";
import InputSearch from "@/components/inputSearch";
import SkeletonTwoItem from "@/components/skeletonTwoItem";
import Styles from "@/constants/Styles";
import { apiGetUser } from "@/lib/api";
import { useAuthSession } from "@/providers/AuthProvider";
@@ -9,7 +10,7 @@ import { AntDesign, Feather } from "@expo/vector-icons";
import { router, useLocalSearchParams } from "expo-router";
import { useEffect, useState } from "react";
import { SafeAreaView, ScrollView, Text, View } from "react-native";
import { useDispatch, useSelector } from "react-redux";
import { useSelector } from "react-redux";
type Props = {
id: string,
@@ -32,25 +33,31 @@ export default function Index() {
const [search, setSearch] = useState('')
const [nameGroup, setNameGroup] = useState('')
const [data, setData] = useState<Props[]>([])
const dispatch = useDispatch()
const update = useSelector((state: any) => state.memberUpdate)
const arrSkeleton = Array.from({ length: 5 }, (_, index) => index)
const [loading, setLoading] = useState(true)
async function handleLoad() {
async function handleLoad(loading: boolean) {
try {
setLoading(loading)
const hasil = await decryptToken(String(token?.current))
const response = await apiGetUser({ user: hasil, active: String(active), search: search, group: String(group) })
setData(response.data)
setNameGroup(response.filter.name)
} catch (error) {
console.error(error)
} finally {
setLoading(false)
}
}
useEffect(() => {
handleLoad()
}, [active, search, group, update])
handleLoad(true)
}, [active, search, group])
useEffect(() => {
handleLoad(false)
}, [update])
return (
@@ -61,14 +68,14 @@ export default function Index() {
<ButtonTab
active={active == "false" ? "false" : "true"}
value="true"
onPress={() => { router.push(`/member?active=true&group=${group}&search=${search}`) }}
onPress={() => { router.replace(`/member?active=true&group=${group}&search=${search}`) }}
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.push(`/member?active=false&group=${group}&search=${search}`) }}
onPress={() => { router.replace(`/member?active=false&group=${group}&search=${search}`) }}
label="Tidak Aktif"
icon={<AntDesign name="closecircleo" color={active == "false" ? 'white' : 'black'} size={20} />}
n={2} />
@@ -82,6 +89,13 @@ export default function Index() {
}
<View>
{
loading ?
arrSkeleton.map((item, index) => {
return (
<SkeletonTwoItem key={index} />
)
})
:
data.length > 0
?
data.map((item, index) => {
@@ -100,7 +114,6 @@ export default function Index() {
})
:
<Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada data</Text>
}
</View>
</View>

View File

@@ -6,6 +6,7 @@ import DrawerBottom from "@/components/drawerBottom";
import { InputForm } from "@/components/inputForm";
import InputSearch from "@/components/inputSearch";
import MenuItemRow from "@/components/menuItemRow";
import SkeletonTwoItem from "@/components/skeletonTwoItem";
import { ColorsStatus } from "@/constants/ColorsStatus";
import Styles from "@/constants/Styles";
import { apiDeletePosition, apiEditPosition, apiGetPosition } from "@/lib/api";
@@ -26,6 +27,8 @@ type Props = {
}
export default function Index() {
const arrSkeleton = Array.from({ length: 5 }, (_, index) => index)
const [loading, setLoading] = useState(true)
const { token, decryptToken } = useAuthSession()
const entityUser = useSelector((state: any) => state.user)
const { active, group } = useLocalSearchParams<{ active?: string, group?: string }>()
@@ -42,20 +45,27 @@ export default function Index() {
const dispatch = useDispatch()
const update = useSelector((state: any) => state.positionUpdate)
async function handleLoad() {
async function handleLoad(loading: boolean) {
try {
setLoading(loading)
const hasil = await decryptToken(String(token?.current))
const response = await apiGetPosition({ user: hasil, active: String(active), search: search, group: String(group) })
setData(response.data)
setNameGroup(response.filter.name)
} catch (error) {
console.error(error)
} finally {
setLoading(false)
}
}
useEffect(() => {
handleLoad()
}, [active, search, group, update])
handleLoad(true)
}, [active, search, group])
useEffect(() => {
handleLoad(false)
}, [update])
function handleChooseData(id: string, name: string, active: boolean, group: string) {
@@ -115,14 +125,14 @@ export default function Index() {
<ButtonTab
active={active == "false" ? "false" : "true"}
value="true"
onPress={() => { router.push(`/position?active=true&group=${group}&search=${search}`) }}
onPress={() => { router.replace(`/position?active=true&group=${group}&search=${search}`) }}
label="Aktif"
icon={<Feather name="check-circle" color={active == "true" ? 'white' : 'black'} size={20} />}
n={2} />
<ButtonTab
active={active == "false" ? "false" : "true"}
value="false"
onPress={() => { router.push(`/position?active=false&group=${group}&search=${search}`) }}
onPress={() => { router.replace(`/position?active=false&group=${group}&search=${search}`) }}
label="Tidak Aktif"
icon={<AntDesign name="closecircleo" color={active == "false" ? 'white' : 'black'} size={20} />}
n={2} />
@@ -136,6 +146,13 @@ export default function Index() {
}
<View>
{
loading ?
arrSkeleton.map((item, index) => {
return (
<SkeletonTwoItem key={index} />
)
})
:
data.length > 0 ?
data.map((item, index) => {
return (

View File

@@ -4,6 +4,7 @@ import { useAuthSession } from "@/providers/AuthProvider";
import { useEffect, useState } from "react";
import { Dimensions, Text, View } from "react-native";
import { BarChart } from "react-native-gifted-charts";
import Skeleton from "../skeleton";
type Props = {
value: number;
@@ -12,6 +13,7 @@ type Props = {
}[]
export default function ChartDokumenHome() {
const [loading, setLoading] = useState(true)
const { decryptToken, token } = useAuthSession()
const [data, setData] = useState<Props>([])
const [maxValue, setMaxValue] = useState(5)
@@ -24,6 +26,7 @@ export default function ChartDokumenHome() {
async function handleData() {
try {
setLoading(true)
const hasil = await decryptToken(String(token?.current))
const response = await apiGetDataHome({ cat: "dokumen", user: hasil })
const maxValue = response.data.reduce((max: number, obj: { value: number; }) => Math.max(max, obj.value), -Infinity);
@@ -37,6 +40,8 @@ export default function ChartDokumenHome() {
setData(convertedArray)
} catch (error) {
console.error(error)
} finally {
setLoading(false)
}
}
@@ -47,6 +52,9 @@ export default function ChartDokumenHome() {
return (
<View style={[Styles.wrapPaper, Styles.contentItemCenter, Styles.mb15]}>
<Text style={[Styles.textSubtitle, Styles.mv15]}>JUMLAH DOKUMEN</Text>
{
loading ? <Skeleton width={100} height={200} borderRadius={10} widthType="percent" />
:
<BarChart
showFractionalValues={false}
showYAxisIndices
@@ -69,6 +77,8 @@ export default function ChartDokumenHome() {
);
}}
/>
}
</View>
)
}

View File

@@ -4,6 +4,7 @@ import { useAuthSession } from "@/providers/AuthProvider";
import { useEffect, useState } from "react";
import { Text, View } from "react-native";
import { PieChart } from "react-native-gifted-charts";
import Skeleton from "../skeleton";
type Props = {
value: number;
@@ -14,9 +15,11 @@ type Props = {
export default function ChartProgresHome() {
const { decryptToken, token } = useAuthSession()
const [data, setData] = useState<Props>([])
const [loading, setLoading] = useState(true)
async function handleData() {
try {
setLoading(true)
const hasil = await decryptToken(String(token?.current))
const response = await apiGetDataHome({ cat: "progress", user: hasil })
const convertedArray = response.data.map((item: { color: any; text: any; value: any; }) => ({
@@ -27,6 +30,8 @@ export default function ChartProgresHome() {
setData(convertedArray)
} catch (error) {
console.error(error)
} finally {
setLoading(false)
}
}
@@ -37,6 +42,10 @@ export default function ChartProgresHome() {
return (
<View style={[Styles.wrapPaper, Styles.contentItemCenter, Styles.mb15]}>
<Text style={[Styles.textSubtitle, Styles.mv15]}>PROGRES KEGIATAN</Text>
{
loading ? <Skeleton width={100} height={200} borderRadius={10} widthType="percent" />
:
<>
<PieChart
data={data}
showText
@@ -75,6 +84,8 @@ export default function ChartProgresHome() {
</View>
</View>
</View>
</>
}
</View>
)
}

View File

@@ -1,9 +1,11 @@
import Styles from "@/constants/Styles";
import { apiGetDataHome } from "@/lib/api";
import { useAuthSession } from "@/providers/AuthProvider";
import { router } from "expo-router";
import { useEffect, useState } from "react";
import { Text, View } from "react-native";
import DiscussionItem from "../discussionItem";
import Skeleton from "../skeleton";
type Props = {
id: string
@@ -17,15 +19,19 @@ type Props = {
export default function DisccussionHome() {
const { decryptToken, token } = useAuthSession()
const [data, setData] = useState<Props[]>([])
const [loading, setLoading] = useState(true)
async function handleData() {
try {
setLoading(true)
const hasil = await decryptToken(String(token?.current))
const response = await apiGetDataHome({ cat: "discussion", user: hasil })
setData(response.data)
} catch (error) {
console.error(error)
} finally {
setLoading(false)
}
}
@@ -38,13 +44,19 @@ export default function DisccussionHome() {
<Text style={[Styles.textDefaultSemiBold, Styles.mv10]}>Diskusi</Text>
<View style={[Styles.wrapPaper]}>
{
loading ?
<>
<Skeleton width={100} height={70} borderRadius={10} widthType="percent" />
<Skeleton width={100} height={70} borderRadius={10} widthType="percent" />
</>
:
data.length > 0 ?
data.map((item, index) => {
return (
<DiscussionItem key={index} title={item.desc} user={item.user} date={item.date} />
<DiscussionItem key={index} title={item.desc} user={item.user} date={item.date} onPress={() => { router.push(`/division/${item.idDivision}/discussion/${item.id}`) }} />
)
})
: <Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada acara hari ini</Text>
: <Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada diskusi</Text>
}
</View>
</View>

View File

@@ -6,6 +6,7 @@ import React, { useEffect, useState } from "react";
import { Dimensions, Text, View } from "react-native";
import Carousel, { ICarouselInstance } from "react-native-reanimated-carousel";
import PaperGridContent from "../paperGridContent";
import Skeleton from "../skeleton";
type Props = {
id: string
@@ -18,14 +19,18 @@ export default function DivisionHome() {
const ref = React.useRef<ICarouselInstance>(null);
const width = Dimensions.get("window").width;
const [data, setData] = useState<Props[]>([])
const [loading, setLoading] = useState(true)
async function handleData() {
try {
setLoading(true)
const hasil = await decryptToken(String(token?.current))
const response = await apiGetDataHome({ cat: "division", user: hasil })
setData(response.data)
} catch (error) {
console.error(error)
} finally {
setLoading(false)
}
}
@@ -38,6 +43,9 @@ export default function DivisionHome() {
return (
<View style={[Styles.mb15]}>
<Text style={[Styles.textDefaultSemiBold, Styles.mv10]}>Divisi Teraktif</Text>
{
loading ? <Skeleton width={100} height={150} borderRadius={10} widthType="percent" />
:
<Carousel
ref={ref}
style={{ width: "100%" }}
@@ -59,6 +67,8 @@ export default function DivisionHome() {
</PaperGridContent>
)}
/>
}
</View>
)
}

View File

@@ -1,10 +1,11 @@
import Styles from "@/constants/Styles";
import { apiGetDataHome } from "@/lib/api";
import { useAuthSession } from "@/providers/AuthProvider";
import { router } from "expo-router";
import { useEffect, useState } from "react";
import { Text, View } from "react-native";
import EventItem from "../eventItem";
import { router } from "expo-router";
import Skeleton from "../skeleton";
type Props = {
id: string
@@ -23,14 +24,18 @@ type Props = {
export default function EventHome() {
const { decryptToken, token } = useAuthSession()
const [data, setData] = useState<Props[]>([])
const [loading, setLoading] = useState(true)
async function handleData() {
try {
setLoading(true)
const hasil = await decryptToken(String(token?.current))
const response = await apiGetDataHome({ cat: "event", user: hasil })
setData(response.data)
} catch (error) {
console.error(error)
} finally {
setLoading(false)
}
}
@@ -42,11 +47,18 @@ export default function EventHome() {
<View style={[Styles.mb15]}>
<Text style={[Styles.textDefaultSemiBold, Styles.mv10]}>Acara Hari Ini</Text>
<View style={[Styles.wrapPaper]}>
{
loading ?
<>
<Skeleton width={100} height={70} borderRadius={10} widthType="percent" />
<Skeleton width={100} height={70} borderRadius={10} widthType="percent" />
</>
:
data.length > 0 ?
data.map((item, index) => {
return (
<EventItem key={index} category={index % 2 == 0 ? 'purple' : 'orange'} onPress={() => {router.push(`/division/${item.idDivision}/calendar/${item.id}`)}} title={item.title} user={item.user_name} jamAwal={item.timeStart} jamAkhir={item.timeEnd} />
<EventItem key={index} category={index % 2 == 0 ? 'purple' : 'orange'} onPress={() => { router.push(`/division/${item.idDivision}/calendar/${item.id}`) }} title={item.title} user={item.user_name} jamAwal={item.timeStart} jamAkhir={item.timeEnd} />
)
})
: <Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada acara hari ini</Text>

View File

@@ -8,6 +8,7 @@ import Carousel, { ICarouselInstance } from "react-native-reanimated-carousel";
import LabelStatus from "../labelStatus";
import PaperGridContent from "../paperGridContent";
import ProgressBar from "../progressBar";
import Skeleton from "../skeleton";
type Props = {
id: string
@@ -23,14 +24,18 @@ export default function ProjectHome() {
const ref = React.useRef<ICarouselInstance>(null);
const width = Dimensions.get("window").width;
const [data, setData] = useState<Props[]>([])
const [loading, setLoading] = useState(true)
async function handleData() {
try {
setLoading(true)
const hasil = await decryptToken(String(token?.current))
const response = await apiGetDataHome({ cat: "kegiatan", user: hasil })
setData(response.data)
} catch (error) {
console.error(error)
} finally {
setLoading(false)
}
}
@@ -41,6 +46,9 @@ export default function ProjectHome() {
return (
<View style={[Styles.mb15]}>
<Text style={[Styles.textDefaultSemiBold, Styles.mv10]}>Kegiatan Terupdate</Text>
{
loading ? (<Skeleton width={100} height={150} borderRadius={10} widthType="percent" />)
:
<Carousel
ref={ref}
style={{ width: "100%" }}
@@ -79,6 +87,8 @@ export default function ProjectHome() {
</PaperGridContent>
)}
/>
}
</View>
)
}

View File

@@ -4,7 +4,7 @@ import { Image } from "react-native";
type Props = {
src: string,
size?: 'sm' | 'xs'
size?: 'sm' | 'xs' | 'lg'
border?: boolean
}
@@ -13,7 +13,7 @@ export default function ImageUser({ src, size }: Props) {
return (
<Image
source={error ? require('../assets/images/user.jpg') : { uri: src }}
style={[size == 'xs' ? Styles.userProfileExtraSmall : Styles.userProfileSmall, Styles.borderAll]}
style={[size == 'xs' ? Styles.userProfileExtraSmall : size == 'lg' ? Styles.userProfileBig : Styles.userProfileSmall, Styles.borderAll]}
onError={() =>
setError(true)
}

40
components/skeleton.tsx Normal file
View File

@@ -0,0 +1,40 @@
import Styles from '@/constants/Styles';
import React, { useEffect } from 'react';
import { StyleSheet } from 'react-native';
import Animated, { Easing, useAnimatedStyle, useSharedValue, withRepeat, withTiming } from 'react-native-reanimated';
const Skeleton = ({ width, height, borderRadius = 0, widthType = 'number' }: { width: number, widthType?: 'number' | 'percent', height: number, borderRadius?: number }) => {
const opacity = useSharedValue(0.3);
useEffect(() => {
opacity.value = withRepeat(
withTiming(1, { duration: 500, easing: Easing.linear }),
-1,
true
);
}, []);
const animatedStyle = useAnimatedStyle(() => {
return {
opacity: opacity.value,
};
});
return (
<Animated.View
style={[
styles.skeleton,
{ width: widthType === 'percent' ? `${width}%` : width, height: height, borderRadius: borderRadius },
animatedStyle, Styles.mv05
]}
/>
);
};
const styles = StyleSheet.create({
skeleton: {
backgroundColor: '#e0e0e0',
},
});
export default Skeleton;

View File

@@ -0,0 +1,14 @@
import Styles from "@/constants/Styles";
import { View } from "react-native";
import Skeleton from "./skeleton";
export default function SkeletonTwoItem() {
return (
<View style={[Styles.rowOnly]}>
<Skeleton width={50} height={50} borderRadius={10} />
<View style={[{ flex: 1 }, Styles.ph05]}>
<Skeleton width={100} widthType="percent" height={50} borderRadius={10} />
</View>
</View>
)
}