Improving the tile server chooser (#7)

This commit is contained in:
vdv committed 2022-09-27 17:34:17 +02:00
1 parent f5ce103cb3
commit 59fbe4aa3f
2 files changed
+71 -6

No files matched your search

+49 -6
View File
@@ -1,4 +1,7 @@
import {
createAnimation,
IonButton,
IonButtons,
IonContent,
IonHeader,
IonItem,
@@ -8,29 +11,69 @@ import {
IonRadio,
IonRadioGroup,
IonTitle,
IonToolbar,
} from '@ionic/react';
import React from 'react';
import React, { useRef } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { mapActions, MapState } from '../../store/map';
import { tileProviders } from './tile';
const TileServerChooserDialog: React.FC<{}> = () => {
const tileProvider = useSelector(
(state: { map: MapState }) => state.map.scope.tileProvider
) as keyof typeof tileProviders;
const dispatch = useDispatch();
const modal = useRef<HTMLIonModalElement>(null);
const dismiss = () => {
modal.current?.dismiss();
};
const changeHandler = (event: any) => {
dispatch(mapActions.setTileProvider(event.detail.value));
dismiss();
};
const enterAnimation = (baseEl: HTMLElement) => {
const root = baseEl.shadowRoot;
const backdropAnimation = createAnimation()
.addElement(root?.querySelector('ion-backdrop')!)
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');
const wrapperAnimation = createAnimation()
.addElement(root?.querySelector('.modal-wrapper')!)
.keyframes([
{ offset: 0, opacity: '0', transform: 'scale(0)' },
{ offset: 1, opacity: '0.99', transform: 'scale(1)' },
]);
return createAnimation()
.addElement(baseEl)
.easing('ease-out')
.duration(500)
.addAnimation([backdropAnimation, wrapperAnimation]);
};
const leaveAnimation = (baseEl: HTMLElement) => {
return enterAnimation(baseEl).direction('reverse');
};
return (
<IonModal trigger='open-TileServerChooser'>
<IonHeader>
<IonTitle>Select your map</IonTitle>
</IonHeader>
<IonModal
ref={modal}
trigger='open-TileServerChooser'
enterAnimation={enterAnimation}
leaveAnimation={leaveAnimation}
>
<IonToolbar>
<IonTitle>Choose your map</IonTitle>
<IonButtons slot='end'>
<IonButton onClick={() => dismiss()}>Close</IonButton>
</IonButtons>
</IonToolbar>
<IonContent>
<IonList>
<IonRadioGroup value={tileProvider} onIonChange={changeHandler}>