Refactoring

This commit is contained in:
vdv committed 2023-01-07 18:00:35 +01:00
1 parent b23e44b576
commit 7483d9f904
4 files changed
+86 -74

No files matched your search

@@ -0,0 +1,52 @@
import { IconButton } from '@suid/material';
import SearchIcon from '@suid/icons-material/Search';
import { Component, Show } from 'solid-js';
import { findAddress, getVillageOrTown } from '../../lib/osm';
import { cloneDeep } from 'lodash';
import { useI18n } from '@solid-primitives/i18n';
import dispatch from '../../workers/dispatcher-main';
interface Props {
target: any;
putAction: string;
putParamName: string;
}
const DisplayOrGetAddress: Component<Props> = ({
target,
putAction,
putParamName,
}) => {
const [t, { add, locale, dict }] = useI18n();
const findClickHandlerFactory = (target: any) => async () => {
const address = await findAddress(target.$.lon, target.$.lat, locale);
const updatedTarget = cloneDeep(target);
if (updatedTarget.extensions === undefined) {
updatedTarget.extensions = {};
}
updatedTarget.extensions.address = address;
const params: any = { id: target.id };
params[putParamName] = updatedTarget;
dispatch({
action: putAction,
params,
});
};
return (
<Show
when={target.extensions?.address}
fallback={
<IconButton color='primary' onClick={findClickHandlerFactory(target)}>
<SearchIcon />
</IconButton>
}
>
<>{getVillageOrTown(target.extensions?.address)}</>
</Show>
);
};
export default DisplayOrGetAddress;
@@ -0,0 +1 @@
export { default } from './DisplayOrGetAddress';