ändra hur valda listor sparas, öppna och stäng debug med home
This commit is contained in:
parent
705caa3cfa
commit
619c33c189
@ -21,13 +21,13 @@
|
|||||||
$: abbForm = {
|
$: abbForm = {
|
||||||
shortform: '',
|
shortform: '',
|
||||||
phrase: '',
|
phrase: '',
|
||||||
target: '',
|
target: { value: -1 },
|
||||||
errors: []
|
errors: []
|
||||||
};
|
};
|
||||||
|
|
||||||
let importing = false;
|
let importing = false;
|
||||||
let progress = 0;
|
let progress = 0;
|
||||||
const handleCreate = async (e: Any) => {
|
const handleCreate = async (e: Event) => {
|
||||||
// abbForm.errors = []
|
// abbForm.errors = []
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
@ -41,7 +41,8 @@
|
|||||||
remind: number, // negative if disabled
|
remind: number, // negative if disabled
|
||||||
updated: Date;
|
updated: Date;
|
||||||
*/
|
*/
|
||||||
const sf = {
|
var sf = {
|
||||||
|
id: null,
|
||||||
listid: abbForm.target.value,
|
listid: abbForm.target.value,
|
||||||
shortform: abbForm.shortform.replace(/\s/g, '').toLowerCase(),
|
shortform: abbForm.shortform.replace(/\s/g, '').toLowerCase(),
|
||||||
phrase: abbForm.phrase.trim(),
|
phrase: abbForm.phrase.trim(),
|
||||||
@ -56,11 +57,13 @@
|
|||||||
.equals([sf.listid, sf.shortform])
|
.equals([sf.listid, sf.shortform])
|
||||||
.first()
|
.first()
|
||||||
.then((existing) => {
|
.then((existing) => {
|
||||||
sf.id = existing.id;
|
if (existing?.id) {
|
||||||
db.shortforms.put(sf).then((result) => {
|
sf.id = Number(existing.id);
|
||||||
cacheShortform(sf);
|
db.shortforms.put(sf).then((result) => {
|
||||||
appState.open = '';
|
cacheShortform(sf);
|
||||||
});
|
appState.open = '';
|
||||||
|
});
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
db.shortforms.put(sf).then((result) => {
|
db.shortforms.put(sf).then((result) => {
|
||||||
@ -81,17 +84,18 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onSelectedChange = (v) => {
|
const onSelectedChange = (v) => {
|
||||||
// console.log(v);
|
console.log(typeof v, v);
|
||||||
abbForm.target = v;
|
abbForm.target = v;
|
||||||
};
|
};
|
||||||
|
|
||||||
$: selectedLists = {
|
$: selectedLists = {
|
||||||
standard: {},
|
standard: { label: '', value: -1 },
|
||||||
subject: {}
|
subject: { label: '', value: -1 }
|
||||||
};
|
};
|
||||||
let show = false;
|
let show = false;
|
||||||
|
|
||||||
db.lists
|
db.lists
|
||||||
.get(shortforms.standardList)
|
.get(shortforms.standardList.id)
|
||||||
.then((l) => {
|
.then((l) => {
|
||||||
if (l) {
|
if (l) {
|
||||||
selectedLists.standard = { value: l.id, label: l.name };
|
selectedLists.standard = { value: l.id, label: l.name };
|
||||||
@ -104,7 +108,7 @@
|
|||||||
console.error('db.lists.get (standard)', err);
|
console.error('db.lists.get (standard)', err);
|
||||||
});
|
});
|
||||||
db.lists
|
db.lists
|
||||||
.get(shortforms.subjectList)
|
.get(shortforms.subjectList.id)
|
||||||
.then((l) => {
|
.then((l) => {
|
||||||
if (l) {
|
if (l) {
|
||||||
selectedLists.subject = { value: l.id, label: l.name };
|
selectedLists.subject = { value: l.id, label: l.name };
|
||||||
@ -159,13 +163,7 @@
|
|||||||
>
|
>
|
||||||
<div class="grid grid-cols-4 items-center gap-4">
|
<div class="grid grid-cols-4 items-center gap-4">
|
||||||
<Label>Förkortning</Label>
|
<Label>Förkortning</Label>
|
||||||
<Input
|
<Input id="shortformEl" bind:value={abbForm.shortform} placeholder="" class="w-[290px]" />
|
||||||
id="shortformEl"
|
|
||||||
bind:value={abbForm.shortform}
|
|
||||||
focus
|
|
||||||
placeholder=""
|
|
||||||
class="w-[290px]"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="grid grid-cols-4 items-center gap-4">
|
<div class="grid grid-cols-4 items-center gap-4">
|
||||||
<Label>Text</Label>
|
<Label>Text</Label>
|
||||||
@ -221,7 +219,7 @@
|
|||||||
>
|
>
|
||||||
<p class="font-bold">Fel vid import</p>
|
<p class="font-bold">Fel vid import</p>
|
||||||
<ul class="p-6">
|
<ul class="p-6">
|
||||||
{#each abbForms.errors as error}
|
{#each abbForm.errors as error}
|
||||||
<li class="list-disc">{error}</li>
|
<li class="list-disc">{error}</li>
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<script>
|
<script lang="ts">
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { clickOutside } from 'svelte-outside';
|
import { clickOutside } from 'svelte-outside';
|
||||||
import * as Card from '$lib/components/ui/card/index';
|
import * as Card from '$lib/components/ui/card/index';
|
||||||
@ -9,22 +9,30 @@
|
|||||||
import { appState, shortforms } from '$lib/stores.svelte';
|
import { appState, shortforms } from '$lib/stores.svelte';
|
||||||
import { cacheShortforms } from '../modules/shortforms';
|
import { cacheShortforms } from '../modules/shortforms';
|
||||||
|
|
||||||
const onSelectedStandardListChange = (e) => {
|
interface listOption {
|
||||||
console.log('onSelectedStandardListChange', e);
|
value: number;
|
||||||
shortforms.standardList = e.value;
|
label: string;
|
||||||
cacheShortforms([Number(shortforms.standardList), Number(shortforms.subjectList)]);
|
disabled: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const onSelectedStandardListChange = (e: listOption) => {
|
||||||
|
console.log('onSelectedStandardListChange', typeof e, e);
|
||||||
|
shortforms.standardList.id = e.value;
|
||||||
|
shortforms.standardList.name = e.label;
|
||||||
|
cacheShortforms([Number(shortforms.standardList.id), Number(shortforms.subjectList.id)]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSelectedSubjectListChange = (e) => {
|
const onSelectedSubjectListChange = (e) => {
|
||||||
if (e.value == 0) {
|
if (e.value == 0) {
|
||||||
listSelectorForm.subject = { value: '', label: '' };
|
listSelectorForm.subject = { value: '', label: '' };
|
||||||
shortforms.subjectList = '';
|
shortforms.subjectList = { name: '', id: -1 };
|
||||||
cacheShortforms([Number(shortforms.standardList)]);
|
cacheShortforms([Number(shortforms.standardList.id)]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log('onSelectedSubjectListChange', e);
|
console.log('onSelectedSubjectListChange', e);
|
||||||
shortforms.subjectList = e.value;
|
shortforms.subjectList.id = e.value;
|
||||||
cacheShortforms([Number(shortforms.standardList), Number(shortforms.subjectList)]);
|
shortforms.subjectList.name = e.label;
|
||||||
|
cacheShortforms([Number(shortforms.standardList.id), Number(shortforms.subjectList.id)]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSubmit = (e) => {
|
const onSubmit = (e) => {
|
||||||
@ -37,22 +45,22 @@
|
|||||||
subject: {}
|
subject: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getListFromId = (lists, id) => {
|
|
||||||
return lists.filter((l) => l.id == id)[0];
|
|
||||||
};
|
|
||||||
|
|
||||||
let standardLists = [];
|
let standardLists = [];
|
||||||
let subjectLists = [];
|
$: subjectLists = [];
|
||||||
let show = false;
|
let show = false;
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
//console.log($state.snapshot(shortforms));
|
//console.log($state.snapshot(shortforms));
|
||||||
db.lists.toArray().then((lists) => {
|
db.lists.toArray().then((lists) => {
|
||||||
standardLists = lists.filter((l) => l.type == 0);
|
standardLists = lists.filter((l) => l.type == 0);
|
||||||
subjectLists = lists.filter((l) => l.type == 1);
|
subjectLists = lists.filter((l) => l.type == 1);
|
||||||
const standard = getListFromId(standardLists, shortforms.standardList);
|
listSelectorForm.standard = {
|
||||||
listSelectorForm.standard = { value: standard.id, label: standard.name };
|
value: shortforms.standardList.id,
|
||||||
const subject = getListFromId(subjectLists, shortforms.subjectList);
|
label: shortforms.standardList.name
|
||||||
listSelectorForm.subject = { value: subject.id, label: subject.name };
|
};
|
||||||
|
listSelectorForm.subject = {
|
||||||
|
value: shortforms.subjectList.id,
|
||||||
|
label: shortforms.subjectList.name
|
||||||
|
};
|
||||||
console.log(listSelectorForm);
|
console.log(listSelectorForm);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -13,18 +13,8 @@
|
|||||||
|
|
||||||
import * as Select from '$lib/components/ui/select/index.js';
|
import * as Select from '$lib/components/ui/select/index.js';
|
||||||
|
|
||||||
let styles = $derived({
|
|
||||||
'text-bg': '#333333',
|
|
||||||
'text-fg': '#baff00',
|
|
||||||
'text-font': textSettings.font,
|
|
||||||
'text-size': textSettings.size + 'px'
|
|
||||||
});
|
|
||||||
|
|
||||||
let selectedStandardList = {};
|
let selectedStandardList = {};
|
||||||
const selectedStandardListChanged = (v) => {
|
|
||||||
shortforms.standardList = v.value;
|
|
||||||
shortforms.cache = cacheShortforms([Number(v.value)]);
|
|
||||||
};
|
|
||||||
let state = {
|
let state = {
|
||||||
capitalizeNext: true,
|
capitalizeNext: true,
|
||||||
currentWord: ''
|
currentWord: ''
|
||||||
@ -51,10 +41,6 @@
|
|||||||
return await db.lists.toArray();
|
return await db.lists.toArray();
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
let css = Object.entries(styles)
|
|
||||||
.map(([key, value]) => `--${key}:${value}`)
|
|
||||||
.join(';');
|
|
||||||
const cssVarStyles = $derived({ css });
|
|
||||||
|
|
||||||
const expand = (e: InputEvent) => {
|
const expand = (e: InputEvent) => {
|
||||||
let expander = e.data as string;
|
let expander = e.data as string;
|
||||||
|
@ -32,10 +32,10 @@ const colorThemes = [
|
|||||||
|
|
||||||
let selectedColor = 0;
|
let selectedColor = 0;
|
||||||
|
|
||||||
export const shortforms = $state({ standardList: "", subjectList: "", cache: new Map() })
|
export const shortforms = $state({ standardList: { name: "", id: -1 }, subjectList: { name: "", id: -1 }, cache: new Map() })
|
||||||
export const importState = $state({ data: "", errors: [] })
|
export const importState = $state({ data: "", errors: [] })
|
||||||
export const textSettings = $state({ font: "Arial", size: 30, colors: colorSetting, padding: 0, lineheight: 1 })
|
export const textSettings = $state({ font: "Arial", size: 30, colors: colorSetting, padding: 0, lineheight: 1 })
|
||||||
export const appState = $state({ text: "", menuOpen: false, open: "" })
|
export const appState = $state({ debug: true, menuOpen: false, open: "", text: "", })
|
||||||
|
|
||||||
import { toast } from "svelte-sonner";
|
import { toast } from "svelte-sonner";
|
||||||
import { db } from "../db/main"
|
import { db } from "../db/main"
|
||||||
@ -43,12 +43,14 @@ import { cacheShortforms } from "../modules/shortforms"
|
|||||||
|
|
||||||
export const initShortformState = async () => {
|
export const initShortformState = async () => {
|
||||||
const lists = await db.lists.toArray()
|
const lists = await db.lists.toArray()
|
||||||
if (shortforms.standardList == "") {
|
if (shortforms.standardList.id == -1) {
|
||||||
if (lists.length > 0) {
|
if (lists.length > 0) {
|
||||||
console.log("Väljer en av standardlistorna")
|
if (lists[0]?.id) {
|
||||||
shortforms.standardList = lists[0].id
|
shortforms.standardList.id = lists[0].id
|
||||||
toast("Ingen standardlista vald. Väljer " + lists[0].name)
|
shortforms.standardList.name = lists[0].name
|
||||||
shortforms.cache = cacheShortforms([shortforms.standardList]);
|
toast("Ingen standardlista vald. Väljer " + lists[0].name)
|
||||||
|
shortforms.cache = cacheShortforms([shortforms.standardList.id]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,7 +70,6 @@ export const toggleMenuOpen = (force = undefined) => {
|
|||||||
|
|
||||||
|
|
||||||
export const incTextSize = () => {
|
export const incTextSize = () => {
|
||||||
console.log(textSettings.size)
|
|
||||||
if (textSettings.size < 200) {
|
if (textSettings.size < 200) {
|
||||||
textSettings.size += 5
|
textSettings.size += 5
|
||||||
return
|
return
|
||||||
|
@ -84,12 +84,10 @@ defaultExpanders.set(";", {
|
|||||||
fullstop: false,
|
fullstop: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
hotkeys.set("F1", {
|
hotkeys.set("Home", {
|
||||||
action: (e) => {
|
action: (e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
console.log("Open dashboard")
|
appState.debug = !appState.debug;
|
||||||
appState.open = "dashboard"
|
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -7,13 +7,13 @@
|
|||||||
import { db, deleteShortformList, type Shortform } from '../db/main';
|
import { db, deleteShortformList, type Shortform } from '../db/main';
|
||||||
import Menu from '../components/menu.svelte';
|
import Menu from '../components/menu.svelte';
|
||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import { appState } from '$lib/stores.svelte';
|
import { appState, shortforms } from '$lib/stores.svelte';
|
||||||
let loaded = false;
|
let loaded = false;
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
console.log(appState.open);
|
console.log(appState.open);
|
||||||
appState.open;
|
appState.open;
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
if (appState.open == '') {
|
if (appState.open == '' && textarea != undefined) {
|
||||||
textarea.focus();
|
textarea.focus();
|
||||||
}
|
}
|
||||||
if (appState.open == 'selectLists') {
|
if (appState.open == 'selectLists') {
|
||||||
@ -27,18 +27,22 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
loaded = true;
|
loaded = true;
|
||||||
|
debugState = JSON.stringify(appState, null, 4);
|
||||||
|
debugShortforms = JSON.stringify(shortforms, null, 4);
|
||||||
});
|
});
|
||||||
import { hotkeys } from '../modules/keyboard';
|
import { hotkeys } from '../modules/keyboard';
|
||||||
var showDashboard = $state(0);
|
var showDashboard = $state(true);
|
||||||
import { Toaster } from '$lib/components/ui/sonner';
|
import { Toaster } from '$lib/components/ui/sonner';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
const handleHotkeys = (e: KeyboardEvent) => {
|
const handleHotkeys = (e: KeyboardEvent) => {
|
||||||
hotkeys.get(e.key)?.action(e);
|
hotkeys.get(e.key)?.action(e);
|
||||||
};
|
};
|
||||||
let textarea = null;
|
let textarea: HTMLTextAreaElement | undefined = $state();
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
appState.open = 'dashboard';
|
appState.open = 'dashboard';
|
||||||
});
|
});
|
||||||
|
var debugState = $state();
|
||||||
|
var debugShortforms = $state();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@ -47,6 +51,13 @@
|
|||||||
<svelte:window on:keydown={handleHotkeys} />
|
<svelte:window on:keydown={handleHotkeys} />
|
||||||
|
|
||||||
<div class="h-dvh w-full overflow-hidden" role="application">
|
<div class="h-dvh w-full overflow-hidden" role="application">
|
||||||
|
{#if appState.debug}
|
||||||
|
<div>
|
||||||
|
hello appState: {debugState}
|
||||||
|
<br />
|
||||||
|
shortforms: {debugShortforms}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
{#if appState.open == 'create'}
|
{#if appState.open == 'create'}
|
||||||
<div
|
<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"
|
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"
|
||||||
@ -68,5 +79,4 @@
|
|||||||
<Dashboard open={showDashboard} />
|
<Dashboard open={showDashboard} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Toaster />
|
<Toaster />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user