forked from microbit-foundation/cctd-ml-machine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redirect potentially non Next Gen users to prototype version (#247)
- Shown to users before browser compatibility warning dialog - Shown only if they are detected to be in the UK (GB), Isle of Man (IM), Jersey (JE), or Guernsey (GG) - Should only be shown once to the user - API proxy for calling browser info endpoint for local dev via .env
- Loading branch information
1 parent
fce8fda
commit a4c70eb
Showing
6 changed files
with
163 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<!-- | ||
(c) 2023, Center for Computational Thinking and Design at Aarhus University and contributors | ||
SPDX-License-Identifier: MIT | ||
--> | ||
|
||
<script lang="ts"> | ||
import { t } from '../i18n'; | ||
import { hasSeenAppVersionRedirectDialog } from '../script/stores/uiStore'; | ||
import StandardDialog from './dialogs/StandardDialog.svelte'; | ||
import StandardButton from './StandardButton.svelte'; | ||
let isOpen = true; | ||
const appVersionRedirect = () => { | ||
hasSeenAppVersionRedirectDialog.set(true); | ||
window.location.href = 'https://ml.microbit.org/v/prototype'; | ||
}; | ||
const onClose = () => { | ||
hasSeenAppVersionRedirectDialog.set(true); | ||
isOpen = false; | ||
}; | ||
</script> | ||
|
||
<StandardDialog | ||
{isOpen} | ||
hasCloseButton={false} | ||
closeOnOutsideClick={false} | ||
closeOnEscape={false} | ||
class="w-110 space-y-5" | ||
{onClose}> | ||
<svelte:fragment slot="heading"> | ||
{$t('popup.appVersionRedirect.header')} | ||
</svelte:fragment> | ||
<svelte:fragment slot="body"> | ||
<div class="space-y-8"> | ||
<p>{$t('popup.appVersionRedirect.explain')}</p> | ||
<div class="flex flex-col justify-end space-y-3"> | ||
<StandardButton | ||
type="primary" | ||
size="normal" | ||
class="w-sm" | ||
onClick={appVersionRedirect} | ||
>{$t('popup.appVersionRedirect.button.redirect')}</StandardButton> | ||
<StandardButton onClick={onClose} type="secondary" size="normal" class="w-sm" | ||
>{$t('popup.appVersionRedirect.button.stay')}</StandardButton> | ||
</div> | ||
<p class="text-sm">{$t('popup.appVersionRedirect.uk')}</p> | ||
</div> | ||
</svelte:fragment> | ||
</StandardDialog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { logError } from './logging'; | ||
|
||
/** | ||
* (c) 2023, Center for Computational Thinking and Design at Aarhus University and contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
interface BrowserInfo { | ||
country?: string; | ||
region?: string; | ||
} | ||
|
||
const isBrowserInfo = (v: unknown): v is BrowserInfo => { | ||
return typeof v === 'object' && v !== null; | ||
}; | ||
|
||
/** | ||
* Best effort attempt to fetch browser info. | ||
* On error it returns empty browser info. | ||
*/ | ||
export const fetchBrowserInfo = async (): Promise<BrowserInfo> => { | ||
try { | ||
// Note this API is not available if you're running locally without configuring API_PROXY in .env | ||
const response = await fetch('/api/v1/browser/info'); | ||
if (!response.ok) { | ||
return {}; | ||
} | ||
const json = await response.json(); | ||
if (isBrowserInfo(json)) { | ||
return json; | ||
} | ||
} catch (e) { | ||
logError('Failed to fetch browser info', e); | ||
} | ||
return {}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters