2022-11-01 20:27:36 +00:00
|
|
|
import {
|
|
|
|
IonApp,
|
|
|
|
IonButtons,
|
|
|
|
IonContent,
|
|
|
|
IonFooter,
|
|
|
|
IonHeader,
|
|
|
|
IonToolbar,
|
|
|
|
setupIonicReact,
|
|
|
|
} from '@ionic/react';
|
2022-08-31 12:35:20 +00:00
|
|
|
|
|
|
|
/* Core CSS required for Ionic components to work properly */
|
|
|
|
import '@ionic/react/css/core.css';
|
|
|
|
|
|
|
|
/* Basic CSS for apps built with Ionic */
|
|
|
|
import '@ionic/react/css/normalize.css';
|
|
|
|
import '@ionic/react/css/structure.css';
|
|
|
|
import '@ionic/react/css/typography.css';
|
|
|
|
|
|
|
|
/* Optional CSS utils that can be commented out */
|
|
|
|
import '@ionic/react/css/padding.css';
|
|
|
|
import '@ionic/react/css/float-elements.css';
|
|
|
|
import '@ionic/react/css/text-alignment.css';
|
|
|
|
import '@ionic/react/css/text-transformation.css';
|
|
|
|
import '@ionic/react/css/flex-utils.css';
|
|
|
|
import '@ionic/react/css/display.css';
|
|
|
|
|
|
|
|
/* Theme variables */
|
|
|
|
import './theme/variables.css';
|
2022-11-06 21:29:33 +00:00
|
|
|
|
|
|
|
import dispatch from './workers/dispatcher-main';
|
|
|
|
|
2022-10-31 17:05:58 +00:00
|
|
|
import LiveMap from './components/map/LiveMap';
|
2022-08-31 12:35:20 +00:00
|
|
|
|
2022-11-01 20:27:36 +00:00
|
|
|
import { atom, useAtom } from 'jotai';
|
2022-11-01 16:58:57 +00:00
|
|
|
import { atomWithHash } from 'jotai/utils';
|
|
|
|
import { MapScope } from './components/map/types';
|
|
|
|
import { debounce } from 'lodash';
|
2022-11-02 14:29:13 +00:00
|
|
|
import GetLocation from './components/buttons/GetLocation';
|
2022-11-01 20:27:36 +00:00
|
|
|
import { geoPoint } from './components/map/types';
|
2022-11-02 15:04:18 +00:00
|
|
|
import Back from './components/buttons/Back';
|
|
|
|
import Forward from './components/buttons/Forward';
|
2022-11-02 21:28:08 +00:00
|
|
|
import CurrentLocation from './components/map/CurrentLocation';
|
2022-11-14 13:13:12 +00:00
|
|
|
import GpxImport from './components/dialogs/GpxImport';
|
2022-11-15 19:19:14 +00:00
|
|
|
import Gpxes from './components/map/Gpxes';
|
2022-11-06 21:29:33 +00:00
|
|
|
// import { initDb } from './db';
|
|
|
|
// import PouchDB from 'pouchdb';
|
|
|
|
// import PouchDBFind from 'pouchdb-find';
|
|
|
|
// PouchDB.plugin(PouchDBFind);
|
2022-11-01 16:58:57 +00:00
|
|
|
|
2022-08-31 12:35:20 +00:00
|
|
|
setupIonicReact();
|
|
|
|
|
2022-11-02 21:33:03 +00:00
|
|
|
// See https://stackoverflow.com/questions/71538643/property-wakelock-does-not-exist-on-type-navigator
|
|
|
|
const requestWakeLock = async () => {
|
|
|
|
const anyNav: any = navigator;
|
|
|
|
if ('wakeLock' in navigator) {
|
|
|
|
try {
|
|
|
|
const wakeLock = await anyNav['wakeLock'].request('screen');
|
|
|
|
} catch (err: any) {
|
|
|
|
// The wake lock request fails - usually system-related, such as low battery.
|
|
|
|
console.log(`Wake lock request failed: ${err.name}, ${err.message}`);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.log('No wake lock support here...');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleVisibilityChange = () => {
|
|
|
|
if (document.hidden) {
|
|
|
|
console.log('Application hidden');
|
|
|
|
} else {
|
|
|
|
console.log('Application visible');
|
|
|
|
requestWakeLock();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// See https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API
|
|
|
|
document.addEventListener('visibilitychange', handleVisibilityChange, false);
|
|
|
|
requestWakeLock();
|
|
|
|
|
2022-11-01 16:58:57 +00:00
|
|
|
const initialScope: MapScope = {
|
|
|
|
center: { lat: -37.8403508, lon: 77.5539501 },
|
|
|
|
zoom: 13,
|
|
|
|
tileProvider: 'osm',
|
|
|
|
};
|
|
|
|
const scopeAtom = atomWithHash('scope', initialScope);
|
|
|
|
|
2022-11-01 20:27:36 +00:00
|
|
|
export const setCenterAtom = atom(null, (get, set, center: geoPoint) => {
|
|
|
|
const previousScope = get(scopeAtom);
|
|
|
|
const newScope: MapScope = {
|
|
|
|
...previousScope,
|
|
|
|
center: center,
|
|
|
|
};
|
|
|
|
set(scopeAtom, newScope);
|
|
|
|
});
|
2022-11-03 16:27:02 +00:00
|
|
|
|
2022-11-06 21:29:33 +00:00
|
|
|
// const db = new PouchDB('dyomedea', { auto_compaction: true, revs_limit: 10 });
|
|
|
|
// initDb(db);
|
|
|
|
|
|
|
|
dispatch({ action: 'initDb' });
|
2022-11-15 19:19:14 +00:00
|
|
|
//dispatch({ action: 'getGpxesForViewport', params: { type: 'tech' } });
|
2022-10-17 10:04:25 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @returns The root app component
|
|
|
|
*/
|
2022-11-01 16:58:57 +00:00
|
|
|
const App: React.FC = () => {
|
|
|
|
const [scope, setScope] = useAtom(scopeAtom);
|
|
|
|
|
|
|
|
console.log(`App, scope: ${JSON.stringify(scope)}`);
|
|
|
|
return (
|
|
|
|
<IonApp>
|
2022-11-01 20:27:36 +00:00
|
|
|
<IonContent fullscreen={true}>
|
|
|
|
<IonApp>
|
|
|
|
<LiveMap
|
|
|
|
scope={scope}
|
|
|
|
setScope={debounce(setScope, 1000)}
|
|
|
|
numberOfTiledLayers={5}
|
2022-11-15 19:19:14 +00:00
|
|
|
slippyGraphics={[
|
|
|
|
<CurrentLocation key='currentLocation' />,
|
|
|
|
<Gpxes key='gpxes' />,
|
|
|
|
]}
|
2022-11-01 20:27:36 +00:00
|
|
|
/>
|
|
|
|
</IonApp>
|
|
|
|
</IonContent>
|
|
|
|
<IonHeader className='ion-no-border' translucent={true}>
|
|
|
|
<IonToolbar>
|
2022-11-02 15:04:18 +00:00
|
|
|
<IonButtons slot='start'>
|
|
|
|
<Back />
|
|
|
|
<Forward />
|
|
|
|
</IonButtons>
|
2022-11-14 13:13:12 +00:00
|
|
|
<IonButtons slot='end'>
|
|
|
|
<GpxImport />
|
|
|
|
</IonButtons>
|
2022-11-01 20:27:36 +00:00
|
|
|
</IonToolbar>
|
|
|
|
</IonHeader>
|
|
|
|
<IonFooter className='ion-no-border'>
|
|
|
|
<IonToolbar>
|
|
|
|
<IonButtons>
|
|
|
|
<GetLocation />
|
|
|
|
</IonButtons>
|
|
|
|
</IonToolbar>
|
|
|
|
</IonFooter>
|
2022-11-01 16:58:57 +00:00
|
|
|
</IonApp>
|
|
|
|
);
|
|
|
|
};
|
2022-08-31 12:35:20 +00:00
|
|
|
|
|
|
|
export default App;
|