working leantime widget 55

This commit is contained in:
Alma 2025-04-12 15:29:51 +02:00
parent 1a41f773eb
commit ec1d413d9c

View File

@ -19,6 +19,10 @@ interface Task {
authorFirstname?: string;
authorLastname?: string;
tags?: string;
description?: string;
milestone?: string;
details?: string;
milestoneHeadline?: string;
}
interface ProjectSummary {
@ -67,13 +71,28 @@ export function Flow() {
const getDateToSort = (task: Task): number => {
// Try different date fields in order of preference
const dates = [
task.date,
task.dateToFinish,
task.editFrom,
task.editTo
task.date,
task.editTo,
task.editFrom
].filter(date => date && date !== '0000-00-00 00:00:00');
return dates.length > 0 ? new Date(dates[0]).getTime() : 0;
return dates.length > 0 ? new Date(dates[0]).getTime() : Number.MAX_SAFE_INTEGER;
};
const formatDate = (dateStr: string): string => {
if (!dateStr || dateStr === '0000-00-00 00:00:00') return '';
try {
const date = new Date(dateStr);
if (isNaN(date.getTime())) return '';
return date.toLocaleDateString('fr-FR', {
day: '2-digit',
month: '2-digit',
year: 'numeric'
});
} catch {
return '';
}
};
const fetchTasks = async (isRefresh = false) => {
@ -90,9 +109,9 @@ export function Flow() {
}
// Sort tasks by date (oldest first)
const sortedTasks = data.tasks.sort((a: Task, b: Task) => {
return getDateToSort(a) - getDateToSort(b);
});
const sortedTasks = data.tasks
.filter((task: Task) => task.headline && typeof task.headline === 'string')
.sort((a: Task, b: Task) => getDateToSort(a) - getDateToSort(b));
// Limit to 6 tasks
setTasks(sortedTasks.slice(0, 6));
@ -146,13 +165,25 @@ export function Flow() {
{getStatusLabel(task.status)}
</span>
</div>
<div className="flex items-center justify-between mt-1">
<p className="text-xs text-gray-500 truncate">
{task.projectName}
</p>
{task.tags && (
<p className="text-xs text-blue-500 truncate">
{task.tags}
<div className="flex flex-col gap-1 mt-1">
<div className="flex items-center justify-between">
<p className="text-xs text-gray-500 truncate">
{task.projectName}
</p>
{task.tags && (
<p className="text-xs text-blue-500 truncate">
{task.tags}
</p>
)}
</div>
{task.dateToFinish && task.dateToFinish !== '0000-00-00 00:00:00' && (
<p className="text-xs text-gray-400">
Due: {formatDate(task.dateToFinish)}
</p>
)}
{task.milestoneHeadline && (
<p className="text-xs text-purple-500 truncate">
{task.milestoneHeadline}
</p>
)}
</div>