working leantime widget 81

This commit is contained in:
Alma 2025-04-12 20:26:18 +02:00
parent fa733f952c
commit 767a0d56c7

View File

@ -18,12 +18,9 @@ interface Task {
date?: string;
}
interface ProjectSummary {
name: string;
tasks: {
status: number;
count: number;
}[];
interface ApiResponse {
jsonrpc: string;
result: Task[];
}
export function Flow() {
@ -75,16 +72,19 @@ export function Flow() {
if (!response.ok) {
throw new Error('Failed to fetch tasks');
}
const data = await response.json();
const data: ApiResponse = await response.json();
if (!Array.isArray(data)) {
console.warn('No tasks found in response', data as unknown);
// Extract tasks from the result property
const tasksList = data.result || [];
if (!Array.isArray(tasksList)) {
console.warn('No tasks found in response', tasksList);
setTasks([]);
return;
}
// Sort tasks by date and limit to 4
const sortedTasks = data
const sortedTasks = tasksList
.sort((a: Task, b: Task) => {
const dateA = a.dateToFinish ? new Date(a.dateToFinish).getTime() :
a.date ? new Date(a.date).getTime() : Date.now();