On ne récupère que ses propres trains empruntés
This commit is contained in:
parent
a4a0981b2c
commit
bfc6069a87
@ -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 />
|
||||
</>
|
||||
}
|
||||
|
@ -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(() => {
|
||||
|
Loading…
Reference in New Issue
Block a user