fix : tampilan
deskripsi: - detail divisi > on klik pda file - update project dan tugas divisi tidak perlu loading judul project - tampilan notifikasi top right info No Issues
This commit is contained in:
@@ -2,11 +2,16 @@ import Styles from "@/constants/Styles";
|
||||
import { apiGetDivisionOneFeature } from "@/lib/api";
|
||||
import { useAuthSession } from "@/providers/AuthProvider";
|
||||
import { Feather } 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 React, { useEffect, useState } from "react";
|
||||
import { Dimensions, Text, View } from "react-native";
|
||||
import { Alert, Dimensions, Platform, Pressable, Text, View } from "react-native";
|
||||
import * as mime from 'react-native-mime-types';
|
||||
import { ICarouselInstance } from "react-native-reanimated-carousel";
|
||||
import Skeleton from "../skeleton";
|
||||
import ModalLoading from "../modalLoading";
|
||||
|
||||
type Props = {
|
||||
id: string
|
||||
@@ -14,6 +19,7 @@ type Props = {
|
||||
extension: string
|
||||
path: string
|
||||
share: boolean
|
||||
idStorage: string
|
||||
}
|
||||
|
||||
export default function FileDivisionDetail() {
|
||||
@@ -23,6 +29,7 @@ export default function FileDivisionDetail() {
|
||||
const { token, decryptToken } = useAuthSession()
|
||||
const { id } = useLocalSearchParams<{ id: string }>()
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [loadingOpen, setLoadingOpen] = useState(false)
|
||||
|
||||
async function handleLoad() {
|
||||
try {
|
||||
@@ -41,8 +48,45 @@ export default function FileDivisionDetail() {
|
||||
handleLoad()
|
||||
}, [])
|
||||
|
||||
|
||||
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}`;
|
||||
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');
|
||||
} finally {
|
||||
setLoadingOpen(false)
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<View style={[Styles.mb15]}>
|
||||
<ModalLoading isVisible={loadingOpen} setVisible={setLoadingOpen} />
|
||||
<Text style={[Styles.textDefaultSemiBold, Styles.mv10]}>Dokumen Terkini</Text>
|
||||
{
|
||||
loading ?
|
||||
@@ -56,7 +100,7 @@ export default function FileDivisionDetail() {
|
||||
<View style={[Styles.rowItemsCenter]}>
|
||||
{
|
||||
data.map((item, index) => (
|
||||
<View style={[Styles.mr05, { width: '24%' }]} key={index}>
|
||||
<Pressable style={[Styles.mr05, { width: '24%' }]} key={index} onPress={() => openFile(item)}>
|
||||
<View style={{ alignItems: 'center' }}>
|
||||
<View style={[Styles.wrapPaper, { alignItems: 'center' }]}>
|
||||
<Feather name="file-text" size={50} color="black" style={Styles.mr05} />
|
||||
@@ -65,7 +109,7 @@ export default function FileDivisionDetail() {
|
||||
<View style={[Styles.contentItemCenter]}>
|
||||
<Text style={[Styles.textMediumNormal, Styles.w90, { textAlign: 'center' }]} numberOfLines={1}>{item.name}.{item.extension}</Text>
|
||||
</View>
|
||||
</View>
|
||||
</Pressable>
|
||||
))
|
||||
}
|
||||
</View>
|
||||
|
||||
Reference in New Issue
Block a user