import { useQueryClient } from '@tanstack/react-query'; import { useLocalSearchParams } from 'expo-router'; import { Pressable, ScrollView, Text, View } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; import { useWorkOrder } from '@/api/exploitation'; import { useHorsLigne } from '@/auth/session'; import { EnteteFiche } from '@/composants/ui'; import { enfilerCoche } from '@/file/actions'; import { useFile } from '@/file/store'; import { prochainEtat, progression } from '@/lib/checklist'; import { useTokens } from '@/theme/tokens'; /** Écran 6 de la maquette R4 : la grille au pouce. Appui simple = coche, * appui long = non-applicable. Chaque coche part en file INDIVIDUELLEMENT * (D1) : 7 coches faites = 7 coches sauvées, réseau ou pas. */ export default function PageGrille() { const t = useTokens(); const horsLigne = useHorsLigne(); const { id } = useLocalSearchParams<{ id: string }>(); const { data: ot } = useWorkOrder(id); const queryClient = useQueryClient(); const file = useFile(); if (!ot) return null; const { faits, total, pct } = progression(ot.checklist); const enFile = new Set( file.flatMap((s) => (s.otId === ot.id && s.type === 'COCHE' ? [s.payload.itemId] : [])), ); const basculer = (item: { id: string; label: string }, etat: Parameters[0], versNA = false) => { enfilerCoche( queryClient, ot, item, versNA ? (etat === 'NA' ? 'PENDING' : 'NA') : prochainEtat(etat), ); }; return ( {faits}/{total} } /> {horsLigne ? ( ⚠ Hors-ligne — chaque coche part en file et se synchronisera au retour du réseau. ) : null} {ot.checklist.map((item) => ( basculer(item, item.state)} onLongPress={() => basculer(item, item.state, true)} style={{ flexDirection: 'row', alignItems: 'center', gap: 10, backgroundColor: t.surface, borderColor: t.bordure, borderWidth: 1, borderRadius: 10, paddingHorizontal: 12, paddingVertical: 11, }} > {item.state === 'DONE' ? ( ) : item.state === 'NA' ? ( NA ) : null} {item.label} {enFile.has(item.id) ? ( en file ) : item.doneBy ? ( {item.doneBy.displayName.split(' ')[0]} ) : null} ))} Appui simple : cocher / décocher · appui long : non-applicable. ); }