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
+51
View File
@@ -0,0 +1,51 @@
import type { DbInterface } from "../../../db/types/DbInterface.js";
import type { CreateUser, UpdateUser } from "../../../db/types/User.js";
import { waitForLoadIfLoading } from "../load.js";
import { clearLoading } from "../slices/loading.js";
import { delUser, getUser, setUser } from "../slices/users.js";
import type { Store } from "../store.js";
export async function deleteUserById(
uid: string,
{ store, db }: { store: Store; db: DbInterface }
): Promise<void> {
await Promise.all([
waitForLoadIfLoading(store, "loadAllUsers"),
waitForLoadIfLoading(store, `loadUserById:${uid}`),
]);
const user = getUser(store.getState(), uid);
await db.deleteUserById(uid);
store.dispatch(delUser(uid));
store.dispatch(clearLoading(`loadUserById:${uid}`));
if (user && "email" in user)
store.dispatch(clearLoading(`loadUserByEmail:${user.email}`));
}
export async function updateUser(
user: UpdateUser,
{ store, db }: { store: Store; db: DbInterface }
): Promise<void> {
await Promise.all([
waitForLoadIfLoading(store, "loadAllUsers"),
waitForLoadIfLoading(store, `loadUserById:${user.uid}`),
]);
const current = getUser(store.getState(), user.uid);
const next = await db.updateUser(user);
store.dispatch(setUser(next));
store.dispatch(clearLoading(`loadUserById:${user.uid}`));
if (current && "email" in current)
store.dispatch(clearLoading(`loadUserByEmail:${current.email}`));
}
export async function createUser(
user: CreateUser,
{ store, db }: { store: Store; db: DbInterface }
): Promise<string> {
await waitForLoadIfLoading(store, "loadAllUsers");
const next = await db.createUser(user);
store.dispatch(setUser(next));
return next.uid;
}