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,29 +116,37 @@ export default function Index() {
<InputSearch onChange={setSearch} />
<View>
{
data.length > 0 ?
data.map((item, index) => {
loading ?
arrSkeleton.map((item, index) => {
return (
<BorderBottomItem
key={index}
onPress={() => {
setIdChoose(item.id)
setActiveChoose(item.isActive)
setTitleChoose(item.name)
setModal(true)
}}
borderType="all"
icon={
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
<MaterialCommunityIcons name="office-building-outline" size={25} color={'#384288'} />
</View>
}
title={item.name}
/>
<SkeletonTwoItem key={index} />
)
})
:
<Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada data</Text>
data.length > 0 ?
data.map((item, index) => {
return (
<BorderBottomItem
key={index}
onPress={() => {
setIdChoose(item.id)
setActiveChoose(item.isActive)
setTitleChoose(item.name)
setModal(true)
}}
borderType="all"
icon={
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
<MaterialCommunityIcons name="office-building-outline" size={25} color={'#384288'} />
</View>
}
title={item.name}
/>
)
})
:
<Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada data</Text>
}
</View>
</View>

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]}
/>
<Text style={[Styles.textSubtitle, Styles.cWhite, Styles.mt10]}>{data?.name}</Text>
<Text style={[Styles.textMediumNormal, Styles.cWhite]}>{data?.role}</Text>
{
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>
<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"} />
{
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,25 +89,31 @@ export default function Index() {
}
<View>
{
data.length > 0
?
data.map((item, index) => {
loading ?
arrSkeleton.map((item, index) => {
return (
<BorderBottomItem
key={index}
onPress={() => { router.push(`/member/${item.id}`) }}
borderType="all"
icon={
<ImageUser src={`https://wibu-storage.wibudev.com/api/files/${item.img}`} />
}
title={item.name}
subtitle={`${item.group} - ${item.position}`}
/>
<SkeletonTwoItem key={index} />
)
})
:
<Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada data</Text>
data.length > 0
?
data.map((item, index) => {
return (
<BorderBottomItem
key={index}
onPress={() => { router.push(`/member/${item.id}`) }}
borderType="all"
icon={
<ImageUser src={`https://wibu-storage.wibudev.com/api/files/${item.img}`} />
}
title={item.name}
subtitle={`${item.group} - ${item.position}`}
/>
)
})
:
<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,25 +146,32 @@ export default function Index() {
}
<View>
{
data.length > 0 ?
data.map((item, index) => {
loading ?
arrSkeleton.map((item, index) => {
return (
<BorderBottomItem
key={index}
onPress={() => { handleChooseData(item.id, item.name, item.isActive, item.idGroup) }}
borderType="all"
icon={
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
<MaterialCommunityIcons name="account-tie" size={25} color={'#384288'} />
</View>
}
title={item.name}
subtitle={item.group}
/>
<SkeletonTwoItem key={index} />
)
})
:
<Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada data</Text>
data.length > 0 ?
data.map((item, index) => {
return (
<BorderBottomItem
key={index}
onPress={() => { handleChooseData(item.id, item.name, item.isActive, item.idGroup) }}
borderType="all"
icon={
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
<MaterialCommunityIcons name="account-tie" size={25} color={'#384288'} />
</View>
}
title={item.name}
subtitle={item.group}
/>
)
})
:
<Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada data</Text>
}
</View>
</View>

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,28 +52,33 @@ export default function ChartDokumenHome() {
return (
<View style={[Styles.wrapPaper, Styles.contentItemCenter, Styles.mb15]}>
<Text style={[Styles.textSubtitle, Styles.mv15]}>JUMLAH DOKUMEN</Text>
<BarChart
showFractionalValues={false}
showYAxisIndices
noOfSections={4}
maxValue={maxValue}
data={data}
isAnimated
width={width - 140}
barWidth={width * 0.25}
renderTooltip={(item: any, index: any) => {
return (
<View
style={{
alignItems: 'center',
justifyContent: 'center',
width: width * 0.25
}}>
<Text>{item.value}</Text>
</View>
);
}}
/>
{
loading ? <Skeleton width={100} height={200} borderRadius={10} widthType="percent" />
:
<BarChart
showFractionalValues={false}
showYAxisIndices
noOfSections={4}
maxValue={maxValue}
data={data}
isAnimated
width={width - 140}
barWidth={width * 0.25}
renderTooltip={(item: any, index: any) => {
return (
<View
style={{
alignItems: 'center',
justifyContent: 'center',
width: width * 0.25
}}>
<Text>{item.value}</Text>
</View>
);
}}
/>
}
</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,44 +42,50 @@ export default function ChartProgresHome() {
return (
<View style={[Styles.wrapPaper, Styles.contentItemCenter, Styles.mb15]}>
<Text style={[Styles.textSubtitle, Styles.mv15]}>PROGRES KEGIATAN</Text>
<PieChart
data={data}
showText
showValuesAsTooltipText
textColor="black"
radius={120}
textSize={15}
focusOnPress={false}
showValuesAsLabels
showTextBackground={false}
textBackgroundRadius={0}
isAnimated
/>
{
loading ? <Skeleton width={100} height={200} borderRadius={10} widthType="percent" />
:
<>
<PieChart
data={data}
showText
showValuesAsTooltipText
textColor="black"
radius={120}
textSize={15}
focusOnPress={false}
showValuesAsLabels
showTextBackground={false}
textBackgroundRadius={0}
isAnimated
/>
<View style={[Styles.mt15]}>
<View style={[Styles.rowSpaceBetween, Styles.w80]}>
<View style={[Styles.rowItemsCenter, Styles.w60]}>
<View style={[Styles.iconContent, { backgroundColor: '#177AD5' }]}></View>
<Text style={[Styles.textInformation, Styles.ml10]}>Segera Dikerjakan</Text>
</View>
<View style={[Styles.mt15]}>
<View style={[Styles.rowSpaceBetween, Styles.w80]}>
<View style={[Styles.rowItemsCenter, Styles.w60]}>
<View style={[Styles.iconContent, { backgroundColor: '#177AD5' }]}></View>
<Text style={[Styles.textInformation, Styles.ml10]}>Segera Dikerjakan</Text>
</View>
<View style={[Styles.rowItemsCenter, Styles.w50]}>
<View style={[Styles.iconContent, { backgroundColor: '#92cc76' }]}></View>
<Text style={[Styles.textInformation, Styles.ml10]}>Selesai</Text>
</View>
</View>
<View style={[Styles.rowSpaceBetween, Styles.w80, Styles.mt10]}>
<View style={[Styles.rowItemsCenter, Styles.w60]}>
<View style={[Styles.iconContent, { backgroundColor: '#fac858' }]}></View>
<Text style={[Styles.textInformation, Styles.ml10]}>Dikerjakan</Text>
</View>
<View style={[Styles.rowItemsCenter, Styles.w50]}>
<View style={[Styles.iconContent, { backgroundColor: '#92cc76' }]}></View>
<Text style={[Styles.textInformation, Styles.ml10]}>Selesai</Text>
</View>
</View>
<View style={[Styles.rowSpaceBetween, Styles.w80, Styles.mt10]}>
<View style={[Styles.rowItemsCenter, Styles.w60]}>
<View style={[Styles.iconContent, { backgroundColor: '#fac858' }]}></View>
<Text style={[Styles.textInformation, Styles.ml10]}>Dikerjakan</Text>
</View>
<View style={[Styles.rowItemsCenter, Styles.w50]}>
<View style={[Styles.iconContent, { backgroundColor: '#ED6665' }]}></View>
<Text style={[Styles.textInformation, Styles.ml10]}>Dibatalkan</Text>
</View>
</View>
</View>
<View style={[Styles.rowItemsCenter, Styles.w50]}>
<View style={[Styles.iconContent, { backgroundColor: '#ED6665' }]}></View>
<Text style={[Styles.textInformation, Styles.ml10]}>Dibatalkan</Text>
</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]}>
{
data.length > 0 ?
data.map((item, index) => {
return (
<DiscussionItem key={index} title={item.desc} user={item.user} date={item.date} />
)
})
: <Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada acara hari ini</Text>
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} onPress={() => { router.push(`/division/${item.idDivision}/discussion/${item.id}`) }} />
)
})
: <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,27 +43,32 @@ export default function DivisionHome() {
return (
<View style={[Styles.mb15]}>
<Text style={[Styles.textDefaultSemiBold, Styles.mv10]}>Divisi Teraktif</Text>
<Carousel
ref={ref}
style={{ width: "100%" }}
width={width * 0.8}
height={235}
data={data}
loop={true}
autoPlay={false}
autoPlayReverse={false}
pagingEnabled={true}
snapEnabled={true}
vertical={false}
renderItem={({ index }) => (
<PaperGridContent onPress={() => { router.push(`/division/${data[index].id}`) }} content="carousel" title={data[index].name} headerColor="warning">
<View>
<Text style={{ fontSize: 50, textAlign: "center", fontWeight: 'bold' }}>{data[index].jumlah}</Text>
<Text style={[Styles.textSubtitle, { textAlign: "center" }]}>KEGIATAN</Text>
</View>
</PaperGridContent>
)}
/>
{
loading ? <Skeleton width={100} height={150} borderRadius={10} widthType="percent" />
:
<Carousel
ref={ref}
style={{ width: "100%" }}
width={width * 0.8}
height={235}
data={data}
loop={true}
autoPlay={false}
autoPlayReverse={false}
pagingEnabled={true}
snapEnabled={true}
vertical={false}
renderItem={({ index }) => (
<PaperGridContent onPress={() => { router.push(`/division/${data[index].id}`) }} content="carousel" title={data[index].name} headerColor="warning">
<View>
<Text style={{ fontSize: 50, textAlign: "center", fontWeight: 'bold' }}>{data[index].jumlah}</Text>
<Text style={[Styles.textSubtitle, { textAlign: "center" }]}>KEGIATAN</Text>
</View>
</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,14 +47,21 @@ export default function EventHome() {
<View style={[Styles.mb15]}>
<Text style={[Styles.textDefaultSemiBold, Styles.mv10]}>Acara Hari Ini</Text>
<View style={[Styles.wrapPaper]}>
{
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} />
)
})
: <Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada acara hari ini</Text>
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} />
)
})
: <Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada acara hari ini</Text>
}
</View>
</View>

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,44 +46,49 @@ export default function ProjectHome() {
return (
<View style={[Styles.mb15]}>
<Text style={[Styles.textDefaultSemiBold, Styles.mv10]}>Kegiatan Terupdate</Text>
<Carousel
ref={ref}
style={{ width: "100%" }}
width={width * 0.8}
height={235}
data={data}
loop={true}
autoPlay={false}
autoPlayReverse={false}
pagingEnabled={true}
snapEnabled={true}
vertical={false}
renderItem={({ index }) => (
<PaperGridContent content="carousel" onPress={() => { router.push(`/project/${data[index].id}`) }} title={data[index].title} headerColor="primary">
<ProgressBar value={data[index].progress} category="carousel" />
<View style={[Styles.rowSpaceBetween]}>
<Text style={[Styles.textDefault, Styles.cGray]}>{data[index].createdAt}</Text>
<LabelStatus
size="default"
category={
data[index].status === 0 ? 'primary' :
data[index].status === 1 ? 'warning' :
data[index].status === 2 ? 'success' :
data[index].status === 3 ? 'error' :
'primary'
}
text={
data[index].status === 0 ? 'SEGERA' :
data[index].status === 1 ? 'DIKERJAKAN' :
data[index].status === 2 ? 'SELESAI' :
data[index].status === 3 ? 'DIBATALKAN' :
'SEGERA'
}
/>
</View>
</PaperGridContent>
)}
/>
{
loading ? (<Skeleton width={100} height={150} borderRadius={10} widthType="percent" />)
:
<Carousel
ref={ref}
style={{ width: "100%" }}
width={width * 0.8}
height={235}
data={data}
loop={true}
autoPlay={false}
autoPlayReverse={false}
pagingEnabled={true}
snapEnabled={true}
vertical={false}
renderItem={({ index }) => (
<PaperGridContent content="carousel" onPress={() => { router.push(`/project/${data[index].id}`) }} title={data[index].title} headerColor="primary">
<ProgressBar value={data[index].progress} category="carousel" />
<View style={[Styles.rowSpaceBetween]}>
<Text style={[Styles.textDefault, Styles.cGray]}>{data[index].createdAt}</Text>
<LabelStatus
size="default"
category={
data[index].status === 0 ? 'primary' :
data[index].status === 1 ? 'warning' :
data[index].status === 2 ? 'success' :
data[index].status === 3 ? 'error' :
'primary'
}
text={
data[index].status === 0 ? 'SEGERA' :
data[index].status === 1 ? 'DIKERJAKAN' :
data[index].status === 2 ? 'SELESAI' :
data[index].status === 3 ? 'DIBATALKAN' :
'SEGERA'
}
/>
</View>
</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>
)
}