From 7df0b41260e3b8228d90764dcfffe23927a58894 Mon Sep 17 00:00:00 2001 From: evlist Date: Mon, 12 Dec 2022 15:37:12 +0100 Subject: [PATCH] GpxDialog (wip) --- src/components/gpx-dialog/GpxDialog.tsx | 55 ++++++++++++++++++++----- src/components/gpx-dialog/index.ts | 2 +- src/components/map/Map.tsx | 1 - 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/components/gpx-dialog/GpxDialog.tsx b/src/components/gpx-dialog/GpxDialog.tsx index fa714e1..c245b99 100644 --- a/src/components/gpx-dialog/GpxDialog.tsx +++ b/src/components/gpx-dialog/GpxDialog.tsx @@ -1,14 +1,11 @@ import { useI18n } from '@solid-primitives/i18n'; -import { OpenInBrowserTwoTone } from '@suid/icons-material'; import { Box, FormControl, IconButton, InputLabel, - MenuItem, NativeSelect, SvgIcon, - TextField, } from '@suid/material'; import { Component, createSignal, For } from 'solid-js'; import dispatch from '../../workers/dispatcher-main'; @@ -16,21 +13,56 @@ import Dialog from '../dialog'; //import GpxesIcon from '../../icons/adventure-journey-location-svgrepo-com.svg'; import style from './GpxDialog.module.css'; -const GpxChooser: Component<{}> = (props) => { +export const [currentGpxId, setCurrentGpxId] = createSignal(''); + +const GpxDialog: Component<{}> = (props) => { const [t] = useI18n(); const [open, setOpen] = createSignal(false); const [allGpxes, setAllGpxes] = createSignal([]); + const [selectedGpxId, setSelectedGpxId] = createSignal(''); + const [gpx, setGpx] = createSignal(); + + console.log({ caller: 'GpxDialog', currentGpx: currentGpxId() }); const handleClickOpen = async () => { setOpen(true); - const newAllGpxes: any[] = await dispatch({ + const newAllGpxes = await dispatch({ action: 'getAllGpxesWithSummary', }); - setAllGpxes(newAllGpxes); + setAllGpxes(newAllGpxes as any[]); + setSelectedGpxId(currentGpxId()); + if (currentGpxId() !== '') { + const newGpx = await dispatch({ + action: 'getGpx', + params: { + id: currentGpxId(), + }, + }); + setGpx(newGpx as Gpx); + } + console.log({ + caller: 'GpxDialog / handleClickOpen', + currentGpxId: currentGpxId(), + gpx: gpx(), + }); }; const handleClose = () => { setOpen(false); }; + const gpxChangeHandler = async (event: any) => { + console.log({ + caller: 'GpxDialog / gpxChangeHandler', + value: event.target.value, + }); + setSelectedGpxId(event.target.value); + const newGpx = await dispatch({ + action: 'getGpx', + params: { + id: event.target.value, + }, + }); + setGpx(newGpx as Gpx); + }; return ( <> @@ -75,17 +107,18 @@ const GpxChooser: Component<{}> = (props) => { {t('gpxChooser')} {(gpx) => ( - + )} @@ -96,4 +129,4 @@ const GpxChooser: Component<{}> = (props) => { ); }; -export default GpxChooser; +export default GpxDialog; diff --git a/src/components/gpx-dialog/index.ts b/src/components/gpx-dialog/index.ts index eda6f59..702e636 100644 --- a/src/components/gpx-dialog/index.ts +++ b/src/components/gpx-dialog/index.ts @@ -1 +1 @@ -export { default } from './GpxDialog'; +export { default, currentGpxId, setCurrentGpxId } from './GpxDialog'; diff --git a/src/components/map/Map.tsx b/src/components/map/Map.tsx index 688e8f7..963e45e 100644 --- a/src/components/map/Map.tsx +++ b/src/components/map/Map.tsx @@ -1,5 +1,4 @@ import { Component, createEffect, createSignal, onMount } from 'solid-js'; -import { createStore } from 'solid-js/store'; import { useParams, useNavigate } from '@solidjs/router'; import OlMap from 'ol/Map'; import View from 'ol/View';