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

@@ -25,9 +25,14 @@ import {
MaterialCommunityIcons,
MaterialIcons,
} from "@expo/vector-icons";
import * as FileSystem from 'expo-file-system';
import { startActivityAsync } from 'expo-intent-launcher';
import { router, Stack, useLocalSearchParams } from "expo-router";
import * as Sharing from 'expo-sharing';
import { useEffect, useState } from "react";
import {
Alert,
Platform,
Pressable,
SafeAreaView,
ScrollView,
@@ -35,6 +40,7 @@ import {
ToastAndroid,
View,
} from "react-native";
import * as mime from 'react-native-mime-types';
import { useDispatch, useSelector } from "react-redux";
type Props = {
@@ -258,6 +264,39 @@ export default function DocumentDivision() {
}
}
const openFile = (item: Props) => {
let remoteUrl = 'https://wibu-storage.wibudev.com/api/files/' + item.idStorage;
const fileName = item.name + '.' + item.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');
}
});
};
return (
<SafeAreaView>
<Stack.Screen
@@ -331,9 +370,7 @@ export default function DocumentDivision() {
:
data.length > 0 ? (
data.map((item, index) => {
const isSelected = selectedFiles.some(
(i: any) => i?.id == item.id
);
const isSelected = selectedFiles.some((i: any) => i?.id == item.id);
return (
<ItemFile
key={index}
@@ -357,7 +394,11 @@ export default function DocumentDivision() {
}}
checked={isSelected}
onPress={() => {
setPath(item.id);
if (item.category == "FOLDER" && selectedFiles.length == 0 && !dariSelectAll) {
setPath(item.id);
} else if (item.category == "FILE" && selectedFiles.length == 0 && !dariSelectAll) {
openFile(item)
}
}}
/>
);
@@ -380,7 +421,7 @@ export default function DocumentDivision() {
{(selectedFiles.length > 0 || dariSelectAll) && (
<View style={[ColorsStatus.primary, Styles.bottomMenuSelectDocument]}>
<View style={[Styles.rowItemsCenter, { justifyContent: "center" }]}>
<MenuItemRow
{/* <MenuItemRow
icon={
<MaterialCommunityIcons
name="download-outline"
@@ -393,7 +434,7 @@ export default function DocumentDivision() {
column="many"
color="white"
disabled={selectedFiles.length == 0 || !copyAllowed}
/>
/> */}
<MenuItemRow
icon={
<MaterialCommunityIcons