upd: view file

Deskripsi:
- unduh diilangin
- kegiatan umum
- task divisi
- dokumen divisi

No Issues
This commit is contained in:
amel
2025-06-10 14:57:31 +08:00
parent 636bfcc87c
commit e4dd649e08
7 changed files with 150 additions and 31 deletions

View File

@@ -3,9 +3,13 @@ import { apiDeleteFileTask, apiGetTaskOne } from "@/lib/api";
import { setUpdateTask } from "@/lib/taskUpdate";
import { useAuthSession } from "@/providers/AuthProvider";
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
import * as FileSystem from 'expo-file-system';
import { startActivityAsync } from 'expo-intent-launcher';
import { useLocalSearchParams } from "expo-router";
import * as Sharing from 'expo-sharing';
import { useEffect, useState } from "react";
import { Text, ToastAndroid, View } from "react-native";
import { Alert, Platform, Text, ToastAndroid, View } from "react-native";
import * as mime from 'react-native-mime-types';
import { useDispatch, useSelector } from "react-redux";
import AlertKonfirmasi from "../alertKonfirmasi";
import BorderBottomItem from "../borderBottomItem";
@@ -25,11 +29,11 @@ export default function SectionFileTask() {
const { token, decryptToken } = useAuthSession()
const { detail } = useLocalSearchParams<{ detail: string }>();
const [data, setData] = useState<Props[]>([])
const [idSelect, setIdSelect] = 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<Props | null>(null)
async function handleLoad(loading: boolean) {
try {
@@ -52,10 +56,43 @@ export default function SectionFileTask() {
handleLoad(true)
}, [])
const openFile = () => {
let remoteUrl = 'https://wibu-storage.wibudev.com/api/files/' + selectFile?.idStorage;
const fileName = selectFile?.name + '.' + selectFile?.extension;
let localPath = `${FileSystem.documentDirectory}/${fileName}`;
const mimeType = mime.lookup(fileName)
FileSystem.downloadAsync(remoteUrl, localPath).then(async ({ uri }) => {
const contentURL = await FileSystem.getContentUriAsync(uri);
try {
if (Platform.OS == 'android') {
// open with android intent
await startActivityAsync(
'android.intent.action.VIEW',
{
data: contentURL,
flags: 1,
type: mimeType as string,
}
);
// or
// 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');
}
});
};
async function handleDelete() {
try {
const hasil = await decryptToken(String(token?.current));
const response = await apiDeleteFileTask({ user: hasil }, idSelect);
const response = await apiDeleteFileTask({ user: hasil }, String(selectFile?.id));
if (response.success) {
ToastAndroid.show('Berhasil menghapus file', ToastAndroid.SHORT)
dispatch(setUpdateTask({ ...update, file: !update.file }))
@@ -92,7 +129,7 @@ export default function SectionFileTask() {
icon={<MaterialCommunityIcons name="file-outline" size={25} color="black" />}
title={item.name + '.' + item.extension}
titleWeight="normal"
onPress={() => { setIdSelect(item.id); setModal(true) }}
onPress={() => { setSelectFile(item); setModal(true) }}
width={65}
/>
)
@@ -109,16 +146,17 @@ export default function SectionFileTask() {
icon={<MaterialCommunityIcons name="file-eye" color="black" size={25} />}
title="Lihat File"
onPress={() => {
setModal(false)
openFile()
// setModal(false)
}}
/>
<MenuItemRow
{/* <MenuItemRow
icon={<MaterialCommunityIcons name="download" color="black" size={25} />}
title="Download"
onPress={() => {
setModal(false)
}}
/>
/> */}
<MenuItemRow
icon={<Ionicons name="trash" color="black" size={25} />}