Initial open-source release
This commit is contained in:
33
src/hooks/useLoadApps.ts
Normal file
33
src/hooks/useLoadApps.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
import { useAtom } from "jotai";
|
||||
import { appBasePathAtom, appsListAtom } from "@/atoms/appAtoms";
|
||||
import { IpcClient } from "@/ipc/ipc_client";
|
||||
|
||||
export function useLoadApps() {
|
||||
const [apps, setApps] = useAtom(appsListAtom);
|
||||
const [appBasePath, setAppBasePath] = useAtom(appBasePathAtom);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<Error | null>(null);
|
||||
|
||||
const refreshApps = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const ipcClient = IpcClient.getInstance();
|
||||
const appListResponse = await ipcClient.listApps();
|
||||
setApps(appListResponse.apps);
|
||||
setAppBasePath(appListResponse.appBasePath);
|
||||
setError(null);
|
||||
} catch (error) {
|
||||
console.error("Error refreshing apps:", error);
|
||||
setError(error instanceof Error ? error : new Error(String(error)));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [setApps, setError, setLoading]);
|
||||
|
||||
useEffect(() => {
|
||||
refreshApps();
|
||||
}, [refreshApps]);
|
||||
|
||||
return { apps, loading, error, refreshApps };
|
||||
}
|
||||
Reference in New Issue
Block a user