feat: Enhance document management with a first draft of upload and download functionalities (needs revision)
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import { Download, FileText, MapPin, Plus, Search, CalendarIcon } from 'lucide-react-native';
|
||||
import { ArrowLeft, Download, FileText, MapPin, Plus, Search, CalendarIcon } from 'lucide-react-native';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useRouter } from 'expo-router';
|
||||
import { RangePickerModal } from '@/components/RangePickerModal';
|
||||
import { Alert, RefreshControl, ScrollView, Text, TextInput, TouchableOpacity, View } from 'react-native';
|
||||
import { DocumentItem } from '@/types/types';
|
||||
@ -8,8 +9,10 @@ import dayjs from 'dayjs';
|
||||
import LoadingScreen from '@/components/LoadingScreen';
|
||||
import { formatTimestamp, parseTimestamp } from '@/utils/dateTime';
|
||||
import AddDocumentModal from '@/components/AddDocumentModal';
|
||||
import { downloadAndShareDocument, downloadDocumentByUrl, downloadDocumentLegacy, uploadDocument } from '@/utils/documentUtils';
|
||||
|
||||
export default function DocumentsScreen() {
|
||||
const router = useRouter();
|
||||
const [documents, setDocuments] = useState<DocumentItem[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
@ -77,25 +80,9 @@ export default function DocumentsScreen() {
|
||||
|
||||
// Gestione Caricamento Documento
|
||||
const handleUploadDocument = async (file: any, customTitle?: string) => {
|
||||
console.log('Caricamento documento:', file, 'con titolo personalizzato:', customTitle);
|
||||
setIsUploading(true);
|
||||
try {
|
||||
// const formData = new FormData();
|
||||
// formData.append('file', {
|
||||
// uri: file.uri,
|
||||
// name: file.name,
|
||||
// type: file.mimeType || 'application/octet-stream',
|
||||
// } as any);
|
||||
// if (customTitle) {
|
||||
// formData.append('title', customTitle);
|
||||
// }
|
||||
|
||||
// const response = await api.post('/attachment/upload', formData, {
|
||||
// headers: {
|
||||
// 'Content-Type': 'multipart/form-data',
|
||||
// },
|
||||
// });
|
||||
|
||||
const response = await uploadDocument(file, null, customTitle);
|
||||
// console.log('Risposta caricamento:', response.data);
|
||||
// Alert.alert('Successo', 'Documento caricato con successo!');
|
||||
// setShowUploadModal(false);
|
||||
@ -108,6 +95,16 @@ export default function DocumentsScreen() {
|
||||
}
|
||||
}
|
||||
|
||||
// Gestione Download e Condivisione Documento
|
||||
const handleDownloadAndShare = async (mimetype: string, fileName: string, fileUrl: string) => {
|
||||
try {
|
||||
await downloadAndShareDocument(mimetype, fileName, fileUrl);
|
||||
} catch (error) {
|
||||
console.error('Errore nel download/condivisione del documento:', error);
|
||||
Alert.alert('Errore', 'Impossibile scaricare/condividere il documento. Riprova più tardi.');
|
||||
}
|
||||
};
|
||||
|
||||
if (isLoading && !refreshing) {
|
||||
return (
|
||||
<LoadingScreen />
|
||||
@ -117,10 +114,14 @@ export default function DocumentsScreen() {
|
||||
return (
|
||||
<View className="flex-1 bg-gray-50">
|
||||
{/* Header */}
|
||||
{/* TODO: Aggiungi torna indietro */}
|
||||
<View className="bg-white p-6 pt-16 shadow-sm border-b border-gray-100">
|
||||
<Text className="text-3xl font-bold text-gray-800 mb-1">Documenti</Text>
|
||||
<Text className="text-base text-gray-500">Gestisci i tuoi documenti</Text>
|
||||
<View className="flex-row items-center gap-4 bg-white p-6 pt-16 shadow-sm border-b border-gray-100">
|
||||
<TouchableOpacity onPress={() => router.back()} className="p-2 -ml-2 rounded-full active:bg-gray-100">
|
||||
<ArrowLeft size={24} color="#374151" />
|
||||
</TouchableOpacity>
|
||||
<View className="flex-1">
|
||||
<Text className="text-3xl font-bold text-gray-800">Documenti</Text>
|
||||
<Text className="text-base text-gray-500">Gestisci i tuoi documenti</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View className="p-5 gap-6 flex-1">
|
||||
@ -179,7 +180,9 @@ export default function DocumentsScreen() {
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
<TouchableOpacity className="p-4 bg-gray-50 rounded-2xl active:bg-gray-100">
|
||||
<TouchableOpacity
|
||||
onPress={() => downloadDocumentLegacy(doc.mimetype, doc.title, doc.url)} // downloadDocumentByUrl(doc.url, doc.title) handleDownloadAndShare(doc.mimetype, doc.title, doc.url)
|
||||
className="p-4 bg-gray-50 rounded-2xl active:bg-gray-100">
|
||||
<Download size={24} color="#6b7280" />
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
|
||||
Reference in New Issue
Block a user