Skip to content

Commit ecdfb2b

Browse files
Pop up unsupported dialog when Bluetooth and WebUSB are unsupported (#185)
1 parent 0b64267 commit ecdfb2b

File tree

2 files changed

+58
-22
lines changed

2 files changed

+58
-22
lines changed

src/components/LinkOverlay.svelte

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,33 @@
2222
</style>
2323

2424
<script lang="ts">
25-
import { PathType, navigate } from '../router/paths';
25+
import { PathType, Paths, navigate } from '../router/paths';
26+
export let onClickOrHrefOrPath: string | PathType | (() => void);
2627
27-
export let href: string | undefined = undefined;
28-
export let path: PathType | undefined = undefined;
28+
const sharedClass = `overlay outline-none focus-visible:ring-4 focus-visible:ring-offset-1 focus-visible:ring-ring cursor-pointer ${
29+
$$restProps.class || ''
30+
}`;
2931
30-
function handleClick(e: Event) {
31-
if (path) {
32-
e.preventDefault();
33-
navigate(path);
34-
}
32+
function isPathType(x: string | PathType | (() => void)): x is PathType {
33+
return Object.values(Paths).includes(x as PathType);
34+
}
35+
36+
function handleClickPath(e: Event) {
37+
e.preventDefault();
38+
navigate(onClickOrHrefOrPath as PathType);
3539
}
3640
</script>
3741

38-
<a
39-
href={href ?? path}
40-
on:click={handleClick}
41-
class="overlay outline-none focus-visible:ring-4 focus-visible:ring-offset-1
42-
focus-visible:ring-ring {$$restProps.class || ''}">
43-
<slot />
44-
</a>
42+
{#if isPathType(onClickOrHrefOrPath)}
43+
<a href={onClickOrHrefOrPath} on:click={handleClickPath} class={sharedClass}>
44+
<slot />
45+
</a>
46+
{:else if typeof onClickOrHrefOrPath === 'string'}
47+
<a href={onClickOrHrefOrPath} class={sharedClass}>
48+
<slot />
49+
</a>
50+
{:else}
51+
<button on:click={onClickOrHrefOrPath} class={sharedClass}>
52+
<slot />
53+
</button>
54+
{/if}

src/pages/Homepage.svelte

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
</style>
1313

1414
<script lang="ts">
15-
import { state } from '../script/stores/uiStore';
15+
import {
16+
compatibility,
17+
isCompatibilityWarningDialogOpen,
18+
state,
19+
} from '../script/stores/uiStore';
1620
import trainModelImage from '../imgs/TrainModel.svg';
1721
import inputDataImage from '../imgs/InputData.svg';
1822
import testModelImage from '../imgs/TestModel.svg';
@@ -25,8 +29,9 @@
2529
} from '../components/HtmlFormattedMessage.svelte';
2630
import LinkOverlayContainer from '../components/LinkOverlayContainer.svelte';
2731
import LinkOverlay from '../components/LinkOverlay.svelte';
28-
import { Paths, currentPath, getTitle, navigate } from '../router/paths';
32+
import { Paths, getTitle, navigate } from '../router/paths';
2933
import { gestures } from '../script/stores/Stores';
34+
import CompatibilityWarningDialog from '../components/CompatibilityWarningDialog.svelte';
3035
import StandardDialog from '../components/dialogs/StandardDialog.svelte';
3136
import { clearGestures } from '../script/stores/mlStore';
3237
import { get } from 'svelte/store';
@@ -44,7 +49,16 @@
4449
$: hasExistingSession = $gestures.some(g => g.name || g.recordings.length);
4550
let showDataLossWarning = false;
4651
47-
const checkForExistingSession = () => {
52+
const { bluetooth, usb } = get(compatibility);
53+
const isIncompatible = !bluetooth && !usb;
54+
55+
const openCompatibityWarningDialog = () => isCompatibilityWarningDialogOpen.set(true);
56+
57+
const onClickStartNewSession = () => {
58+
if (isIncompatible) {
59+
openCompatibityWarningDialog();
60+
return;
61+
}
4862
if (hasExistingSession) {
4963
showDataLossWarning = true;
5064
} else {
@@ -103,7 +117,11 @@
103117
<div class="grid grid-cols-1 lg:grid-cols-3 p-10 gap-5">
104118
<LinkOverlayContainer>
105119
<FrontPageContentTile>
106-
<LinkOverlay path={Paths.DATA} class="mb-5">
120+
<LinkOverlay
121+
onClickOrHrefOrPath={isIncompatible
122+
? openCompatibityWarningDialog
123+
: Paths.DATA}
124+
class="mb-5">
107125
<h3 class="text-center text-2xl font-bold">
108126
{$t('content.index.toolProcessCards.data.title')}
109127
</h3>
@@ -117,7 +135,11 @@
117135

118136
<LinkOverlayContainer>
119137
<FrontPageContentTile>
120-
<LinkOverlay path={Paths.TRAINING} class="mb-5">
138+
<LinkOverlay
139+
onClickOrHrefOrPath={isIncompatible
140+
? openCompatibityWarningDialog
141+
: Paths.TRAINING}
142+
class="mb-5">
121143
<h3 class="text-center text-2xl font-bold">
122144
{$t('content.index.toolProcessCards.train.title')}
123145
</h3>
@@ -131,7 +153,11 @@
131153

132154
<LinkOverlayContainer>
133155
<FrontPageContentTile>
134-
<LinkOverlay path={Paths.MODEL} class="mb-5">
156+
<LinkOverlay
157+
onClickOrHrefOrPath={isIncompatible
158+
? openCompatibityWarningDialog
159+
: Paths.MODEL}
160+
class="mb-5">
135161
<h3 class="text-center text-2xl font-bold">
136162
{$t('content.index.toolProcessCards.model.title')}
137163
</h3>
@@ -153,7 +179,7 @@
153179
<StandardButton
154180
size="large"
155181
type={hasExistingSession ? 'secondary' : 'primary'}
156-
onClick={checkForExistingSession}>{$t('footer.start')}</StandardButton>
182+
onClick={onClickStartNewSession}>{$t('footer.start')}</StandardButton>
157183
</div>
158184
</div>
159185
</main>

0 commit comments

Comments
 (0)