Importation automatique d'un train depuis Rail Planner par partage de l'URL d'un trajet
This commit is contained in:
@ -5,7 +5,8 @@ import { useTrain } from '@/hooks/useTrain'
|
||||
import { TrainTrip } from '@/utils/features/train/trainSlice'
|
||||
import { FontAwesome6 } from '@expo/vector-icons'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
import { useMemo, useState } from 'react'
|
||||
import { useShareIntentContext } from 'expo-share-intent'
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { FlatList, StyleSheet } from 'react-native'
|
||||
import { Button, Dialog, Divider, FAB, HelperText, List, MD3Colors, Portal, Snackbar, Surface, Text, TextInput } from 'react-native-paper'
|
||||
|
||||
@ -38,6 +39,24 @@ export default function TrainScreen() {
|
||||
|
||||
const trains = useTrain()
|
||||
|
||||
|
||||
const { hasShareIntent, shareIntent, resetShareIntent } = useShareIntentContext()
|
||||
useEffect(() => {
|
||||
console.log(hasShareIntent, shareIntent)
|
||||
if (hasShareIntent) {
|
||||
resetShareIntent()
|
||||
if (!shareIntent.text || !shareIntent.text.includes("eurailapp.com/share"))
|
||||
return
|
||||
const parsedTrainId = /[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}/.exec(shareIntent.text)?.[0]
|
||||
if (parsedTrainId)
|
||||
addTrainMutation.mutate(parsedTrainId)
|
||||
else {
|
||||
setErrorVisible(true)
|
||||
setError([400, "Impossible de récupérer l'identifiant du train à ajouter"])
|
||||
}
|
||||
}
|
||||
}, [hasShareIntent])
|
||||
|
||||
return (
|
||||
<Surface style={{ flex: 1 }}>
|
||||
<PenaltyBanner />
|
||||
|
Reference in New Issue
Block a user