1
0
mirror of https://github.com/community-scripts/ProxmoxVE.git synced 2025-02-01 17:51:49 +00:00

Filter out duplicate scripts in LatestScripts component and sort by creation date (#1828)

This commit is contained in:
Bram Suurd 2025-01-28 19:33:22 +01:00 committed by GitHub
parent 63061942b9
commit 1f39208c1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -35,8 +35,18 @@ export function LatestScripts({ items }: { items: Category[] }) {
const latestScripts = useMemo(() => {
if (!items) return [];
const scripts = items.flatMap((category) => category.scripts || []);
return scripts.sort(
// Filter out duplicates by slug
const uniqueScriptsMap = new Map<string, Script>();
scripts.forEach((script) => {
if (!uniqueScriptsMap.has(script.slug)) {
uniqueScriptsMap.set(script.slug, script);
}
});
return Array.from(uniqueScriptsMap.values()).sort(
(a, b) =>
new Date(b.date_created).getTime() - new Date(a.date_created).getTime(),
);
@ -49,7 +59,7 @@ export function LatestScripts({ items }: { items: Category[] }) {
const goToPreviousPage = () => {
setPage((prevPage) => prevPage - 1);
};
const startIndex = (page - 1) * ITEMS_PER_PAGE;
const endIndex = page * ITEMS_PER_PAGE;