diff --git a/src/components/gpx-chooser/GpxChooser.tsx b/src/components/gpx-chooser/GpxChooser.tsx new file mode 100644 index 0000000..6fdeddc --- /dev/null +++ b/src/components/gpx-chooser/GpxChooser.tsx @@ -0,0 +1,62 @@ +import { useI18n } from '@solid-primitives/i18n'; +import { FormControl, InputLabel, NativeSelect } from '@suid/material'; +import { Component, createSignal, For } from 'solid-js'; +import dispatch from '../../workers/dispatcher-main'; + +interface Props { + gpxId: () => string; + setGpxId: (id: string) => void; +} + +const GpxChooser: Component = (props: Props) => { + const { gpxId, setGpxId } = props; + + const [t] = useI18n(); + + const [allGpxes, setAllGpxes] = createSignal([ + { id: 'new', name: t('newGpx'), creator: 'dyomedea' }, + ]); + + dispatch( + { + action: 'getAllGpxesWithSummary', + }, + (error, result) => { + if (!error) { + setAllGpxes([ + { id: 'new', name: t('newGpx'), creator: 'dyomedea' }, + ...result, + ]); + } + } + ); + + const gpxChangeHandler = async (event: any) => { + setGpxId(event.target.value); + }; + + return ( + + + {t('gpxChooser')} + + + + {(gpx) => ( + + )} + + + + ); +}; + +export default GpxChooser; diff --git a/src/components/gpx-chooser/index.ts b/src/components/gpx-chooser/index.ts new file mode 100644 index 0000000..ee21f15 --- /dev/null +++ b/src/components/gpx-chooser/index.ts @@ -0,0 +1 @@ +export { default } from './GpxChooser'; diff --git a/src/components/gpx-dialog/GpxDialog.tsx b/src/components/gpx-dialog/GpxDialog.tsx index be04b63..b315155 100644 --- a/src/components/gpx-dialog/GpxDialog.tsx +++ b/src/components/gpx-dialog/GpxDialog.tsx @@ -14,6 +14,7 @@ import { cloneDeep } from 'lodash'; import { Component, createSignal, For, Show } from 'solid-js'; import dispatch from '../../workers/dispatcher-main'; import Dialog from '../dialog'; +import GpxChooser from '../gpx-chooser'; //import GpxesIcon from '../../icons/adventure-journey-location-svgrepo-com.svg'; import style from './GpxDialog.module.css'; @@ -22,7 +23,7 @@ export const [currentGpxId, setCurrentGpxId] = createSignal('new'); const GpxDialog: Component<{}> = (props) => { const [t] = useI18n(); const [open, setOpen] = createSignal(false); - const [allGpxes, setAllGpxes] = createSignal([]); + const [selectedGpxId, setSelectedGpxId] = createSignal(''); const [gpx, setGpx] = createSignal(); @@ -30,13 +31,6 @@ const GpxDialog: Component<{}> = (props) => { const handleClickOpen = async () => { setOpen(true); - const newAllGpxes = (await dispatch({ - action: 'getAllGpxesWithSummary', - })) as any[]; - setAllGpxes([ - { id: 'new', name: t('newGpx'), creator: 'dyomedea' }, - ...newAllGpxes, - ]); setSelectedGpxId(currentGpxId()); if (currentGpxId() !== '') { const newGpx = await dispatch({ @@ -63,18 +57,17 @@ const GpxDialog: Component<{}> = (props) => { setOpen(false); } }; - const gpxChangeHandler = async (event: any) => { - setSelectedGpxId(event.target.value); + const gpxChangeHandler = async (gpxId: string) => { + setSelectedGpxId(gpxId); const newGpx = await dispatch({ action: 'getGpx', params: { - id: event.target.value, + id: gpxId, }, }); setGpx(newGpx as Gpx); console.log({ caller: 'GpxDialog / gpxChangeHandler', - value: event.target.value, gpx: gpx(), }); }; @@ -172,26 +165,8 @@ const GpxDialog: Component<{}> = (props) => { noValidate autoComplete='off' > - - - {t('gpxChooser')} - - - - {(gpx) => ( - - )} - - - + + { width: '100%', }} > - + + {(gpxFile) => } + diff --git a/src/components/gpx-import/GpxImportSingleFile.tsx b/src/components/gpx-import/GpxImportSingleFile.tsx index d2f136e..5c44c7f 100644 --- a/src/components/gpx-import/GpxImportSingleFile.tsx +++ b/src/components/gpx-import/GpxImportSingleFile.tsx @@ -10,6 +10,11 @@ import { Divider, FormControl, FormLabel, + Card, + CardContent, + CardActions, + CardHeader, + Button, } from '@suid/material'; import { Component, createEffect, createSignal, Show } from 'solid-js'; import { findStartTime } from '../../lib/gpx'; @@ -48,6 +53,7 @@ const analyzeGpx = (gpx: Gpx | undefined) => { const GpxImportSingleFile: Component = ({ gpxFile }) => { const [t] = useI18n(); const [statsAndGpx, setStatsAndGpx] = createSignal(); + const [state, setState] = createSignal('init'); const gpxReader = new FileReader(); gpxReader.readAsText(gpxFile); @@ -71,6 +77,10 @@ const GpxImportSingleFile: Component = ({ gpxFile }) => { false ); + const doImport = () => { + setState('imported'); + }; + const [selectedTrkTransform, setSelectedTrkTransform] = createSignal( 'importNonTimedTrksAsRtes' ); @@ -89,30 +99,26 @@ const GpxImportSingleFile: Component = ({ gpxFile }) => { }); return ( - - - + + + {t('file')} {gpxFile.name} - - - + + + {t('gpxStats', statsAndGpx().stats)}{' '} {statsAndGpx()?.stats.startTime ? t('gpxStartTime', statsAndGpx().stats) : t('gpxNoStartTime')} - - - + {t('trkMaybeRte')} - - - 0}> - - + + {/* 0}> + {t('importTrk')} = ({ gpxFile }) => { /> - + */} - - + + + + + ); }; diff --git a/src/i18n/fr.ts b/src/i18n/fr.ts index 0f2a300..c7b853a 100644 --- a/src/i18n/fr.ts +++ b/src/i18n/fr.ts @@ -24,6 +24,8 @@ const dict = { cancel: 'ANNULER', gpxImport: 'Import de fichier(s) GPX ', + import: 'Importer', + file: 'Fichier\u00a0: ', gpxStats: 'Ce fichier a été créé avec "{{creator}}" et contient {{nbWpts}} lieu(x), {{nbRtes}} itineraire(s) et {{nbTrks}} trace(s).',