Initial open-source release

This commit is contained in:
Will Chen
2025-04-11 09:37:05 -07:00
commit 43f67e0739
208 changed files with 45476 additions and 0 deletions

61
src/hooks/useLoadApp.ts Normal file
View File

@@ -0,0 +1,61 @@
import { useState, useEffect } from "react";
import { IpcClient } from "@/ipc/ipc_client";
import type { App } from "@/ipc/ipc_types";
import { atom, useAtom } from "jotai";
import { currentAppAtom } from "@/atoms/appAtoms";
export function useLoadApp(appId: number | null) {
const [app, setApp] = useAtom(currentAppAtom);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<Error | null>(null);
useEffect(() => {
const loadApp = async () => {
if (appId === null) {
setApp(null);
setLoading(false);
return;
}
setLoading(true);
try {
const ipcClient = IpcClient.getInstance();
const appData = await ipcClient.getApp(appId);
setApp(appData);
setError(null);
} catch (error) {
console.error(`Error loading app ${appId}:`, error);
setError(error instanceof Error ? error : new Error(String(error)));
setApp(null);
} finally {
setLoading(false);
}
};
loadApp();
}, [appId]);
const refreshApp = async () => {
if (appId === null) {
return;
}
setLoading(true);
try {
console.log("Refreshing app", appId);
const ipcClient = IpcClient.getInstance();
const appData = await ipcClient.getApp(appId);
console.log("App data", appData);
setApp(appData);
setError(null);
} catch (error) {
console.error(`Error refreshing app ${appId}:`, error);
setError(error instanceof Error ? error : new Error(String(error)));
} finally {
setLoading(false);
}
};
return { app, loading, error, refreshApp };
}