On ne récupère que ses propres trains empruntés

This commit is contained in:
Emmy D'Anello 2024-12-12 15:38:47 +01:00
parent a4a0981b2c
commit bfc6069a87
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
2 changed files with 6 additions and 5 deletions

View File

@ -5,7 +5,7 @@ import { TrainTrip } from '@/utils/features/train/trainSlice'
import { FontAwesome6 } from '@expo/vector-icons'
import { useMemo, useState } from 'react'
import { FlatList, StyleSheet } from 'react-native'
import { Badge, Button, Dialog, Divider, FAB, HelperText, List, Portal, Surface, Text, TextInput } from 'react-native-paper'
import { Button, Dialog, Divider, FAB, HelperText, List, Portal, Surface, Text, TextInput } from 'react-native-paper'
export default function TrainScreen() {
const [addTrainVisible, setAddTrainVisible] = useState(false)
@ -24,6 +24,8 @@ export default function TrainScreen() {
<Surface style={{ flex: 1 }}>
<FlatList
data={trains.trains}
keyExtractor={(train) => train.id}
ItemSeparatorComponent={() => <Divider />}
renderItem={(item) => <TrainListItem train={item.item} />} />
<FAB
icon='plus'
@ -87,6 +89,5 @@ function TrainListItem({ train }: { train: TrainTrip }) {
title={title}
description={<><Text>Durée : {duration}, distance : {distanceKm} km, coût : {cost}</Text> <FontAwesome6 name='coins' /></>}
/>
<Divider />
</>
}

View File

@ -39,11 +39,11 @@ export default function GameProvider({ children }: { children: ReactNode }) {
}, [playerQuery.status, playerQuery.dataUpdatedAt])
const trainsQuery = useQuery({
queryKey: ['get-trains', auth.token],
queryFn: () => fetch(`${process.env.EXPO_PUBLIC_TRAINTRAPE_MOI_SERVER}/trains/`, {
queryKey: ['get-trains', game.playerId, auth.token],
queryFn: () => fetch(`${process.env.EXPO_PUBLIC_TRAINTRAPE_MOI_SERVER}/trains/?playerId=${game.playerId}`, {
headers: { "Authorization": `Bearer ${auth.token}` }}
).then(resp => resp.json()),
enabled: isAuthValid(auth),
enabled: isAuthValid(auth) && !game.playerId,
refetchInterval: 5000,
})
useEffect(() => {