generated from dave/wails-template
Add Nowstore
This commit is contained in:
@@ -3,18 +3,33 @@
|
||||
import Header from "$lib/components/Header.svelte";
|
||||
import Router from "$lib/router/Router.svelte";
|
||||
import { billsStore } from "$lib/store/billsStore";
|
||||
import { Close } from '$wails/main/App'
|
||||
import { Close } from "$wails/main/App";
|
||||
import { nowStore } from "$lib/store/nowStore";
|
||||
|
||||
console.log($billsStore);
|
||||
console.log($nowStore);
|
||||
|
||||
function keyDown(event: KeyboardEvent) {
|
||||
setTimeout(nowStore.next, 1000);
|
||||
setTimeout(nowStore.next, 2000);
|
||||
setTimeout(nowStore.next, 3000);
|
||||
setTimeout(nowStore.next, 4000);
|
||||
setTimeout(nowStore.next, 5000);
|
||||
setTimeout(nowStore.next, 6000);
|
||||
setTimeout(nowStore.next, 7000);
|
||||
setTimeout(nowStore.next, 8000);
|
||||
|
||||
$: {
|
||||
console.log($nowStore);
|
||||
}
|
||||
|
||||
function keyDown(event: KeyboardEvent) {
|
||||
if (event.ctrlKey && event.key == "r") {
|
||||
window.location.reload();
|
||||
}
|
||||
if (event.ctrlKey && event.key == "w") {
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window on:keydown={keyDown} />
|
||||
|
24
frontend/src/lib/store/nowStore.ts
Normal file
24
frontend/src/lib/store/nowStore.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { type Writable, writable } from "svelte/store";
|
||||
|
||||
async function createStore(): Promise<Writable<Date> & { next: Function; prev: Function }> {
|
||||
const { subscribe, update, set } = writable(new Date());
|
||||
return {
|
||||
subscribe,
|
||||
update,
|
||||
set,
|
||||
next: () => {
|
||||
update((now: Date) => {
|
||||
now.setMonth(now.getMonth() + 1);
|
||||
return now
|
||||
});
|
||||
},
|
||||
prev: () => {
|
||||
update((now: Date) => {
|
||||
now.setMonth(now.getMonth() - 1);
|
||||
return now
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export const nowStore = await createStore();
|
Reference in New Issue
Block a user