Add utility functions to ease the setting of preferences
This commit is contained in:
parent
56ff114f5d
commit
1ce509ffa5
@ -5,14 +5,13 @@
|
|||||||
import type { CardConfig } from "./Card.types";
|
import type { CardConfig } from "./Card.types";
|
||||||
import type { NearestStationResponse } from "@owlboard/ts-types";
|
import type { NearestStationResponse } from "@owlboard/ts-types";
|
||||||
import { uuid } from "$lib/stores/uuid";
|
import { uuid } from "$lib/stores/uuid";
|
||||||
import { preferences } from "$lib/stores/preferences";
|
import { preferences, togglePreference } from "$lib/stores/preferences";
|
||||||
import InLineLoading from "$lib/navigation/InLineLoading.svelte";
|
import InLineLoading from "$lib/navigation/InLineLoading.svelte";
|
||||||
import { apiGet } from "$lib/scripts/apiFetch";
|
import { apiGet } from "$lib/scripts/apiFetch";
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import { nearToMeCache } from "$lib/stores/nearToMeCache";
|
import { nearToMeCache } from "$lib/stores/nearToMeCache";
|
||||||
import LinkButton from "$lib/buttons/LinkButton.svelte";
|
import LinkButton from "$lib/buttons/LinkButton.svelte";
|
||||||
import ScriptButton from "$lib/buttons/ScriptButton.svelte";
|
import ScriptButton from "$lib/buttons/ScriptButton.svelte";
|
||||||
import { togglePreference } from "$lib/scripts/preferenceUtil";
|
|
||||||
|
|
||||||
let errorMessage: string;
|
let errorMessage: string;
|
||||||
let stations: NearestStationResponse[] = [];
|
let stations: NearestStationResponse[] = [];
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Island from "$lib/islands/island.svelte";
|
import Island from "$lib/islands/island.svelte";
|
||||||
import type { Preferences } from "$lib/stores/preferences";
|
import type { Preferences } from "$lib/stores/preferences";
|
||||||
import { preferences } from "$lib/stores/preferences";
|
import { preferences, setQl, clearQl, addQlItem } from "$lib/stores/preferences";
|
||||||
import toast from "svelte-french-toast";
|
import toast from "svelte-french-toast";
|
||||||
export let variables = {
|
export let variables = {
|
||||||
title: "Quick Links",
|
title: "Quick Links",
|
||||||
@ -38,30 +38,20 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(inputLinks);
|
console.log(inputLinks);
|
||||||
preferences.update((p: Preferences) => ({
|
setQl(inputLinks);
|
||||||
...p,
|
|
||||||
ql: inputLinks,
|
|
||||||
}))
|
|
||||||
await timeout(1000);
|
await timeout(1000);
|
||||||
saveButton = "Saved";
|
saveButton = "Saved";
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearQl(): void {
|
function clearQlSettings(): void {
|
||||||
preferences.update((p: Preferences) => ({
|
clearQl();
|
||||||
...p,
|
|
||||||
ql: [],
|
|
||||||
}))
|
|
||||||
saveButton = "Saved";
|
saveButton = "Saved";
|
||||||
toast.success("Cleared Quick Links.");
|
toast.success("Cleared Quick Links.");
|
||||||
}
|
}
|
||||||
|
|
||||||
function addQlBox(): void {
|
function addQlBox(): void {
|
||||||
saveButton = "Save";
|
saveButton = "Save";
|
||||||
const updatedQl = [...qlData, ""];
|
addQlItem("");
|
||||||
preferences.update((p: Preferences) => ({
|
|
||||||
...p,
|
|
||||||
ql: updatedQl,
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleClick(event: any): void {
|
function handleClick(event: any): void {
|
||||||
@ -83,7 +73,7 @@
|
|||||||
<button on:click={addQlBox} id="qlAdd">+</button>
|
<button on:click={addQlBox} id="qlAdd">+</button>
|
||||||
</div>
|
</div>
|
||||||
<button on:click={save}>{@html saveButton}</button>
|
<button on:click={save}>{@html saveButton}</button>
|
||||||
<button on:click={clearQl}>Clear</button>
|
<button on:click={clearQlSettings}>Clear</button>
|
||||||
</Island>
|
</Island>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
import type { Preferences } from "$lib/stores/preferences";
|
|
||||||
import { preferences } from "$lib/stores/preferences";
|
|
||||||
|
|
||||||
export function togglePreference<K extends keyof Preferences>(key: K, value: boolean): void {
|
|
||||||
preferences.update(p => ({
|
|
||||||
...p,
|
|
||||||
[key]: value,
|
|
||||||
}));
|
|
||||||
}
|
|
@ -59,3 +59,21 @@ try {
|
|||||||
console.error("Preferences migration failed, resetting store", e);
|
console.error("Preferences migration failed, resetting store", e);
|
||||||
preferences.reset();
|
preferences.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Utility Functions
|
||||||
|
|
||||||
|
export function addQlItem(item: string): void {
|
||||||
|
preferences.update(p => ({ ...p, ql: [...p.ql, item] }));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setQl(items: string[]): void {
|
||||||
|
preferences.update(p => ({ ...p, ql: items }));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearQl(): void {
|
||||||
|
preferences.update(p => ({ ...p, ql: [] }));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function togglePreference<K extends keyof Preferences>(key: K, value: boolean): void {
|
||||||
|
preferences.update(p => ({ ...p, [key]: value }));
|
||||||
|
}
|
||||||
|
@ -3,8 +3,7 @@
|
|||||||
import Nav from "$lib/navigation/nav.svelte";
|
import Nav from "$lib/navigation/nav.svelte";
|
||||||
import QlSet from "$lib/islands/quick-link-set-island.svelte";
|
import QlSet from "$lib/islands/quick-link-set-island.svelte";
|
||||||
import Island from "$lib/islands/island.svelte";
|
import Island from "$lib/islands/island.svelte";
|
||||||
import { preferences } from "$lib/stores/preferences";
|
import { preferences, togglePreference } from "$lib/stores/preferences";
|
||||||
import { togglePreference } from "$lib/scripts/preferenceUtil";
|
|
||||||
import { getCurrentLocation } from "$lib/scripts/getLocation";
|
import { getCurrentLocation } from "$lib/scripts/getLocation";
|
||||||
import toast from "svelte-french-toast";
|
import toast from "svelte-french-toast";
|
||||||
const title = "Settings";
|
const title = "Settings";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user