feat: save onboarding state and auto trigger onboarding
This commit is contained in:
@ -5,9 +5,12 @@
|
||||
import SettingsButton from "../settings/SettingsButton.svelte";
|
||||
import { view } from "../../view.svelte";
|
||||
import Button from "$lib/components/ui/button/button.svelte";
|
||||
import { setOnboardingState } from "$lib/onboarding.svelte";
|
||||
</script>
|
||||
|
||||
<h1 style="font-size: 2em; font-weight: bold;">{m["sidebar.onboarding.welcome"]()}</h1>
|
||||
<h1 style="font-size: 2em; font-weight: bold;">
|
||||
{m["sidebar.onboarding.welcome"]()}
|
||||
</h1>
|
||||
<h2>{m["sidebar.onboarding.choose-lang"]()}</h2>
|
||||
|
||||
<div id="languages">
|
||||
@ -18,17 +21,23 @@
|
||||
onclick={() => {
|
||||
if (locale != getLocale()) {
|
||||
setLocale(locale);
|
||||
} else {
|
||||
setOnboardingState("vehicles");
|
||||
view.switch("onboarding-vehicles");
|
||||
}
|
||||
view.switch("onboarding-vehicles")
|
||||
}}
|
||||
/>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<Button variant="link" onclick={() => {
|
||||
<Button
|
||||
variant="link"
|
||||
onclick={() => {
|
||||
setOnboardingState("end");
|
||||
view.switch("main");
|
||||
view.history = [];
|
||||
}}>{m["sidebar.onboarding.skip"]()}</Button>
|
||||
}}>{m["sidebar.onboarding.skip"]()}</Button
|
||||
>
|
||||
|
||||
<style>
|
||||
#languages {
|
||||
|
||||
@ -4,9 +4,12 @@
|
||||
import { view } from "../../view.svelte";
|
||||
import AddVehicleDrawer from "../../AddVehicleDrawer.svelte";
|
||||
import Button from "$lib/components/ui/button/button.svelte";
|
||||
import { setOnboardingState } from "$lib/onboarding.svelte";
|
||||
</script>
|
||||
|
||||
<h1 style="font-size: 1.3em; font-weight: bold; margin-bottom: 1rem;">{m["sidebar.onboarding.first-vehicle"]()}</h1>
|
||||
<h1 style="font-size: 1.3em; font-weight: bold; margin-bottom: 1rem;">
|
||||
{m["sidebar.onboarding.first-vehicle"]()}
|
||||
</h1>
|
||||
|
||||
<AddVehicleDrawer>
|
||||
<Button variant="secondary" class="w-full p-5">
|
||||
@ -15,7 +18,11 @@
|
||||
</Button>
|
||||
</AddVehicleDrawer>
|
||||
|
||||
<Button style="margin-top: 1rem; width: 100%;" onclick={() => {
|
||||
<Button
|
||||
style="margin-top: 1rem; width: 100%;"
|
||||
onclick={() => {
|
||||
setOnboardingState("end");
|
||||
view.switch("offline-maps");
|
||||
view.history = [{ type: "main" }];
|
||||
}}>{m.next()}</Button>
|
||||
}}>{m.next()}</Button
|
||||
>
|
||||
|
||||
@ -1,5 +1,11 @@
|
||||
<script>
|
||||
import { HandIcon, MapIcon, SpeechIcon, ToggleLeftIcon } from "@lucide/svelte";
|
||||
import {
|
||||
HandIcon,
|
||||
MapIcon,
|
||||
RefreshCcwIcon,
|
||||
SpeechIcon,
|
||||
ToggleLeftIcon,
|
||||
} from "@lucide/svelte";
|
||||
import SidebarHeader from "../SidebarHeader.svelte";
|
||||
import SettingsButton from "./SettingsButton.svelte";
|
||||
import say from "$lib/services/navigation/TTS";
|
||||
@ -7,6 +13,7 @@
|
||||
import { getDeveloperToggle } from "./developer.svelte";
|
||||
import { view } from "../../view.svelte";
|
||||
import { m } from "$lang/messages";
|
||||
import { setOnboardingState } from "$lib/onboarding.svelte";
|
||||
|
||||
const dev = getDeveloperToggle();
|
||||
</script>
|
||||
@ -39,10 +46,20 @@
|
||||
|
||||
<section>
|
||||
<h2>Open</h2>
|
||||
<SettingsButton icon={HandIcon} text="Start onboarding" view="onboarding" />
|
||||
<SettingsButton
|
||||
icon={HandIcon}
|
||||
text="Start onboarding"
|
||||
view="onboarding"
|
||||
text="Reset onboarding"
|
||||
onclick={() => {
|
||||
setOnboardingState("start");
|
||||
}}
|
||||
/>
|
||||
<SettingsButton
|
||||
icon={RefreshCcwIcon}
|
||||
text="Reload"
|
||||
onclick={() => {
|
||||
location.reload();
|
||||
}}
|
||||
/>
|
||||
</section>
|
||||
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
import { getOnboardingView } from "$lib/onboarding.svelte";
|
||||
|
||||
export interface View {
|
||||
type: string;
|
||||
props?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export const view = $state({
|
||||
current: { type: "main" } as View,
|
||||
current: { type: getOnboardingView("main") } as View,
|
||||
history: [] as View[],
|
||||
back: () => {
|
||||
if (view.history.length > 0) {
|
||||
|
||||
20
src/lib/onboarding.svelte.ts
Normal file
20
src/lib/onboarding.svelte.ts
Normal file
@ -0,0 +1,20 @@
|
||||
type OnboardingState = "start" | "vehicles" | "end";
|
||||
|
||||
export function getOnboardingState(): OnboardingState {
|
||||
const value = localStorage.getItem("onboarding") as OnboardingState;
|
||||
return value ?? "start";
|
||||
}
|
||||
|
||||
export function setOnboardingState(value: OnboardingState) {
|
||||
localStorage.setItem("onboarding", value);
|
||||
}
|
||||
|
||||
export function getOnboardingView(def: string) {
|
||||
if (!window.__TAURI__) return def;
|
||||
const state = getOnboardingState();
|
||||
return state == "start"
|
||||
? "onboarding"
|
||||
: state == "vehicles"
|
||||
? "onboarding-vehicles"
|
||||
: def;
|
||||
}
|
||||
Reference in New Issue
Block a user