diff --git a/src/components/import/ImportSingleFile.tsx b/src/components/import/ImportSingleFile.tsx index 3595c11..6459b84 100644 --- a/src/components/import/ImportSingleFile.tsx +++ b/src/components/import/ImportSingleFile.tsx @@ -150,7 +150,7 @@ const ImportSingleFile: Component = ({ file: file }) => { ); } } - const doImport = async () => { + const doImport = async (forceImportAsRoutes: boolean = false) => { setState('importing'); // console.log({ caller: 'GpxImport / JSON', file, gpx }); // if (gpx) { @@ -159,6 +159,7 @@ const ImportSingleFile: Component = ({ file: file }) => { action: 'pruneAndSaveImportedGpx', params: { id: gpxId(), + forceImportAsRoutes, gpx: statsAndGpx()?.gpx, tech: typeof file === 'string' @@ -244,10 +245,17 @@ const ImportSingleFile: Component = ({ file: file }) => { + diff --git a/src/db/gpx.ts b/src/db/gpx.ts index c5276f6..82bbca1 100644 --- a/src/db/gpx.ts +++ b/src/db/gpx.ts @@ -150,13 +150,13 @@ const hasMissingTimestamps = (trk: Trk) => { return false; }; -const convertTrkToRteWhenNeeded = (gpx: Gpx) => { +const convertTrkToRteWhenNeeded = (gpx: Gpx, forceImportAsRoutes: boolean) => { if (gpx.trk === undefined) { return; } const newTrks: Trk[] = []; for (const trk of gpx.trk) { - if (hasMissingTimestamps(trk)) { + if (forceImportAsRoutes || hasMissingTimestamps(trk)) { const rte = { ...trk, trkseg: undefined, rtept: [] }; for (const trkseg of trk.trkseg!) { rte.rtept = rte.rtept.concat(trkseg.trkpt); @@ -174,7 +174,7 @@ const convertTrkToRteWhenNeeded = (gpx: Gpx) => { export const pruneAndSaveImportedGpx = async (params: any) => { console.log({ caller: 'pruneAndSaveImportedGpx', params }); - const { id, gpx, tech } = params; + const { id, gpx, tech, forceImportAsRoutes } = params; let gpxId: IdGpx; let docs: any[] = []; const extensions = { @@ -186,7 +186,7 @@ export const pruneAndSaveImportedGpx = async (params: any) => { extensions: gpx.extensions, }, }; - convertTrkToRteWhenNeeded(gpx); + convertTrkToRteWhenNeeded(gpx, forceImportAsRoutes); let previousGpx: Gpx | null = null; let to: string[]; if (id === 'new') {