GpxDialog (wip)

This commit is contained in:
Eric van der Vlist 2022-12-12 15:37:12 +01:00
parent 2f57bff6ed
commit 7df0b41260
3 changed files with 45 additions and 13 deletions

View File

@ -1,14 +1,11 @@
import { useI18n } from '@solid-primitives/i18n'; import { useI18n } from '@solid-primitives/i18n';
import { OpenInBrowserTwoTone } from '@suid/icons-material';
import { import {
Box, Box,
FormControl, FormControl,
IconButton, IconButton,
InputLabel, InputLabel,
MenuItem,
NativeSelect, NativeSelect,
SvgIcon, SvgIcon,
TextField,
} from '@suid/material'; } from '@suid/material';
import { Component, createSignal, For } from 'solid-js'; import { Component, createSignal, For } from 'solid-js';
import dispatch from '../../workers/dispatcher-main'; 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 GpxesIcon from '../../icons/adventure-journey-location-svgrepo-com.svg';
import style from './GpxDialog.module.css'; import style from './GpxDialog.module.css';
const GpxChooser: Component<{}> = (props) => { export const [currentGpxId, setCurrentGpxId] = createSignal<string>('');
const GpxDialog: Component<{}> = (props) => {
const [t] = useI18n(); const [t] = useI18n();
const [open, setOpen] = createSignal(false); const [open, setOpen] = createSignal(false);
const [allGpxes, setAllGpxes] = createSignal<any[]>([]); const [allGpxes, setAllGpxes] = createSignal<any[]>([]);
const [selectedGpxId, setSelectedGpxId] = createSignal<string>('');
const [gpx, setGpx] = createSignal<Gpx>();
console.log({ caller: 'GpxDialog', currentGpx: currentGpxId() });
const handleClickOpen = async () => { const handleClickOpen = async () => {
setOpen(true); setOpen(true);
const newAllGpxes: any[] = await dispatch({ const newAllGpxes = await dispatch({
action: 'getAllGpxesWithSummary', 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 = () => { const handleClose = () => {
setOpen(false); 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 ( return (
<> <>
@ -75,17 +107,18 @@ const GpxChooser: Component<{}> = (props) => {
{t('gpxChooser')} {t('gpxChooser')}
</InputLabel> </InputLabel>
<NativeSelect <NativeSelect
defaultValue={30}
inputProps={{ inputProps={{
name: 'gpx-chooser', name: 'gpx-chooser',
id: 'gpx-chooser', id: 'gpx-chooser',
}} }}
onChange={gpxChangeHandler}
> >
<For each={allGpxes()}> <For each={allGpxes()}>
{(gpx) => ( {(gpx) => (
<option value={gpx.id}>{`${gpx.name || ''} (${ <option
gpx.creator value={gpx.id}
})`}</option> selected={gpx.id === selectedGpxId()}
>{`${gpx.name || gpx.id} (${gpx.creator})`}</option>
)} )}
</For> </For>
</NativeSelect> </NativeSelect>
@ -96,4 +129,4 @@ const GpxChooser: Component<{}> = (props) => {
); );
}; };
export default GpxChooser; export default GpxDialog;

View File

@ -1 +1 @@
export { default } from './GpxDialog'; export { default, currentGpxId, setCurrentGpxId } from './GpxDialog';

View File

@ -1,5 +1,4 @@
import { Component, createEffect, createSignal, onMount } from 'solid-js'; import { Component, createEffect, createSignal, onMount } from 'solid-js';
import { createStore } from 'solid-js/store';
import { useParams, useNavigate } from '@solidjs/router'; import { useParams, useNavigate } from '@solidjs/router';
import OlMap from 'ol/Map'; import OlMap from 'ol/Map';
import View from 'ol/View'; import View from 'ol/View';