this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add useProjects hook for fetching and updating projects

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

alice fe94dcab 45ac1e2c

+50
+50
src/web/app/hooks/useProjects.ts
··· 1 + import { useState, useEffect, useCallback } from 'react'; 2 + import type { ProjectStatus, ProjectListItem } from '../../../types'; 3 + 4 + export function useProjects(status?: ProjectStatus) { 5 + const [projects, setProjects] = useState<ProjectListItem[]>([]); 6 + const [loading, setLoading] = useState(true); 7 + const [error, setError] = useState<string | null>(null); 8 + 9 + const fetchProjects = useCallback(async () => { 10 + try { 11 + setLoading(true); 12 + const url = status ? `/api/projects?status=${status}` : '/api/projects'; 13 + const res = await fetch(url); 14 + if (!res.ok) throw new Error('Failed to fetch projects'); 15 + setProjects(await res.json()); 16 + } catch (err) { 17 + setError(err instanceof Error ? err.message : 'Unknown error'); 18 + } finally { 19 + setLoading(false); 20 + } 21 + }, [status]); 22 + 23 + useEffect(() => { 24 + fetchProjects(); 25 + }, [fetchProjects]); 26 + 27 + return { projects, loading, error, refetch: fetchProjects }; 28 + } 29 + 30 + export function useUpdateProjectStatus() { 31 + const [updating, setUpdating] = useState(false); 32 + 33 + const updateStatus = async (projectPath: string, status: ProjectStatus): Promise<boolean> => { 34 + setUpdating(true); 35 + try { 36 + const res = await fetch('/api/projects/status', { 37 + method: 'PATCH', 38 + headers: { 'Content-Type': 'application/json' }, 39 + body: JSON.stringify({ path: projectPath, status }), 40 + }); 41 + return res.ok; 42 + } catch { 43 + return false; 44 + } finally { 45 + setUpdating(false); 46 + } 47 + }; 48 + 49 + return { updateStatus, updating }; 50 + }