mirror of
https://github.com/siop-spelev/siop2.git
synced 2026-08-08 12:41:54 +00:00
feat(r4.3): file d'écriture, verrou optimiste D2, Synchro & conflits
Serveur : updatedAt exposé au détail OT ; baseUpdatedAt optionnel sur transition/coche/bilan → 409 « Conflit de version » contextualisé (qui, quand) ; toute écriture secondaire (coche, bilan, commentaire, conso, MO) fait avancer la version — sans version fournie, le web est inchangé. ADR-003 : sécurité & protocole de routage mobile (qui vit où sur l'appareil, purge complète à la déconnexion — correctif réel : la file et le cache persisté survivaient au logout). Mobile : file persistée AsyncStorage rejouée dans l'ordre — succès → propagation de la version fraîche aux saisies restantes du même OT (nos écritures ne se conflictent pas entre elles, un écart étranger reste détecté) ; coupure → tout attend ; refus → CONFLIT, la file s'arrête, l'humain tranche (voir l'OT / rejouer sur version à jour / abandonner). Transitions, coches, bilan et photos (D5, compressées ~1600 px) passent par la file avec patch optimiste du cache ; écran Synchro (badge tabbar ambre/rouge) ; préchargement parc + référentiels (le bilan hors-ligne a ses vocabulaires). Recette « mode avion » 13/13 en Expo web piloté : gestes hors-ligne → 3 en file → modification concurrente de Salma → conflit tranché → serveur Terminé avec bilan. 17 tests jest-expo, 74 tests API. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,30 +1,38 @@
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { useLocalSearchParams } from 'expo-router';
|
||||
import { Alert, Pressable, ScrollView, Text, View } from 'react-native';
|
||||
import { Pressable, ScrollView, Text, View } from 'react-native';
|
||||
import { SafeAreaView } from 'react-native-safe-area-context';
|
||||
import { useCocheChecklist, useWorkOrder } from '@/api/exploitation';
|
||||
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. En R4.2 chaque coche part immédiatement à
|
||||
* l'API (hors-ligne : lecture seule — la file individuelle arrive en R4.3). */
|
||||
* 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 coche = useCocheChecklist(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 = (itemId: string, etat: Parameters<typeof prochainEtat>[0], versNA = false) => {
|
||||
if (horsLigne) return;
|
||||
coche.mutate(
|
||||
{ itemId, state: versNA ? (etat === 'NA' ? 'PENDING' : 'NA') : prochainEtat(etat) },
|
||||
{ onError: (e) => Alert.alert('Coche refusée', e.message) },
|
||||
const basculer = (item: { id: string; label: string }, etat: Parameters<typeof prochainEtat>[0], versNA = false) => {
|
||||
enfilerCoche(
|
||||
queryClient,
|
||||
ot,
|
||||
item,
|
||||
versNA ? (etat === 'NA' ? 'PENDING' : 'NA') : prochainEtat(etat),
|
||||
);
|
||||
};
|
||||
|
||||
@@ -55,8 +63,7 @@ export default function PageGrille() {
|
||||
}}
|
||||
>
|
||||
<Text style={{ color: t.stAttente, fontFamily: 'Manrope_700Bold', fontSize: 12 }}>
|
||||
⚠ Hors-ligne — les coches en file arrivent en R4.3 ; pour l’instant la grille est en
|
||||
lecture.
|
||||
⚠ Hors-ligne — chaque coche part en file et se synchronisera au retour du réseau.
|
||||
</Text>
|
||||
</View>
|
||||
) : null}
|
||||
@@ -66,9 +73,8 @@ export default function PageGrille() {
|
||||
accessibilityRole="checkbox"
|
||||
aria-checked={item.state === 'DONE'}
|
||||
accessibilityLabel={item.label}
|
||||
disabled={horsLigne || coche.isPending}
|
||||
onPress={() => basculer(item.id, item.state)}
|
||||
onLongPress={() => basculer(item.id, item.state, true)}
|
||||
onPress={() => basculer(item, item.state)}
|
||||
onLongPress={() => basculer(item, item.state, true)}
|
||||
style={{
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
@@ -109,7 +115,21 @@ export default function PageGrille() {
|
||||
>
|
||||
{item.label}
|
||||
</Text>
|
||||
{item.doneBy ? (
|
||||
{enFile.has(item.id) ? (
|
||||
<Text
|
||||
style={{
|
||||
fontFamily: 'Manrope_800ExtraBold',
|
||||
fontSize: 9,
|
||||
color: t.stAttente,
|
||||
backgroundColor: t.stAttenteFond,
|
||||
paddingHorizontal: 6,
|
||||
borderRadius: 999,
|
||||
overflow: 'hidden',
|
||||
}}
|
||||
>
|
||||
en file
|
||||
</Text>
|
||||
) : item.doneBy ? (
|
||||
<Text style={{ fontFamily: 'Manrope_400Regular', fontSize: 10.5, color: t.encre3 }}>
|
||||
{item.doneBy.displayName.split(' ')[0]}
|
||||
</Text>
|
||||
|
||||
Reference in New Issue
Block a user