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