feat: initial commit

This commit is contained in:
2026-06-29 23:07:14 +00:00
commit 3b9a6bc85c
152 changed files with 12558 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
import type { CreateAbode, UpdateAbode } from "../../../db/types/Abode.js";
import type { DbInterface } from "../../../db/types/DbInterface.js";
import { waitForLoadIfLoading } from "../load.js";
import { delAbode, getAbode, setAbode } from "../slices/abodes.js";
import { clearLoading } from "../slices/loading.js";
import { getLoginUser } from "../slices/login.js";
import type { Store } from "../store.js";
export async function deleteAbodeById(
aid: string,
{ store, db }: { store: Store; db: DbInterface }
): Promise<void> {
await Promise.all([
waitForLoadIfLoading(store, "loadAllAbodes"),
waitForLoadIfLoading(store, `loadAbodeById:${aid}`),
]);
await db.deleteAbodeById(aid);
store.dispatch(delAbode(aid));
store.dispatch(clearLoading(`loadAbodeById:${aid}`));
}
export async function updateAbode(
abode: UpdateAbode,
{ store, db }: { store: Store; db: DbInterface }
): Promise<void> {
await Promise.all([
waitForLoadIfLoading(store, "loadAllAbodes"),
waitForLoadIfLoading(store, `loadAbodeById:${abode.aid}`),
]);
const user = getLoginUser(store.getState());
if (!user) throw new Error("Not logged in");
const next = await db.updateAbode(abode, { uid: user.uid });
store.dispatch(setAbode(next));
store.dispatch(clearLoading(`loadAbodeById:${abode.aid}`));
}
export async function createAbode(
abode: CreateAbode,
{ store, db }: { store: Store; db: DbInterface }
): Promise<string> {
await waitForLoadIfLoading(store, "loadAllAbodes");
const user = getLoginUser(store.getState());
if (!user) throw new Error("Not logged in");
const next = await db.createAbode(abode, { uid: user.uid });
store.dispatch(setAbode(next));
return next.aid;
}