From 8f725a7c64fbeb85ebeb59b54d2f774e9a0a59d6 Mon Sep 17 00:00:00 2001 From: soryu Date: Fri, 6 Feb 2026 01:02:32 +0000 Subject: Fix: Directive page and remove chain page --- makima/frontend/src/hooks/useChains.ts | 145 ----------------------------- makima/frontend/src/hooks/useDirectives.ts | 2 +- 2 files changed, 1 insertion(+), 146 deletions(-) delete mode 100644 makima/frontend/src/hooks/useChains.ts (limited to 'makima/frontend/src/hooks') diff --git a/makima/frontend/src/hooks/useChains.ts b/makima/frontend/src/hooks/useChains.ts deleted file mode 100644 index 272847a..0000000 --- a/makima/frontend/src/hooks/useChains.ts +++ /dev/null @@ -1,145 +0,0 @@ -import { useState, useCallback, useEffect } from "react"; -import { - listChains, - getChain, - createChain, - updateChain, - archiveChain, - getChainGraph, - type ChainSummary, - type ChainWithContracts, - type ChainGraphResponse, - type ChainStatus, - type CreateChainRequest, - type UpdateChainRequest, -} from "../lib/api"; - -interface UseChainsResult { - chains: ChainSummary[]; - loading: boolean; - error: string | null; - refresh: () => Promise; - createNewChain: (req: CreateChainRequest) => Promise; - updateExistingChain: ( - chainId: string, - req: UpdateChainRequest - ) => Promise; - archiveExistingChain: (chainId: string) => Promise; - getChainById: (chainId: string) => Promise; - getGraph: (chainId: string) => Promise; -} - -export function useChains(statusFilter?: ChainStatus): UseChainsResult { - const [chains, setChains] = useState([]); - const [loading, setLoading] = useState(true); - const [error, setError] = useState(null); - - const fetchChains = useCallback(async () => { - setLoading(true); - setError(null); - try { - const response = await listChains(statusFilter); - setChains(response.chains); - } catch (err) { - console.error("Failed to fetch chains:", err); - setError(err instanceof Error ? err.message : "Failed to fetch chains"); - } finally { - setLoading(false); - } - }, [statusFilter]); - - useEffect(() => { - fetchChains(); - }, [fetchChains]); - - const createNewChain = useCallback( - async (req: CreateChainRequest): Promise => { - try { - const chain = await createChain(req); - // Refresh the list - await fetchChains(); - // Return the full chain with contracts - return await getChain(chain.id); - } catch (err) { - console.error("Failed to create chain:", err); - setError(err instanceof Error ? err.message : "Failed to create chain"); - return null; - } - }, - [fetchChains] - ); - - const updateExistingChain = useCallback( - async ( - chainId: string, - req: UpdateChainRequest - ): Promise => { - try { - await updateChain(chainId, req); - // Refresh the list - await fetchChains(); - // Return the updated chain - return await getChain(chainId); - } catch (err) { - console.error("Failed to update chain:", err); - setError(err instanceof Error ? err.message : "Failed to update chain"); - return null; - } - }, - [fetchChains] - ); - - const archiveExistingChain = useCallback( - async (chainId: string): Promise => { - try { - await archiveChain(chainId); - // Refresh the list - await fetchChains(); - return true; - } catch (err) { - console.error("Failed to archive chain:", err); - setError(err instanceof Error ? err.message : "Failed to archive chain"); - return false; - } - }, - [fetchChains] - ); - - const getChainById = useCallback( - async (chainId: string): Promise => { - try { - return await getChain(chainId); - } catch (err) { - console.error("Failed to get chain:", err); - setError(err instanceof Error ? err.message : "Failed to get chain"); - return null; - } - }, - [] - ); - - const getGraph = useCallback( - async (chainId: string): Promise => { - try { - return await getChainGraph(chainId); - } catch (err) { - console.error("Failed to get chain graph:", err); - setError(err instanceof Error ? err.message : "Failed to get chain graph"); - return null; - } - }, - [] - ); - - return { - chains, - loading, - error, - refresh: fetchChains, - createNewChain, - updateExistingChain, - archiveExistingChain, - getChainById, - getGraph, - }; -} diff --git a/makima/frontend/src/hooks/useDirectives.ts b/makima/frontend/src/hooks/useDirectives.ts index 6e1654f..7ae24a5 100644 --- a/makima/frontend/src/hooks/useDirectives.ts +++ b/makima/frontend/src/hooks/useDirectives.ts @@ -50,7 +50,7 @@ export function useDirectives(statusFilter?: DirectiveStatus): UseDirectivesResu setError(null); try { const response = await listDirectives(statusFilter); - setDirectives(response.directives); + setDirectives(response.directives ?? []); } catch (err) { console.error("Failed to fetch directives:", err); setError(err instanceof Error ? err.message : "Failed to fetch directives"); -- cgit v1.2.3