From 88dd6165f21578f509634d0d14809c78f1b66fdc Mon Sep 17 00:00:00 2001 From: amal Date: Mon, 21 Jul 2025 18:07:45 +0800 Subject: [PATCH] upd: modal loading saat open file Deskripsi: - dokumen divisi - banner - project - kegiatan divisi No Issues --- app/(application)/banner/index.tsx | 8 +++++++- .../division/[id]/(fitur-division)/document/index.tsx | 9 +++++++-- components/project/sectionFile.tsx | 7 +++++++ components/task/sectionFileTask.tsx | 10 ++++++++-- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/app/(application)/banner/index.tsx b/app/(application)/banner/index.tsx index b2b7a5d..643ef97 100644 --- a/app/(application)/banner/index.tsx +++ b/app/(application)/banner/index.tsx @@ -4,6 +4,7 @@ import BorderBottomItem from "@/components/borderBottomItem" import ButtonBackHeader from "@/components/buttonBackHeader" import DrawerBottom from "@/components/drawerBottom" import MenuItemRow from "@/components/menuItemRow" +import ModalLoading from "@/components/modalLoading" import Styles from "@/constants/Styles" import { apiDeleteBanner, apiGetBanner } from "@/lib/api" import { setEntities } from "@/lib/bannerSlice" @@ -34,6 +35,7 @@ export default function BannerList() { const [selectFile, setSelectFile] = useState(null) const dispatch = useDispatch() const [refreshing, setRefreshing] = useState(false) + const [loadingOpen, setLoadingOpen] = useState(false) const handleDeleteEntity = async () => { try { @@ -66,6 +68,8 @@ export default function BannerList() { }; const openFile = () => { + setModal(false) + setLoadingOpen(true) let remoteUrl = 'https://wibu-storage.wibudev.com/api/files/' + selectFile?.image; const fileName = selectFile?.name + '.' + selectFile?.extension; let localPath = `${FileSystem.documentDirectory}/${fileName}`; @@ -93,6 +97,8 @@ export default function BannerList() { } } catch (error) { Alert.alert('INFO', 'Gagal membuka file, tidak ada aplikasi yang dapat membuka file ini'); + } finally { + setLoadingOpen(false) } }); }; @@ -108,7 +114,7 @@ export default function BannerList() { headerRight: () => }} /> - + state.dokumenUpdate) const [refreshing, setRefreshing] = useState(false) + const [loadingOpen, setLoadingOpen] = useState(false) const [bodyRename, setBodyRename] = useState({ id: "", name: "", @@ -268,6 +270,7 @@ export default function DocumentDivision() { const openFile = (item: Props) => { + setLoadingOpen(true) let remoteUrl = 'https://wibu-storage.wibudev.com/api/files/' + item.idStorage; const fileName = item.name + '.' + item.extension; let localPath = `${FileSystem.documentDirectory}/${fileName}`; @@ -276,7 +279,6 @@ export default function DocumentDivision() { FileSystem.downloadAsync(remoteUrl, localPath).then(async ({ uri }) => { const contentURL = await FileSystem.getContentUriAsync(uri); try { - if (Platform.OS == 'android') { // open with android intent await startActivityAsync( @@ -288,13 +290,15 @@ export default function DocumentDivision() { } ); // or - // Sharing.shareAsync(localPath); + // Sharing.shareAsync(localPath); } else if (Platform.OS == 'ios') { Sharing.shareAsync(localPath); } } catch (error) { Alert.alert('INFO', 'Gagal membuka file, tidak ada aplikasi yang dapat membuka file ini'); + } finally { + setLoadingOpen(false) } }); }; @@ -345,6 +349,7 @@ export default function DocumentDivision() { ), }} /> + (null) + const [loadingOpen, setLoadingOpen] = useState(false) async function handleLoad(loading: boolean) { try { @@ -89,6 +91,8 @@ export default function SectionFile({ status, member }: { status: number | undef const openFile = () => { + setModal(false) + setLoadingOpen(true) let remoteUrl = 'https://wibu-storage.wibudev.com/api/files/' + selectFile?.idStorage; const fileName = selectFile?.name + '.' + selectFile?.extension; let localPath = `${FileSystem.documentDirectory}/${fileName}`; @@ -116,6 +120,8 @@ export default function SectionFile({ status, member }: { status: number | undef } } catch (error) { Alert.alert('INFO', 'Gagal membuka file, tidak ada aplikasi yang dapat membuka file ini'); + } finally { + setLoadingOpen(false) } }); }; @@ -124,6 +130,7 @@ export default function SectionFile({ status, member }: { status: number | undef return ( <> + File diff --git a/components/task/sectionFileTask.tsx b/components/task/sectionFileTask.tsx index 26ec81e..0594c99 100644 --- a/components/task/sectionFileTask.tsx +++ b/components/task/sectionFileTask.tsx @@ -15,6 +15,7 @@ import AlertKonfirmasi from "../alertKonfirmasi"; import BorderBottomItem from "../borderBottomItem"; import DrawerBottom from "../drawerBottom"; import MenuItemRow from "../menuItemRow"; +import ModalLoading from "../modalLoading"; import Skeleton from "../skeleton"; type Props = { @@ -27,13 +28,14 @@ type Props = { export default function SectionFileTask() { const [isModal, setModal] = useState(false) const { token, decryptToken } = useAuthSession() - const { detail } = useLocalSearchParams<{ detail: string }>(); + const { detail } = useLocalSearchParams<{ detail: string }>() const [data, setData] = useState([]) const update = useSelector((state: any) => state.taskUpdate) const dispatch = useDispatch() const [loading, setLoading] = useState(true) const arrSkeleton = Array.from({ length: 5 }) const [selectFile, setSelectFile] = useState(null) + const [loadingOpen, setLoadingOpen] = useState(false) async function handleLoad(loading: boolean) { try { @@ -57,6 +59,8 @@ export default function SectionFileTask() { }, []) const openFile = () => { + setModal(false) + setLoadingOpen(true) let remoteUrl = 'https://wibu-storage.wibudev.com/api/files/' + selectFile?.idStorage; const fileName = selectFile?.name + '.' + selectFile?.extension; let localPath = `${FileSystem.documentDirectory}/${fileName}`; @@ -65,7 +69,6 @@ export default function SectionFileTask() { FileSystem.downloadAsync(remoteUrl, localPath).then(async ({ uri }) => { const contentURL = await FileSystem.getContentUriAsync(uri); try { - if (Platform.OS == 'android') { // open with android intent await startActivityAsync( @@ -84,6 +87,8 @@ export default function SectionFileTask() { } } catch (error) { Alert.alert('INFO', 'Gagal membuka file, tidak ada aplikasi yang dapat membuka file ini'); + } finally { + setLoadingOpen(false) } }); }; @@ -109,6 +114,7 @@ export default function SectionFileTask() { return ( <> + File