feat: save onboarding state and auto trigger onboarding
This commit is contained in:
@ -5,9 +5,12 @@
|
|||||||
import SettingsButton from "../settings/SettingsButton.svelte";
|
import SettingsButton from "../settings/SettingsButton.svelte";
|
||||||
import { view } from "../../view.svelte";
|
import { view } from "../../view.svelte";
|
||||||
import Button from "$lib/components/ui/button/button.svelte";
|
import Button from "$lib/components/ui/button/button.svelte";
|
||||||
|
import { setOnboardingState } from "$lib/onboarding.svelte";
|
||||||
</script>
|
</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>
|
<h2>{m["sidebar.onboarding.choose-lang"]()}</h2>
|
||||||
|
|
||||||
<div id="languages">
|
<div id="languages">
|
||||||
@ -16,19 +19,25 @@
|
|||||||
text={m.language({}, { locale })}
|
text={m.language({}, { locale })}
|
||||||
icon={LanguagesIcon}
|
icon={LanguagesIcon}
|
||||||
onclick={() => {
|
onclick={() => {
|
||||||
if(locale != getLocale()) {
|
if (locale != getLocale()) {
|
||||||
setLocale(locale);
|
setLocale(locale);
|
||||||
|
} else {
|
||||||
|
setOnboardingState("vehicles");
|
||||||
|
view.switch("onboarding-vehicles");
|
||||||
}
|
}
|
||||||
view.switch("onboarding-vehicles")
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Button variant="link" onclick={() => {
|
<Button
|
||||||
view.switch("main");
|
variant="link"
|
||||||
view.history = [];
|
onclick={() => {
|
||||||
}}>{m["sidebar.onboarding.skip"]()}</Button>
|
setOnboardingState("end");
|
||||||
|
view.switch("main");
|
||||||
|
view.history = [];
|
||||||
|
}}>{m["sidebar.onboarding.skip"]()}</Button
|
||||||
|
>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
#languages {
|
#languages {
|
||||||
|
|||||||
@ -4,9 +4,12 @@
|
|||||||
import { view } from "../../view.svelte";
|
import { view } from "../../view.svelte";
|
||||||
import AddVehicleDrawer from "../../AddVehicleDrawer.svelte";
|
import AddVehicleDrawer from "../../AddVehicleDrawer.svelte";
|
||||||
import Button from "$lib/components/ui/button/button.svelte";
|
import Button from "$lib/components/ui/button/button.svelte";
|
||||||
|
import { setOnboardingState } from "$lib/onboarding.svelte";
|
||||||
</script>
|
</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>
|
<AddVehicleDrawer>
|
||||||
<Button variant="secondary" class="w-full p-5">
|
<Button variant="secondary" class="w-full p-5">
|
||||||
@ -15,7 +18,11 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</AddVehicleDrawer>
|
</AddVehicleDrawer>
|
||||||
|
|
||||||
<Button style="margin-top: 1rem; width: 100%;" onclick={() => {
|
<Button
|
||||||
view.switch("offline-maps");
|
style="margin-top: 1rem; width: 100%;"
|
||||||
view.history = [{ type: "main" }];
|
onclick={() => {
|
||||||
}}>{m.next()}</Button>
|
setOnboardingState("end");
|
||||||
|
view.switch("offline-maps");
|
||||||
|
view.history = [{ type: "main" }];
|
||||||
|
}}>{m.next()}</Button
|
||||||
|
>
|
||||||
|
|||||||
@ -1,5 +1,11 @@
|
|||||||
<script>
|
<script>
|
||||||
import { HandIcon, MapIcon, SpeechIcon, ToggleLeftIcon } from "@lucide/svelte";
|
import {
|
||||||
|
HandIcon,
|
||||||
|
MapIcon,
|
||||||
|
RefreshCcwIcon,
|
||||||
|
SpeechIcon,
|
||||||
|
ToggleLeftIcon,
|
||||||
|
} from "@lucide/svelte";
|
||||||
import SidebarHeader from "../SidebarHeader.svelte";
|
import SidebarHeader from "../SidebarHeader.svelte";
|
||||||
import SettingsButton from "./SettingsButton.svelte";
|
import SettingsButton from "./SettingsButton.svelte";
|
||||||
import say from "$lib/services/navigation/TTS";
|
import say from "$lib/services/navigation/TTS";
|
||||||
@ -7,6 +13,7 @@
|
|||||||
import { getDeveloperToggle } from "./developer.svelte";
|
import { getDeveloperToggle } from "./developer.svelte";
|
||||||
import { view } from "../../view.svelte";
|
import { view } from "../../view.svelte";
|
||||||
import { m } from "$lang/messages";
|
import { m } from "$lang/messages";
|
||||||
|
import { setOnboardingState } from "$lib/onboarding.svelte";
|
||||||
|
|
||||||
const dev = getDeveloperToggle();
|
const dev = getDeveloperToggle();
|
||||||
</script>
|
</script>
|
||||||
@ -39,10 +46,20 @@
|
|||||||
|
|
||||||
<section>
|
<section>
|
||||||
<h2>Open</h2>
|
<h2>Open</h2>
|
||||||
|
<SettingsButton icon={HandIcon} text="Start onboarding" view="onboarding" />
|
||||||
<SettingsButton
|
<SettingsButton
|
||||||
icon={HandIcon}
|
icon={HandIcon}
|
||||||
text="Start onboarding"
|
text="Reset onboarding"
|
||||||
view="onboarding"
|
onclick={() => {
|
||||||
|
setOnboardingState("start");
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<SettingsButton
|
||||||
|
icon={RefreshCcwIcon}
|
||||||
|
text="Reload"
|
||||||
|
onclick={() => {
|
||||||
|
location.reload();
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
|
import { getOnboardingView } from "$lib/onboarding.svelte";
|
||||||
|
|
||||||
export interface View {
|
export interface View {
|
||||||
type: string;
|
type: string;
|
||||||
props?: Record<string, unknown>;
|
props?: Record<string, unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const view = $state({
|
export const view = $state({
|
||||||
current: { type: "main" } as View,
|
current: { type: getOnboardingView("main") } as View,
|
||||||
history: [] as View[],
|
history: [] as View[],
|
||||||
back: () => {
|
back: () => {
|
||||||
if (view.history.length > 0) {
|
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