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 { FontAwesome6 } from '@expo/vector-icons'
|
||||||
import { useMemo, useState } from 'react'
|
import { useMemo, useState } from 'react'
|
||||||
import { FlatList, StyleSheet } from 'react-native'
|
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() {
|
export default function TrainScreen() {
|
||||||
const [addTrainVisible, setAddTrainVisible] = useState(false)
|
const [addTrainVisible, setAddTrainVisible] = useState(false)
|
||||||
@ -24,6 +24,8 @@ export default function TrainScreen() {
|
|||||||
<Surface style={{ flex: 1 }}>
|
<Surface style={{ flex: 1 }}>
|
||||||
<FlatList
|
<FlatList
|
||||||
data={trains.trains}
|
data={trains.trains}
|
||||||
|
keyExtractor={(train) => train.id}
|
||||||
|
ItemSeparatorComponent={() => <Divider />}
|
||||||
renderItem={(item) => <TrainListItem train={item.item} />} />
|
renderItem={(item) => <TrainListItem train={item.item} />} />
|
||||||
<FAB
|
<FAB
|
||||||
icon='plus'
|
icon='plus'
|
||||||
@ -87,6 +89,5 @@ function TrainListItem({ train }: { train: TrainTrip }) {
|
|||||||
title={title}
|
title={title}
|
||||||
description={<><Text>Durée : {duration}, distance : {distanceKm} km, coût : {cost}</Text> <FontAwesome6 name='coins' /></>}
|
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])
|
}, [playerQuery.status, playerQuery.dataUpdatedAt])
|
||||||
|
|
||||||
const trainsQuery = useQuery({
|
const trainsQuery = useQuery({
|
||||||
queryKey: ['get-trains', auth.token],
|
queryKey: ['get-trains', game.playerId, auth.token],
|
||||||
queryFn: () => fetch(`${process.env.EXPO_PUBLIC_TRAINTRAPE_MOI_SERVER}/trains/`, {
|
queryFn: () => fetch(`${process.env.EXPO_PUBLIC_TRAINTRAPE_MOI_SERVER}/trains/?playerId=${game.playerId}`, {
|
||||||
headers: { "Authorization": `Bearer ${auth.token}` }}
|
headers: { "Authorization": `Bearer ${auth.token}` }}
|
||||||
).then(resp => resp.json()),
|
).then(resp => resp.json()),
|
||||||
enabled: isAuthValid(auth),
|
enabled: isAuthValid(auth) && !game.playerId,
|
||||||
refetchInterval: 5000,
|
refetchInterval: 5000,
|
||||||
})
|
})
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user