diff --git a/src/components/gpx-import/GpxImport.tsx b/src/components/gpx-import/GpxImport.tsx index 01d409a..a216998 100644 --- a/src/components/gpx-import/GpxImport.tsx +++ b/src/components/gpx-import/GpxImport.tsx @@ -21,50 +21,6 @@ const GpxImport: Component = () => { files: event.target.files, }); setFilesToImport(event.target.files); - // for (const file of event.target.files) { - // const fileReader = new FileReader(); - // fileReader.readAsText(file); - - // fileReader.addEventListener( - // 'load', - // async () => { - // // this will then display a text file - // console.log({ - // caller: 'GpxImport / XML', - // file, - // result: fileReader.result, - // }); - // const gpx = GPX.parse(fileReader.result); - // console.log({ caller: 'GpxImport / JSON', file, gpx }); - // if (gpx) { - // const startTime = new Date(findStartTime(gpx)!); - // await dispatch({ - // action: 'pruneAndSaveImportedGpx', - // params: { - // id: { gpx: intToGpxId(startTime.valueOf()) }, - // gpx: gpx, - // tech: { - // lastModified: new Date(file.lastModified).toISOString(), - // importDate: new Date().toISOString(), - // name: file.name, - // size: file.size, - // type: file.type, - // }, - // }, - // }); - // console.log({ caller: 'GpxImport / JSON / done', file, gpx }); - // } else { - // console.error({ - // message: "can't parse GPX file", - // file, - // xml: fileReader.result, - // }); - // } - // // TODO: error handling - // }, - // false - // ); - // } }; const handleClose = (event: any, reason?: string) => { diff --git a/src/components/gpx-import/GpxImportSingleFile.tsx b/src/components/gpx-import/GpxImportSingleFile.tsx index dfb7194..96e591c 100644 --- a/src/components/gpx-import/GpxImportSingleFile.tsx +++ b/src/components/gpx-import/GpxImportSingleFile.tsx @@ -12,6 +12,7 @@ import { import { Component, createEffect, createSignal, Show } from 'solid-js'; import { findStartTime } from '../../lib/gpx'; import GPX from '../../lib/gpx-parser-builder/src/gpx'; +import dispatch from '../../workers/dispatcher-main'; import GpxChooser from '../gpx-chooser'; import { currentGpxId } from '../gpx-dialog'; @@ -76,8 +77,58 @@ const GpxImportSingleFile: Component = ({ gpxFile }) => { false ); - const doImport = () => { + const doImport = async () => { setState('importing'); + // for (const file of event.target.files) { + // const fileReader = new FileReader(); + // fileReader.readAsText(file); + + // fileReader.addEventListener( + // 'load', + // async () => { + // // this will then display a text file + // console.log({ + // caller: 'GpxImport / XML', + // file, + // result: fileReader.result, + // }); + // const gpx = GPX.parse(fileReader.result); + // console.log({ caller: 'GpxImport / JSON', file, gpx }); + // if (gpx) { + // const startTime = new Date(findStartTime(gpx)!); + await dispatch({ + action: 'pruneAndSaveImportedGpx', + params: { + id: gpxId(), + gpx: statsAndGpx()?.gpx, + tech: { + lastModified: new Date(gpxFile.lastModified).toISOString(), + importDate: new Date().toISOString(), + name: gpxFile.name, + size: gpxFile.size, + type: gpxFile.type, + }, + }, + }); + console.log({ + caller: 'GpxImport / JSON / done', + gpxFile, + gpx: statsAndGpx()?.gpx, + }); + setState('done'); + + // } else { + // console.error({ + // message: "can't parse GPX file", + // file, + // xml: fileReader.result, + // }); + // } + // // TODO: error handling + // }, + // false + // ); + // } }; const [selectedTrkTransform, setSelectedTrkTransform] = createSignal( @@ -139,7 +190,11 @@ const GpxImportSingleFile: Component = ({ gpxFile }) => { - +