generated from dave/wails-template
Add billsstore
This commit is contained in:
@@ -2,7 +2,11 @@
|
|||||||
import { Toaster } from "svelte-sonner";
|
import { Toaster } from "svelte-sonner";
|
||||||
import Header from "$lib/components/Header.svelte";
|
import Header from "$lib/components/Header.svelte";
|
||||||
import Router from "$lib/router/Router.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'
|
||||||
|
|
||||||
|
console.log($billsStore);
|
||||||
|
|
||||||
function keyDown(event: KeyboardEvent) {
|
function keyDown(event: KeyboardEvent) {
|
||||||
if (event.ctrlKey && event.key == "r") {
|
if (event.ctrlKey && event.key == "r") {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
|
38
frontend/src/lib/store/billsStore.ts
Normal file
38
frontend/src/lib/store/billsStore.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import { type Writable, writable } from "svelte/store";
|
||||||
|
import {GetBills} from '$wails/main/App'
|
||||||
|
import { main } from "$wails/models";
|
||||||
|
import { toast } from "svelte-sonner";
|
||||||
|
|
||||||
|
async function createStore(): Promise<Writable<Map<number, main.Bill>>> {
|
||||||
|
const bills: Map<number, main.Bill> = new Map<number, main.Bill>();
|
||||||
|
const res = await GetBills()
|
||||||
|
if (!res.success) {
|
||||||
|
toast.error("Error getting bills " + res.error);
|
||||||
|
} else {
|
||||||
|
for (let i = 0; i < res.data.length; i++) {
|
||||||
|
const bill = res.data[i];
|
||||||
|
bills.set(bill.id, bill)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const { subscribe, update, set } = writable(bills);
|
||||||
|
return {
|
||||||
|
subscribe,
|
||||||
|
update,
|
||||||
|
set,
|
||||||
|
// @ts-ignore
|
||||||
|
refresh: async () => {
|
||||||
|
const res = await GetBills()
|
||||||
|
if (!res.success) {
|
||||||
|
toast.error("Error getting bills " + res.error);
|
||||||
|
} else {
|
||||||
|
for (let i = 0; i < res.data.length; i++) {
|
||||||
|
const bill = res.data[i];
|
||||||
|
bills.set(bill.id, bill)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const billsStore = await createStore();
|
2
main.go
2
main.go
@@ -61,7 +61,7 @@ func main() {
|
|||||||
|
|
||||||
// Create application with options
|
// Create application with options
|
||||||
err = wails.Run(&options.App{
|
err = wails.Run(&options.App{
|
||||||
Title: "bill-manager-w",
|
Title: "bill-manager",
|
||||||
Width: 1024,
|
Width: 1024,
|
||||||
Height: 768,
|
Height: 768,
|
||||||
AssetServer: &assetserver.Options{
|
AssetServer: &assetserver.Options{
|
||||||
|
Reference in New Issue
Block a user