import { useI18n } from '@solid-primitives/i18n'; import { Box, Button, IconButton, SvgIcon, TextField } from '@suid/material'; import { cloneDeep } from 'lodash'; import { Component, createSignal, Show } from 'solid-js'; import { newEmptyGpx } from '../../db/gpx'; import { peekCachedSignal } from '../../workers/cached-signals'; import dispatch from '../../workers/dispatcher-main'; import Dialog from '../dialog'; import GpxChooser from '../gpx-chooser'; import GpxIcon from '../gpx/GpxIcon'; //import GpxesIcon from '../../icons/adventure-journey-location-svgrepo-com.svg'; import style from './GpxDialog.module.css'; export const [currentGpxId, setCurrentGpxId] = createSignal('new'); const GpxDialog: Component<{}> = (props) => { const [t] = useI18n(); const [open, setOpen] = createSignal(false); const [selectedGpxId, setSelectedGpxId] = createSignal(''); const [gpx, setGpx] = createSignal(); console.log({ caller: 'GpxDialog', currentGpxId: currentGpxId() }); const fetchGpx = (gpxId: string) => { if (gpxId === 'new') { return newEmptyGpx(); } const newGpx = peekCachedSignal({ id: gpxId, action: 'getGpx', }); return newGpx(); }; const handleClickOpen = async () => { setOpen(true); setSelectedGpxId(currentGpxId()); if (currentGpxId() !== '') { setGpx(fetchGpx(currentGpxId()) as Gpx); } console.log({ caller: 'GpxDialog / handleClickOpen', currentGpxId: currentGpxId(), gpx: gpx(), }); }; const handleClose = (event: any, reason?: string) => { console.log({ caller: 'GpxDialog / handleClose', event, reason, }); if (reason === undefined) { setOpen(false); } }; const gpxChangeHandler = async (gpxId: string) => { setSelectedGpxId(gpxId); setGpx(fetchGpx(gpxId) as Gpx); console.log({ caller: 'GpxDialog / gpxChangeHandler', gpxId, gpx: gpx(), }); }; const gpxNameChangeHandler = (event: any) => { const newGpx: Gpx = cloneDeep(gpx()) as Gpx; if (newGpx.metadata === undefined) { newGpx.metadata = {}; } newGpx.metadata.name = event.target.value; setGpx(newGpx); console.log({ caller: 'GpxDialog / gpxNameChangeHandler', value: event.target.value, gpx: gpx(), }); }; const gpxDescChangeHandler = (event: any) => { const newGpx: Gpx = cloneDeep(gpx()) as Gpx; if (newGpx.metadata === undefined) { newGpx.metadata = {}; } newGpx.metadata.desc = event.target.value; setGpx(newGpx); console.log({ caller: 'GpxDialog / gpxDescChangeHandler', value: event.target.value, gpx: gpx(), }); }; const gpxTimeChangeHandler = (event: any) => { const newGpx: Gpx = cloneDeep(gpx()) as Gpx; if (newGpx.metadata === undefined) { newGpx.metadata = {}; } newGpx.metadata.time = new Date(event.target.value).toISOString(); setGpx(newGpx); console.log({ caller: 'GpxDialog / gpxTimeChangeHandler', value: event.target.value, gpx: gpx(), }); }; const saveHandler = async (event: any) => { const id = (await dispatch({ action: 'putGpx', params: { id: selectedGpxId(), gpx: gpx(), }, })) as string; setCurrentGpxId(id); setOpen(false); }; return ( <>
); }; export default GpxDialog;