kan välja mellan ämneslistor och standardlistor med cachning
This commit is contained in:
parent
7ccc660b05
commit
84d874f81f
101
src/components/listselector.svelte
Normal file
101
src/components/listselector.svelte
Normal file
@ -0,0 +1,101 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
import * as Card from '$lib/components/ui/card/index';
|
||||
import * as Select from '$lib/components/ui/select';
|
||||
import { Label } from '$lib/components/ui/label';
|
||||
import { db } from '../db/main';
|
||||
import { liveQuery } from 'dexie';
|
||||
import { shortforms } from '$lib/stores.svelte';
|
||||
import { cacheShortforms } from '../modules/shortforms';
|
||||
|
||||
const onSelectedStandardListChange = (e) => {
|
||||
console.log('onSelectedStandardListChange', e);
|
||||
shortforms.standardList = e.value;
|
||||
cacheShortforms([Number(shortforms.standardList), Number(shortforms.subjectLists)]);
|
||||
};
|
||||
|
||||
const onSelectedSubjectListChange = (e) => {
|
||||
console.log('onSelectedSubjectListChange', e);
|
||||
shortforms.subjectList = e.value;
|
||||
cacheShortforms([Number(shortforms.standardList), Number(shortforms.subjectList)]);
|
||||
};
|
||||
|
||||
const onSubmit = (e) => {
|
||||
e.preventDefault();
|
||||
console.log('submit', listSelectorForm);
|
||||
};
|
||||
|
||||
let listSelectorForm = {
|
||||
standard: { value: '', label: '' },
|
||||
subject: { value: '', label: '' }
|
||||
};
|
||||
|
||||
let standardLists = [];
|
||||
let subjectLists = [];
|
||||
onMount(() => {
|
||||
db.lists.toArray().then((lists) => {
|
||||
standardLists = lists.filter((l) => l.type == 0);
|
||||
subjectLists = lists.filter((l) => l.type == 1);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<Card.Root class="mx-auto w-[490px]">
|
||||
<Card.Header>
|
||||
<Card.Title>Välj förkortningslistor</Card.Title>
|
||||
<Card.Description></Card.Description>
|
||||
</Card.Header>
|
||||
<Card.Content class="mx-auto">
|
||||
<form
|
||||
class="grid gap-4 py-4"
|
||||
method="post"
|
||||
enctype="multipart/form-data"
|
||||
onsubmit={onSubmit}
|
||||
autocomplete="off"
|
||||
>
|
||||
<div class="grid grid-cols-4 items-center gap-4">
|
||||
<Label>Standardlista</Label>
|
||||
<Select.Root
|
||||
selected={listSelectorForm.standard}
|
||||
onSelectedChange={onSelectedStandardListChange}
|
||||
>
|
||||
<Select.Trigger class="w-[290px]">
|
||||
<Select.Value placeholder="Ingen lista vald" />
|
||||
</Select.Trigger>
|
||||
|
||||
<Select.Content>
|
||||
{#each standardLists as list}
|
||||
<Select.Item value={list.id} label={list.name}>{list.name}</Select.Item>
|
||||
{/each}
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
</div>
|
||||
<div class="grid grid-cols-4 items-center gap-4">
|
||||
<Label>Ämneslista</Label>
|
||||
<Select.Root
|
||||
selected={listSelectorForm.subject}
|
||||
onSelectedChange={onSelectedSubjectListChange}
|
||||
disabled={subjectLists.length < 1}
|
||||
>
|
||||
<Select.Trigger class="w-[290px]">
|
||||
<Select.Value placeholder="Ingen lista vald" />
|
||||
</Select.Trigger>
|
||||
|
||||
<Select.Content>
|
||||
{#each subjectLists as list}
|
||||
<Select.Item value={list.id} label={list.name}>{list.name}</Select.Item>
|
||||
{/each}
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
</div>
|
||||
<button type="submit" class="hidden" />
|
||||
</form>
|
||||
</Card.Content>
|
||||
<!--
|
||||
<Card.Footer class="flex justify-between">
|
||||
<Button on:click={cancelCreate} variant="outline">Avbryt</Button>
|
||||
<Button on:click={handleCreate}>Importera</Button>
|
||||
</Card.Footer>
|
||||
-->
|
||||
</Card.Root>
|
@ -38,6 +38,14 @@
|
||||
</DropdownMenu.Group>
|
||||
<DropdownMenu.Separator />
|
||||
<DropdownMenu.Group>
|
||||
<DropdownMenu.Item
|
||||
on:click={() => {
|
||||
appState.open = 'selectLists';
|
||||
}}
|
||||
>
|
||||
Välj listor
|
||||
<DropdownMenu.Shortcut>F12</DropdownMenu.Shortcut>
|
||||
</DropdownMenu.Item>
|
||||
<DropdownMenu.Item>
|
||||
Förkortningar
|
||||
<DropdownMenu.Shortcut>F12</DropdownMenu.Shortcut>
|
||||
|
@ -32,7 +32,7 @@ const colorThemes = [
|
||||
|
||||
let selectedColor = 0;
|
||||
|
||||
export const shortforms = $state({ standardList: "", subjectLists: [], cache: new Map() })
|
||||
export const shortforms = $state({ standardList: "", subjectList: "", cache: new Map() })
|
||||
export const importState = $state({ data: "", errors: [] })
|
||||
export const textSettings = $state({ font: "Arial", size: 30, colors: colorSetting, padding: 0, lineheight: 1 })
|
||||
export const appState = $state({ text: "", menuOpen: false, open: "" })
|
||||
|
@ -49,6 +49,8 @@ export function cacheShortforms(lists: Array<number> = []) {
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
shortforms.cache = cache
|
||||
return cache;
|
||||
}
|
||||
export function expandShortform(
|
||||
|
@ -2,6 +2,7 @@
|
||||
import Textarea from '../components/textarea.svelte';
|
||||
import Import from '../components/import/import.svelte';
|
||||
import Create from '../components/create.svelte';
|
||||
import ListSelector from '../components/listselector.svelte';
|
||||
import Dashboard from '../components/dashboard.svelte';
|
||||
import { db, deleteShortformList, type Shortform } from '../db/main';
|
||||
import Menu from '../components/menu.svelte';
|
||||
@ -43,6 +44,13 @@
|
||||
<Create />
|
||||
</div>
|
||||
{/if}
|
||||
{#if appState.open == 'selectLists'}
|
||||
<div
|
||||
class="fixed left-0 right-0 top-0 z-50 flex h-[calc(100%-1rem)] max-h-full w-full items-center justify-center align-middle md:inset-0"
|
||||
>
|
||||
<ListSelector />
|
||||
</div>
|
||||
{/if}
|
||||
<div class="h-full">
|
||||
<Menu />
|
||||
<Textarea bind:ref={textarea} />
|
||||
|
Loading…
x
Reference in New Issue
Block a user