style(biome): using biome for format, lint, check

This commit is contained in:
2025-11-08 12:58:40 +02:00
parent 075a388ccb
commit fdd1cbbfd5
152 changed files with 3737 additions and 3989 deletions
@@ -1,26 +1,26 @@
import { useMemo } from "react";
interface Page<T> {
items: T[];
items: T[];
}
interface PaginatedResult<T> {
pages?: Page<T>[];
items?: T[];
pages?: Page<T>[];
items?: T[];
}
export const useFlattenedItems = <T>(data: PaginatedResult<T> | undefined | null): T[] => {
return useMemo((): T[] => {
if (!data) {
return [];
}
return useMemo((): T[] => {
if (!data) {
return [];
}
if (data.pages && Array.isArray(data.pages) && data.pages.length > 0) {
return data.pages.flatMap(page => page.items || []);
} else if (data.items && Array.isArray(data.items)) {
return data.items;
} else {
return [];
}
}, [data]);
if (data.pages && Array.isArray(data.pages) && data.pages.length > 0) {
return data.pages.flatMap((page) => page.items || []);
} else if (data.items && Array.isArray(data.items)) {
return data.items;
} else {
return [];
}
}, [data]);
};
@@ -1,61 +1,60 @@
import { useEffect, useState } from "react";
import { formatDistanceToNowStrict, Locale } from "date-fns";
import { fr } from "date-fns/locale";
import { useEffect, useState } from "react";
export const useRelativeTime = (
dateInput: string | Date | number | null | undefined,
options?: {
addSuffix?: boolean;
unit?: "second" | "minute" | "hour" | "day" | "month" | "year";
locale?: Locale;
roundingMethod?: "floor" | "ceil" | "round";
includeSeconds?: boolean;
},
updateInterval: number = 60000
dateInput: string | Date | number | null | undefined,
options?: {
addSuffix?: boolean;
unit?: "second" | "minute" | "hour" | "day" | "month" | "year";
locale?: Locale;
roundingMethod?: "floor" | "ceil" | "round";
includeSeconds?: boolean;
},
updateInterval: number = 60000,
): string => {
const [relativeTime, setRelativeTime] = useState("");
const [relativeTime, setRelativeTime] = useState("");
useEffect(() => {
if (dateInput === null || dateInput === undefined) {
setRelativeTime("");
return;
}
useEffect(() => {
if (dateInput === null || dateInput === undefined) {
setRelativeTime("");
return;
}
const date = new Date(dateInput);
const date = new Date(dateInput);
// Check if the date is valid
if (isNaN(date.getTime())) {
setRelativeTime("Invalid Date");
return;
}
// Check if the date is valid
if (Number.isNaN(date.getTime())) {
setRelativeTime("Invalid Date");
return;
}
const updateTime = () => {
// Default options if none provided, ensures suffix is added
const effectiveOptions = {
locale: fr,
addSuffix: true,
...options,
};
const updateTime = () => {
// Default options if none provided, ensures suffix is added
const effectiveOptions = {
addSuffix: true,
locale: fr,
...options,
};
try {
const formattedTime = formatDistanceToNowStrict(date, effectiveOptions);
setRelativeTime(formattedTime);
} catch (error) {
console.error("Error formatting relative time:", error);
setRelativeTime(dateInput.toString()); // Handle potential errors during formatting
}
};
try {
const formattedTime = formatDistanceToNowStrict(date, effectiveOptions);
setRelativeTime(formattedTime);
} catch (error) {
console.error("Error formatting relative time:", error);
setRelativeTime(dateInput.toString()); // Handle potential errors during formatting
}
};
// Initial update
updateTime();
// Initial update
updateTime();
// Set up interval for periodic updates
const intervalId = setInterval(updateTime, updateInterval);
// Set up interval for periodic updates
const intervalId = setInterval(updateTime, updateInterval);
// Clean up the interval when the component unmounts or dateInput changes
return () => clearInterval(intervalId);
}, [dateInput, options, updateInterval]);
// Clean up the interval when the component unmounts or dateInput changes
return () => clearInterval(intervalId);
}, [dateInput, options, updateInterval]);
return relativeTime;
return relativeTime;
};