remove etc ...
This commit is contained in:
@@ -10,6 +10,7 @@ import { SearchScreen } from './app/search';
|
|||||||
import { BatchReviewScreen } from './app/batch-review';
|
import { BatchReviewScreen } from './app/batch-review';
|
||||||
import { PendingReviewScreen } from './app/pending-review';
|
import { PendingReviewScreen } from './app/pending-review';
|
||||||
import { FileDetailScreen } from './app/file-detail';
|
import { FileDetailScreen } from './app/file-detail';
|
||||||
|
import { FileEditScreen } from './app/file-edit';
|
||||||
|
|
||||||
const Stack = createNativeStackNavigator();
|
const Stack = createNativeStackNavigator();
|
||||||
const queryClient = new QueryClient();
|
const queryClient = new QueryClient();
|
||||||
@@ -35,6 +36,7 @@ export default function App() {
|
|||||||
component={FileDetailScreen}
|
component={FileDetailScreen}
|
||||||
options={{ title: 'Détails', headerTintColor: '#fff', headerStyle: { backgroundColor: '#000' } }}
|
options={{ title: 'Détails', headerTintColor: '#fff', headerStyle: { backgroundColor: '#000' } }}
|
||||||
/>
|
/>
|
||||||
|
<Stack.Screen name="FileEdit" component={FileEditScreen} options={{ title: 'Édition' }} />
|
||||||
</Stack.Navigator>
|
</Stack.Navigator>
|
||||||
</NavigationContainer>
|
</NavigationContainer>
|
||||||
<StatusBar style="auto" />
|
<StatusBar style="auto" />
|
||||||
|
|||||||
@@ -0,0 +1,361 @@
|
|||||||
|
import React, { useState, useCallback } from 'react';
|
||||||
|
import {
|
||||||
|
View,
|
||||||
|
Text,
|
||||||
|
StyleSheet,
|
||||||
|
FlatList,
|
||||||
|
TouchableOpacity,
|
||||||
|
Image,
|
||||||
|
TextInput,
|
||||||
|
Alert,
|
||||||
|
ActivityIndicator,
|
||||||
|
Dimensions,
|
||||||
|
} from 'react-native';
|
||||||
|
import { RouteProp, useRoute, useNavigation } from '@react-navigation/native';
|
||||||
|
import { MaterialIcons } from '@expo/vector-icons';
|
||||||
|
import { useFile, useFileImage, useAddTags } from '../hooks/useFiles';
|
||||||
|
import { usePdfGeneration } from '../hooks/usePdfGeneration';
|
||||||
|
import { useUpload } from '../hooks/useUpload';
|
||||||
|
import { TagChip } from '../components/TagChip';
|
||||||
|
import { FileThumbnail } from '../components/FileThumbnail';
|
||||||
|
import { FileItem } from '../types';
|
||||||
|
|
||||||
|
const NUM_COLUMNS = 3;
|
||||||
|
const SCREEN_WIDTH = Dimensions.get('window').width;
|
||||||
|
const ITEM_SIZE = (SCREEN_WIDTH - 16 * 2 - (NUM_COLUMNS - 1) * 6) / NUM_COLUMNS;
|
||||||
|
|
||||||
|
type FileEditRouteParams = {
|
||||||
|
FileEdit: { fileIds: string[] };
|
||||||
|
};
|
||||||
|
|
||||||
|
interface FileEditItemProps {
|
||||||
|
fileId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function FileEditItem({ fileId }: FileEditItemProps) {
|
||||||
|
const { data: fileData, isLoading: fileLoading } = useFile(fileId);
|
||||||
|
const { data: imageData, isLoading: imageLoading } = useFileImage(fileId);
|
||||||
|
const file = fileData as any;
|
||||||
|
const uri = imageData?.data?.url;
|
||||||
|
const isLoading = fileLoading || imageLoading;
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<View style={[styles.gridItem, styles.gridItemLoading]}>
|
||||||
|
<ActivityIndicator size="small" color="#1976D2" />
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={styles.gridItem}>
|
||||||
|
{uri && file?.mimeType?.startsWith('image/') ? (
|
||||||
|
<Image source={{ uri }} style={styles.thumb} />
|
||||||
|
) : (
|
||||||
|
<FileThumbnail
|
||||||
|
mimeType={file?.mimeType ?? 'application/octet-stream'}
|
||||||
|
fileName={file?.name ?? fileId}
|
||||||
|
size={ITEM_SIZE}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function FileEditScreen() {
|
||||||
|
const route = useRoute<RouteProp<FileEditRouteParams, 'FileEdit'>>();
|
||||||
|
const navigation = useNavigation();
|
||||||
|
const { fileIds } = route.params;
|
||||||
|
|
||||||
|
const addTags = useAddTags();
|
||||||
|
const { generatePdf, generating, progress } = usePdfGeneration();
|
||||||
|
const upload = useUpload();
|
||||||
|
|
||||||
|
const [tagInput, setTagInput] = useState('');
|
||||||
|
const [pendingTags, setPendingTags] = useState<string[]>([]);
|
||||||
|
const [uploading, setUploading] = useState(false);
|
||||||
|
|
||||||
|
const handleAddTag = () => {
|
||||||
|
const tag = tagInput.trim().toLowerCase();
|
||||||
|
if (!tag || pendingTags.includes(tag)) return;
|
||||||
|
setPendingTags((prev) => [...prev, tag]);
|
||||||
|
setTagInput('');
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRemoveTag = (tag: string) => {
|
||||||
|
setPendingTags((prev) => prev.filter((t) => t !== tag));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleApplyTags = useCallback(async () => {
|
||||||
|
if (pendingTags.length === 0) return;
|
||||||
|
for (const fileId of fileIds) {
|
||||||
|
await addTags.mutateAsync({ fileId, tags: pendingTags });
|
||||||
|
}
|
||||||
|
Alert.alert('Succès', `${pendingTags.length} tag${pendingTags.length > 1 ? 's' : ''} ajouté${pendingTags.length > 1 ? 's' : ''}`);
|
||||||
|
setPendingTags([]);
|
||||||
|
}, [pendingTags, fileIds, addTags]);
|
||||||
|
|
||||||
|
const handleGeneratePdf = useCallback(async () => {
|
||||||
|
if (fileIds.length === 0) return;
|
||||||
|
|
||||||
|
setUploading(true);
|
||||||
|
try {
|
||||||
|
const imageUris: { uri: string }[] = [];
|
||||||
|
|
||||||
|
for (const fileId of fileIds) {
|
||||||
|
const response = await fetch(`${process.env.EXPO_PUBLIC_API_BASE_URL || 'http://192.168.1.17:8080/api/v1'}/files/${fileId}`);
|
||||||
|
const data = await response.json();
|
||||||
|
const url = data?.data?.url;
|
||||||
|
if (url) {
|
||||||
|
imageUris.push({ uri: url });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (imageUris.length === 0) {
|
||||||
|
Alert.alert('Erreur', 'Aucune image trouvée pour la génération du PDF');
|
||||||
|
setUploading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const pdfUri = await generatePdf(imageUris);
|
||||||
|
if (!pdfUri) {
|
||||||
|
Alert.alert('Erreur', 'Échec de la génération du PDF');
|
||||||
|
setUploading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Alert.alert(
|
||||||
|
'PDF généré',
|
||||||
|
'Voulez-vous uploader le fichier ?',
|
||||||
|
[
|
||||||
|
{ text: 'Annuler', style: 'cancel' },
|
||||||
|
{
|
||||||
|
text: 'Uploader',
|
||||||
|
onPress: async () => {
|
||||||
|
try {
|
||||||
|
const pdfName = `document_${Date.now()}.pdf`;
|
||||||
|
const pdfUriClean = pdfUri.startsWith('file://') ? pdfUri : 'file://' + pdfUri;
|
||||||
|
await upload.mutateAsync([
|
||||||
|
{ uri: pdfUriClean, type: 'application/pdf', name: pdfName },
|
||||||
|
]);
|
||||||
|
Alert.alert('Succès', 'PDF uploadé avec succès', [
|
||||||
|
{ text: 'OK', onPress: () => navigation.goBack() },
|
||||||
|
]);
|
||||||
|
} catch (e: any) {
|
||||||
|
const msg = e?.message || e?.toString() || 'Erreur inconnue';
|
||||||
|
Alert.alert('Erreur', `Échec de l'upload du PDF: ${msg}`);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
setUploading(false);
|
||||||
|
}
|
||||||
|
}, [fileIds, generatePdf, upload, navigation]);
|
||||||
|
|
||||||
|
const isLoading = generating || uploading;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={styles.container}>
|
||||||
|
<View style={styles.header}>
|
||||||
|
<Text style={styles.title}>Édition</Text>
|
||||||
|
<Text style={styles.subtitle}>
|
||||||
|
{fileIds.length} fichier{fileIds.length > 1 ? 's' : ''} sélectionné{fileIds.length > 1 ? 's' : ''}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<FlatList
|
||||||
|
data={fileIds}
|
||||||
|
numColumns={NUM_COLUMNS}
|
||||||
|
keyExtractor={(item) => item}
|
||||||
|
contentContainerStyle={styles.grid}
|
||||||
|
columnWrapperStyle={styles.gridRow}
|
||||||
|
renderItem={({ item }) => <FileEditItem fileId={item} />}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<View style={styles.tagSection}>
|
||||||
|
<Text style={styles.sectionTitle}>Tags</Text>
|
||||||
|
<View style={styles.tagRow}>
|
||||||
|
{pendingTags.map((tag) => (
|
||||||
|
<TouchableOpacity key={tag} style={styles.tagChip} onPress={() => handleRemoveTag(tag)}>
|
||||||
|
<TagChip name={tag} onRemove={() => handleRemoveTag(tag)} />
|
||||||
|
</TouchableOpacity>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
<View style={styles.tagInputRow}>
|
||||||
|
<TextInput
|
||||||
|
style={styles.tagInput}
|
||||||
|
placeholder="Ajouter un tag..."
|
||||||
|
value={tagInput}
|
||||||
|
onChangeText={setTagInput}
|
||||||
|
onSubmitEditing={handleAddTag}
|
||||||
|
returnKeyType="done"
|
||||||
|
/>
|
||||||
|
<TouchableOpacity style={styles.tagAddBtn} onPress={handleAddTag}>
|
||||||
|
<MaterialIcons name="add" size={22} color="#fff" />
|
||||||
|
</TouchableOpacity>
|
||||||
|
</View>
|
||||||
|
{pendingTags.length > 0 && (
|
||||||
|
<TouchableOpacity style={styles.applyTagsBtn} onPress={handleApplyTags} disabled={addTags.isPending}>
|
||||||
|
{addTags.isPending ? (
|
||||||
|
<ActivityIndicator size="small" color="#fff" />
|
||||||
|
) : (
|
||||||
|
<Text style={styles.applyTagsText}>Appliquer les tags</Text>
|
||||||
|
)}
|
||||||
|
</TouchableOpacity>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View style={styles.footer}>
|
||||||
|
{(generating || uploading) && (
|
||||||
|
<View style={styles.progressRow}>
|
||||||
|
<ActivityIndicator size="small" color="#1976D2" />
|
||||||
|
<Text style={styles.progressText}>
|
||||||
|
{generating ? `Génération du PDF... ${progress}%` : 'Upload en cours...'}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
<TouchableOpacity
|
||||||
|
style={[styles.pdfBtn, isLoading && styles.pdfBtnDisabled]}
|
||||||
|
onPress={handleGeneratePdf}
|
||||||
|
disabled={isLoading}
|
||||||
|
>
|
||||||
|
{generating ? (
|
||||||
|
<ActivityIndicator size="small" color="#fff" />
|
||||||
|
) : (
|
||||||
|
<MaterialIcons name="picture-as-pdf" size={20} color="#fff" />
|
||||||
|
)}
|
||||||
|
<Text style={styles.pdfBtnText}>Créer un PDF</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
container: {
|
||||||
|
flex: 1,
|
||||||
|
backgroundColor: '#fff',
|
||||||
|
},
|
||||||
|
header: {
|
||||||
|
padding: 16,
|
||||||
|
borderBottomWidth: 1,
|
||||||
|
borderBottomColor: '#e0e0e0',
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: '700',
|
||||||
|
marginBottom: 4,
|
||||||
|
},
|
||||||
|
subtitle: {
|
||||||
|
fontSize: 14,
|
||||||
|
color: '#666',
|
||||||
|
},
|
||||||
|
grid: {
|
||||||
|
padding: 16,
|
||||||
|
},
|
||||||
|
gridRow: {
|
||||||
|
gap: 6,
|
||||||
|
},
|
||||||
|
gridItem: {
|
||||||
|
width: ITEM_SIZE,
|
||||||
|
height: ITEM_SIZE,
|
||||||
|
borderRadius: 6,
|
||||||
|
overflow: 'hidden',
|
||||||
|
backgroundColor: '#f0f0f0',
|
||||||
|
marginBottom: 6,
|
||||||
|
},
|
||||||
|
gridItemLoading: {
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
|
thumb: {
|
||||||
|
width: '100%',
|
||||||
|
height: '100%',
|
||||||
|
},
|
||||||
|
tagSection: {
|
||||||
|
padding: 16,
|
||||||
|
borderTopWidth: 1,
|
||||||
|
borderTopColor: '#e0e0e0',
|
||||||
|
},
|
||||||
|
sectionTitle: {
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: '600',
|
||||||
|
marginBottom: 8,
|
||||||
|
},
|
||||||
|
tagRow: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
flexWrap: 'wrap',
|
||||||
|
gap: 6,
|
||||||
|
marginBottom: 8,
|
||||||
|
},
|
||||||
|
tagChip: {
|
||||||
|
marginRight: 2,
|
||||||
|
},
|
||||||
|
tagInputRow: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
gap: 8,
|
||||||
|
},
|
||||||
|
tagInput: {
|
||||||
|
flex: 1,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: '#e0e0e0',
|
||||||
|
borderRadius: 8,
|
||||||
|
padding: 10,
|
||||||
|
fontSize: 14,
|
||||||
|
},
|
||||||
|
tagAddBtn: {
|
||||||
|
width: 40,
|
||||||
|
height: 40,
|
||||||
|
borderRadius: 8,
|
||||||
|
backgroundColor: '#1976D2',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
|
applyTagsBtn: {
|
||||||
|
marginTop: 10,
|
||||||
|
backgroundColor: '#4CAF50',
|
||||||
|
paddingVertical: 10,
|
||||||
|
borderRadius: 8,
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
|
applyTagsText: {
|
||||||
|
color: '#fff',
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: '600',
|
||||||
|
},
|
||||||
|
footer: {
|
||||||
|
padding: 16,
|
||||||
|
borderTopWidth: 1,
|
||||||
|
borderTopColor: '#e0e0e0',
|
||||||
|
gap: 8,
|
||||||
|
},
|
||||||
|
progressRow: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: 8,
|
||||||
|
},
|
||||||
|
progressText: {
|
||||||
|
fontSize: 14,
|
||||||
|
color: '#666',
|
||||||
|
},
|
||||||
|
pdfBtn: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
backgroundColor: '#1976D2',
|
||||||
|
paddingHorizontal: 24,
|
||||||
|
paddingVertical: 14,
|
||||||
|
borderRadius: 8,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: 8,
|
||||||
|
},
|
||||||
|
pdfBtnDisabled: {
|
||||||
|
opacity: 0.6,
|
||||||
|
},
|
||||||
|
pdfBtnText: {
|
||||||
|
color: '#fff',
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: '600',
|
||||||
|
},
|
||||||
|
});
|
||||||
+226
-39
@@ -1,10 +1,10 @@
|
|||||||
import React, { useState, useMemo, useEffect } from 'react';
|
import React, { useState, useMemo, useEffect, useCallback } from 'react';
|
||||||
import { View, FlatList, StyleSheet, TouchableOpacity, Text, Dimensions, KeyboardAvoidingView, Platform, Keyboard } from 'react-native';
|
import { View, FlatList, StyleSheet, TouchableOpacity, Text, Dimensions, KeyboardAvoidingView, Platform, Keyboard, Alert } from 'react-native';
|
||||||
import { useNavigation } from '@react-navigation/native';
|
import { useNavigation } from '@react-navigation/native';
|
||||||
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
||||||
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
||||||
import { MaterialIcons } from '@expo/vector-icons';
|
import { MaterialIcons } from '@expo/vector-icons';
|
||||||
import { useFiles, useFileImage } from '../hooks/useFiles';
|
import { useFiles, useFileImage, useDeleteFile } from '../hooks/useFiles';
|
||||||
import { FileItem } from '../types';
|
import { FileItem } from '../types';
|
||||||
import { SearchBar, SearchFilters } from '../components/SearchBar';
|
import { SearchBar, SearchFilters } from '../components/SearchBar';
|
||||||
import { FileThumbnail } from '../components/FileThumbnail';
|
import { FileThumbnail } from '../components/FileThumbnail';
|
||||||
@@ -18,6 +18,7 @@ type RootStackParamList = {
|
|||||||
Upload: undefined;
|
Upload: undefined;
|
||||||
Scan: undefined;
|
Scan: undefined;
|
||||||
FileDetail: { fileIds: string[]; initialIndex: number };
|
FileDetail: { fileIds: string[]; initialIndex: number };
|
||||||
|
FileEdit: { fileIds: string[] };
|
||||||
};
|
};
|
||||||
|
|
||||||
type NavigationProp = NativeStackNavigationProp<RootStackParamList>;
|
type NavigationProp = NativeStackNavigationProp<RootStackParamList>;
|
||||||
@@ -55,11 +56,17 @@ function formatDateLabel(key: string): string {
|
|||||||
return key.charAt(0).toUpperCase() + key.slice(1);
|
return key.charAt(0).toUpperCase() + key.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function FileGridItem({ file, onPress }: { file: FileItem; onPress?: () => void }) {
|
function FileGridItem({ file, onPress, onLongPress, selected }: { file: FileItem; onPress?: () => void; onLongPress?: () => void; selected?: boolean }) {
|
||||||
const { data, isLoading } = useFileImage(file.id);
|
const { data, isLoading } = useFileImage(file.id);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TouchableOpacity style={styles.gridItem} onPress={onPress} activeOpacity={0.7}>
|
<TouchableOpacity
|
||||||
|
style={[styles.gridItem, selected && styles.gridItemSelected]}
|
||||||
|
onPress={onPress}
|
||||||
|
onLongPress={onLongPress}
|
||||||
|
delayLongPress={400}
|
||||||
|
activeOpacity={0.7}
|
||||||
|
>
|
||||||
<FileThumbnail
|
<FileThumbnail
|
||||||
uri={data?.data?.url}
|
uri={data?.data?.url}
|
||||||
mimeType={file.mimeType}
|
mimeType={file.mimeType}
|
||||||
@@ -67,6 +74,13 @@ function FileGridItem({ file, onPress }: { file: FileItem; onPress?: () => void
|
|||||||
size={ITEM_SIZE}
|
size={ITEM_SIZE}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
/>
|
/>
|
||||||
|
{selected && (
|
||||||
|
<View style={styles.selectedOverlay}>
|
||||||
|
<View style={styles.checkCircle}>
|
||||||
|
<MaterialIcons name="check" size={18} color="#fff" />
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
<Text style={styles.fileName} numberOfLines={1}>{file.name}</Text>
|
<Text style={styles.fileName} numberOfLines={1}>{file.name}</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
);
|
);
|
||||||
@@ -96,9 +110,11 @@ export function HomeScreen() {
|
|||||||
const navigation = useNavigation<NavigationProp>();
|
const navigation = useNavigation<NavigationProp>();
|
||||||
const insets = useSafeAreaInsets();
|
const insets = useSafeAreaInsets();
|
||||||
const { data, isLoading, error } = useFiles();
|
const { data, isLoading, error } = useFiles();
|
||||||
|
const deleteFile = useDeleteFile();
|
||||||
const [searchQuery, setSearchQuery] = useState('');
|
const [searchQuery, setSearchQuery] = useState('');
|
||||||
const [filters, setFilters] = useState<SearchFilters>({ name: true, ocrText: true, tags: true });
|
const [filters, setFilters] = useState<SearchFilters>({ name: true, ocrText: true, tags: true });
|
||||||
const [keyboardOpen, setKeyboardOpen] = useState(false);
|
const [keyboardOpen, setKeyboardOpen] = useState(false);
|
||||||
|
const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set());
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const show = Keyboard.addListener('keyboardDidShow', () => setKeyboardOpen(true));
|
const show = Keyboard.addListener('keyboardDidShow', () => setKeyboardOpen(true));
|
||||||
@@ -106,6 +122,8 @@ export function HomeScreen() {
|
|||||||
return () => { show.remove(); hide.remove(); };
|
return () => { show.remove(); hide.remove(); };
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const selectionMode = selectedIds.size > 0;
|
||||||
|
|
||||||
const files = data?.data ?? [];
|
const files = data?.data ?? [];
|
||||||
|
|
||||||
const filteredFiles = useMemo(
|
const filteredFiles = useMemo(
|
||||||
@@ -122,6 +140,67 @@ export function HomeScreen() {
|
|||||||
return map;
|
return map;
|
||||||
}, [filteredFiles]);
|
}, [filteredFiles]);
|
||||||
|
|
||||||
|
const toggleSelection = useCallback((id: string) => {
|
||||||
|
setSelectedIds((prev) => {
|
||||||
|
const next = new Set(prev);
|
||||||
|
if (next.has(id)) next.delete(id);
|
||||||
|
else next.add(id);
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const clearSelection = useCallback(() => {
|
||||||
|
setSelectedIds(new Set());
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleDelete = useCallback(() => {
|
||||||
|
const count = selectedIds.size;
|
||||||
|
if (count === 0) return;
|
||||||
|
const label = count === 1 ? 'ce fichier' : `ces ${count} fichiers`;
|
||||||
|
Alert.alert(
|
||||||
|
'Supprimer',
|
||||||
|
`Supprimer ${label} ?`,
|
||||||
|
[
|
||||||
|
{ text: 'Annuler', style: 'cancel' },
|
||||||
|
{
|
||||||
|
text: 'Supprimer',
|
||||||
|
style: 'destructive',
|
||||||
|
onPress: async () => {
|
||||||
|
const ids = Array.from(selectedIds);
|
||||||
|
for (const id of ids) {
|
||||||
|
await deleteFile.mutateAsync(id);
|
||||||
|
}
|
||||||
|
setSelectedIds(new Set());
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}, [selectedIds, deleteFile]);
|
||||||
|
|
||||||
|
const handleEdit = useCallback(() => {
|
||||||
|
const ids = Array.from(selectedIds);
|
||||||
|
if (ids.length === 0) return;
|
||||||
|
navigation.navigate('FileEdit', { fileIds: ids });
|
||||||
|
setSelectedIds(new Set());
|
||||||
|
}, [selectedIds, navigation]);
|
||||||
|
|
||||||
|
const handleItemPress = useCallback((file: FileItem) => {
|
||||||
|
if (selectionMode) {
|
||||||
|
toggleSelection(file.id);
|
||||||
|
} else {
|
||||||
|
navigation.navigate('FileDetail', {
|
||||||
|
fileIds: filteredFiles.map((f) => f.id),
|
||||||
|
initialIndex: fileIdToIndex.get(file.id) ?? 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [selectionMode, toggleSelection, navigation, filteredFiles, fileIdToIndex]);
|
||||||
|
|
||||||
|
const handleItemLongPress = useCallback((file: FileItem) => {
|
||||||
|
if (!selectionMode) {
|
||||||
|
toggleSelection(file.id);
|
||||||
|
}
|
||||||
|
}, [selectionMode, toggleSelection]);
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
<View style={styles.center}>
|
<View style={styles.center}>
|
||||||
@@ -167,12 +246,9 @@ export function HomeScreen() {
|
|||||||
<FileGridItem
|
<FileGridItem
|
||||||
key={file.id}
|
key={file.id}
|
||||||
file={file}
|
file={file}
|
||||||
onPress={() =>
|
selected={selectedIds.has(file.id)}
|
||||||
navigation.navigate('FileDetail', {
|
onPress={() => handleItemPress(file)}
|
||||||
fileIds: filteredFiles.map((f) => f.id),
|
onLongPress={() => handleItemLongPress(file)}
|
||||||
initialIndex: fileIdToIndex.get(file.id) ?? 0,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
@@ -181,37 +257,71 @@ export function HomeScreen() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<SearchBar
|
{!selectionMode && (
|
||||||
query={searchQuery}
|
<SearchBar
|
||||||
onQueryChange={setSearchQuery}
|
query={searchQuery}
|
||||||
onClear={() => setSearchQuery('')}
|
onQueryChange={setSearchQuery}
|
||||||
filters={filters}
|
onClear={() => setSearchQuery('')}
|
||||||
onFiltersChange={setFilters}
|
filters={filters}
|
||||||
bottomPadding={keyboardOpen ? insets.bottom+8 : 0}
|
onFiltersChange={setFilters}
|
||||||
/>
|
bottomPadding={keyboardOpen ? insets.bottom+8 : 0}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
<View style={styles.bottomNav}>
|
{selectionMode ? (
|
||||||
<TouchableOpacity style={styles.navButton} onPress={() => {}}>
|
<View style={[styles.selectionBar, { paddingBottom: insets.bottom + 8 }]}>
|
||||||
<MaterialIcons name="home" size={24} color="#1976D2" />
|
<View style={styles.selectionHeader}>
|
||||||
<Text style={styles.navText}>Accueil</Text>
|
<TouchableOpacity onPress={clearSelection} style={styles.cancelBtn}>
|
||||||
</TouchableOpacity>
|
<MaterialIcons name="close" size={22} color="#333" />
|
||||||
|
</TouchableOpacity>
|
||||||
|
<Text style={styles.selectionCount}>
|
||||||
|
{selectedIds.size} sélectionnée{selectedIds.size > 1 ? 's' : ''}
|
||||||
|
</Text>
|
||||||
|
<TouchableOpacity onPress={clearSelection} style={styles.selectAllBtn}>
|
||||||
|
<Text style={styles.selectAllText}>Tout</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</View>
|
||||||
|
<View style={styles.selectionActions}>
|
||||||
|
<TouchableOpacity
|
||||||
|
style={[styles.selectionActionBtn, styles.deleteActionBtn]}
|
||||||
|
onPress={handleDelete}
|
||||||
|
>
|
||||||
|
<MaterialIcons name="delete" size={20} color="#F44336" />
|
||||||
|
<Text style={[styles.selectionActionText, { color: '#F44336' }]}>Supprimer</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
<TouchableOpacity
|
||||||
|
style={[styles.selectionActionBtn, styles.editActionBtn]}
|
||||||
|
onPress={handleEdit}
|
||||||
|
>
|
||||||
|
<MaterialIcons name="edit" size={20} color="#1976D2" />
|
||||||
|
<Text style={[styles.selectionActionText, { color: '#1976D2' }]}>Éditer</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
) : (
|
||||||
|
<View style={styles.bottomNav}>
|
||||||
|
<TouchableOpacity style={styles.navButton} onPress={() => {}}>
|
||||||
|
<MaterialIcons name="home" size={24} color="#1976D2" />
|
||||||
|
<Text style={styles.navText}>Accueil</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
style={styles.navButton}
|
style={styles.navButton}
|
||||||
onPress={() => navigation.navigate('Upload')}
|
onPress={() => navigation.navigate('Upload')}
|
||||||
>
|
>
|
||||||
<MaterialIcons name="cloud-upload" size={24} color="#1976D2" />
|
<MaterialIcons name="cloud-upload" size={24} color="#1976D2" />
|
||||||
<Text style={styles.navText}>Upload</Text>
|
<Text style={styles.navText}>Upload</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
|
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
style={styles.navButton}
|
style={styles.navButton}
|
||||||
onPress={() => navigation.navigate('Scan')}
|
onPress={() => navigation.navigate('Scan')}
|
||||||
>
|
>
|
||||||
<MaterialIcons name="document-scanner" size={24} color="#1976D2" />
|
<MaterialIcons name="document-scanner" size={24} color="#1976D2" />
|
||||||
<Text style={styles.navText}>Scan</Text>
|
<Text style={styles.navText}>Scan</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
</View>
|
</View>
|
||||||
|
)}
|
||||||
</KeyboardAvoidingView>
|
</KeyboardAvoidingView>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -259,6 +369,27 @@ const styles = StyleSheet.create({
|
|||||||
gridItem: {
|
gridItem: {
|
||||||
width: ITEM_SIZE,
|
width: ITEM_SIZE,
|
||||||
},
|
},
|
||||||
|
gridItemSelected: {
|
||||||
|
opacity: 0.85,
|
||||||
|
},
|
||||||
|
selectedOverlay: {
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: 18,
|
||||||
|
justifyContent: 'flex-start',
|
||||||
|
alignItems: 'flex-end',
|
||||||
|
padding: 4,
|
||||||
|
},
|
||||||
|
checkCircle: {
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
borderRadius: 12,
|
||||||
|
backgroundColor: '#1976D2',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
fileName: {
|
fileName: {
|
||||||
fontSize: 11,
|
fontSize: 11,
|
||||||
color: '#666',
|
color: '#666',
|
||||||
@@ -282,4 +413,60 @@ const styles = StyleSheet.create({
|
|||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
color: '#1976D2',
|
color: '#1976D2',
|
||||||
},
|
},
|
||||||
|
selectionBar: {
|
||||||
|
backgroundColor: '#fff',
|
||||||
|
borderTopWidth: 1,
|
||||||
|
borderTopColor: '#e0e0e0',
|
||||||
|
paddingHorizontal: 16,
|
||||||
|
paddingTop: 12,
|
||||||
|
},
|
||||||
|
selectionHeader: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
marginBottom: 12,
|
||||||
|
},
|
||||||
|
cancelBtn: {
|
||||||
|
padding: 4,
|
||||||
|
},
|
||||||
|
selectionCount: {
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: '600',
|
||||||
|
color: '#333',
|
||||||
|
},
|
||||||
|
selectAllBtn: {
|
||||||
|
paddingHorizontal: 8,
|
||||||
|
paddingVertical: 4,
|
||||||
|
},
|
||||||
|
selectAllText: {
|
||||||
|
fontSize: 14,
|
||||||
|
color: '#1976D2',
|
||||||
|
fontWeight: '600',
|
||||||
|
},
|
||||||
|
selectionActions: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
gap: 12,
|
||||||
|
},
|
||||||
|
selectionActionBtn: {
|
||||||
|
flex: 1,
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
paddingVertical: 12,
|
||||||
|
borderRadius: 8,
|
||||||
|
gap: 6,
|
||||||
|
borderWidth: 1.5,
|
||||||
|
},
|
||||||
|
deleteActionBtn: {
|
||||||
|
borderColor: '#F44336',
|
||||||
|
backgroundColor: 'transparent',
|
||||||
|
},
|
||||||
|
editActionBtn: {
|
||||||
|
borderColor: '#1976D2',
|
||||||
|
backgroundColor: 'transparent',
|
||||||
|
},
|
||||||
|
selectionActionText: {
|
||||||
|
fontSize: 15,
|
||||||
|
fontWeight: '600',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user