import { useI18n } from '@solid-primitives/i18n'; import { Box, Button, IconButton, SvgIcon, TextField } from '@suid/material'; import { cloneDeep, isPlainObject } 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(); const [currentAccount, setCurrentAccount] = createSignal(); console.log({ caller: 'GpxDialog', currentGpxId: currentGpxId() }); const fetchGpx = (gpxId: string) => { if (gpxId === 'new' || !gpxId) { return newEmptyGpx(); } const newGpx = peekCachedSignal({ id: gpxId, action: 'getGpx', }); return newGpx(); }; dispatch({ action: 'getCurrentAccount' }).then((currentAccount: any) => { console.log({ caller: 'GpxDialog / currentAccount', currentAccount }); setCurrentAccount(currentAccount); setCurrentGpxId(currentAccount.currentGpxId || 'new'); setSelectedGpxId(currentAccount.currentGpxId || 'new'); }); const handleClickOpen = async () => { setOpen(true); 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 gpxToChangeHandler = (event: any) => { const newGpx: Gpx = cloneDeep(gpx()) as Gpx; if (!isPlainObject(newGpx.extensions)) { newGpx.extensions = {}; } newGpx.extensions.to = event.target.value; setGpx(newGpx); console.log({ caller: 'GpxDialog / gpxToChangeHandler', value: event.target.value, gpx: gpx(), newGpx, }); }; 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); await dispatch({ action: 'putCurrentAccount', params: { account: { ...currentAccount(), currentGpxId: currentGpxId() }, }, }); }; return ( <>
); }; export default GpxDialog;