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 { NearestStationResponse } from "@owlboard/ts-types";
|
||||
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 { apiGet } from "$lib/scripts/apiFetch";
|
||||
import { onMount } from "svelte";
|
||||
import { nearToMeCache } from "$lib/stores/nearToMeCache";
|
||||
import LinkButton from "$lib/buttons/LinkButton.svelte";
|
||||
import ScriptButton from "$lib/buttons/ScriptButton.svelte";
|
||||
import { togglePreference } from "$lib/scripts/preferenceUtil";
|
||||
|
||||
let errorMessage: string;
|
||||
let stations: NearestStationResponse[] = [];
|
||||
|
@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import Island from "$lib/islands/island.svelte";
|
||||
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";
|
||||
export let variables = {
|
||||
title: "Quick Links",
|
||||
@ -38,30 +38,20 @@
|
||||
}
|
||||
}
|
||||
console.log(inputLinks);
|
||||
preferences.update((p: Preferences) => ({
|
||||
...p,
|
||||
ql: inputLinks,
|
||||
}))
|
||||
setQl(inputLinks);
|
||||
await timeout(1000);
|
||||
saveButton = "Saved";
|
||||
}
|
||||
|
||||
function clearQl(): void {
|
||||
preferences.update((p: Preferences) => ({
|
||||
...p,
|
||||
ql: [],
|
||||
}))
|
||||
function clearQlSettings(): void {
|
||||
clearQl();
|
||||
saveButton = "Saved";
|
||||
toast.success("Cleared Quick Links.");
|
||||
}
|
||||
|
||||
function addQlBox(): void {
|
||||
saveButton = "Save";
|
||||
const updatedQl = [...qlData, ""];
|
||||
preferences.update((p: Preferences) => ({
|
||||
...p,
|
||||
ql: updatedQl,
|
||||
}))
|
||||
addQlItem("");
|
||||
}
|
||||
|
||||
function handleClick(event: any): void {
|
||||
@ -83,7 +73,7 @@
|
||||
<button on:click={addQlBox} id="qlAdd">+</button>
|
||||
</div>
|
||||
<button on:click={save}>{@html saveButton}</button>
|
||||
<button on:click={clearQl}>Clear</button>
|
||||
<button on:click={clearQlSettings}>Clear</button>
|
||||
</Island>
|
||||
|
||||
<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);
|
||||
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 QlSet from "$lib/islands/quick-link-set-island.svelte";
|
||||
import Island from "$lib/islands/island.svelte";
|
||||
import { preferences } from "$lib/stores/preferences";
|
||||
import { togglePreference } from "$lib/scripts/preferenceUtil";
|
||||
import { preferences, togglePreference } from "$lib/stores/preferences";
|
||||
import { getCurrentLocation } from "$lib/scripts/getLocation";
|
||||
import toast from "svelte-french-toast";
|
||||
const title = "Settings";
|
||||
|
Loading…
x
Reference in New Issue
Block a user