From c90b1949e0c08e4ade04be7cb061e1fb10676a54 Mon Sep 17 00:00:00 2001 From: Alma Date: Sat, 12 Apr 2025 13:49:32 +0200 Subject: [PATCH] working leantime widget 20 --- components/flow.tsx | 70 ++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/components/flow.tsx b/components/flow.tsx index 989d7016..d3dbfe48 100644 --- a/components/flow.tsx +++ b/components/flow.tsx @@ -5,25 +5,29 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { RefreshCw } from "lucide-react"; -interface Task { +interface StatusLabel { id: string; - headline: string; - projectName: string; - status: string; - dueDate: string | null; - details?: string | null; - milestone?: string | null; + name: string; class: string; + statusType: string; + kanbanCol: boolean | string; + sortKey: number | string; +} + +interface Project { + id: number; + name: string; + labels: StatusLabel[]; } export function Flow() { - const [tasks, setTasks] = useState([]); + const [projects, setProjects] = useState([]); const [error, setError] = useState(null); const [loading, setLoading] = useState(true); const [refreshing, setRefreshing] = useState(false); const [retryTimeout, setRetryTimeout] = useState(null); - const fetchTasks = async (isRefresh = false) => { + const fetchStatusLabels = async (isRefresh = false) => { try { if (isRefresh) { setRefreshing(true); @@ -32,22 +36,26 @@ export function Flow() { if (response.status === 429) { const retryAfter = parseInt(response.headers.get('retry-after') || '60'); - const timeout = setTimeout(() => fetchTasks(), retryAfter * 1000); + const timeout = setTimeout(() => fetchStatusLabels(), retryAfter * 1000); setRetryTimeout(timeout); setError(`Rate limit exceeded. Retrying in ${retryAfter} seconds...`); return; } if (!response.ok) { - throw new Error('Failed to fetch tasks'); + throw new Error('Failed to fetch status labels'); } const data = await response.json(); - setTasks(data.tasks || []); + if (data.projects && Array.isArray(data.projects)) { + setProjects(data.projects); + } else { + setProjects([]); + } setError(null); } catch (err) { - console.error('Error fetching tasks:', err); - setError('Failed to fetch tasks'); + console.error('Error fetching status labels:', err); + setError('Failed to fetch status labels'); } finally { setLoading(false); setRefreshing(false); @@ -55,7 +63,7 @@ export function Flow() { }; useEffect(() => { - fetchTasks(); + fetchStatusLabels(); return () => { if (retryTimeout) { clearTimeout(retryTimeout); @@ -63,15 +71,6 @@ export function Flow() { }; }, []); - // Group tasks by project - const groupedTasks = tasks.reduce((acc, task) => { - if (!acc[task.projectName]) { - acc[task.projectName] = []; - } - acc[task.projectName].push(task); - return acc; - }, {} as Record); - return ( @@ -79,7 +78,7 @@ export function Flow() {