From 5ad98a860e7b63bcb323973165d1b7791820f70b Mon Sep 17 00:00:00 2001 From: Eric van der Vlist Date: Sat, 4 Mar 2023 09:23:28 +0100 Subject: [PATCH] Moving invitation check in its own module --- src/components/invitation/Invitation.tsx | 36 ++++++++++++++++++++++++ src/components/invitation/index.ts | 1 + src/components/map/Map.tsx | 26 ++--------------- 3 files changed, 39 insertions(+), 24 deletions(-) create mode 100644 src/components/invitation/Invitation.tsx create mode 100644 src/components/invitation/index.ts diff --git a/src/components/invitation/Invitation.tsx b/src/components/invitation/Invitation.tsx new file mode 100644 index 0000000..bddacf6 --- /dev/null +++ b/src/components/invitation/Invitation.tsx @@ -0,0 +1,36 @@ +import { Component, createSignal } from 'solid-js'; + +interface props {} + +const [invitation, setInvitation] = createSignal(false); + +export const searchInvitation = () => { + const hash = location.hash; + console.log({ caller: 'Invitation / searchInvitation', hash }); + + if (hash.length > 1) { + try { + const payload = hash.slice(1); + const decoded = atob(payload); + const url = new URL(decoded); + setInvitation(url); + console.log({ + caller: 'Invitation / searchInvitation', + hash, + invitation: decoded, + }); + } catch { + console.warn({ + caller: 'Invitation / searchInvitation', + hash, + message: 'Hash is not a base64 encoded URL', + }); + } + } +}; + +const Invitation: Component = (props) => { + return <>; +}; + +export default Invitation; diff --git a/src/components/invitation/index.ts b/src/components/invitation/index.ts new file mode 100644 index 0000000..b7dbbb2 --- /dev/null +++ b/src/components/invitation/index.ts @@ -0,0 +1 @@ +export { default, searchInvitation } from './Invitation'; diff --git a/src/components/map/Map.tsx b/src/components/map/Map.tsx index 9d4310f..e09f053 100644 --- a/src/components/map/Map.tsx +++ b/src/components/map/Map.tsx @@ -46,6 +46,7 @@ import { Overlays } from '../overlays/Overlays'; import Finder, { findLocation } from '../finder'; import { ZoomIn } from '@suid/icons-material'; import Note from '../note'; +import { searchInvitation } from '../invitation'; const [getState, setState] = createSignal({ lon: 0, @@ -67,30 +68,7 @@ const Map: Component = () => { const navigate = useNavigate(); const params = useParams(); - const hash = location.hash; - console.log({ caller: 'Map / hash', hash }); - - const [invitation, setInvitation] = createSignal(false); - - if (hash.length > 1) { - try { - const payload = hash.slice(1); - const decoded = atob(payload); - const url = new URL(decoded); - setInvitation(url); - console.log({ - caller: 'Map', - hash, - invitation: decoded, - }); - } catch { - console.warn({ - caller: 'Map', - hash, - message: 'Hash is not a base64 encoded URL', - }); - } - } + searchInvitation(); // See https://stackoverflow.com/questions/71288670/how-to-make-fullscreen-ionic-capacitor-app AndroidFullScreen.isImmersiveModeSupported()