Skip to content

Commit 1f39208

Browse files
authored
Filter out duplicate scripts in LatestScripts component and sort by creation date (#1828)
1 parent 6306194 commit 1f39208

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

frontend/src/app/scripts/_components/ScriptInfoBlocks.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,18 @@ export function LatestScripts({ items }: { items: Category[] }) {
3535

3636
const latestScripts = useMemo(() => {
3737
if (!items) return [];
38+
3839
const scripts = items.flatMap((category) => category.scripts || []);
39-
return scripts.sort(
40+
41+
// Filter out duplicates by slug
42+
const uniqueScriptsMap = new Map<string, Script>();
43+
scripts.forEach((script) => {
44+
if (!uniqueScriptsMap.has(script.slug)) {
45+
uniqueScriptsMap.set(script.slug, script);
46+
}
47+
});
48+
49+
return Array.from(uniqueScriptsMap.values()).sort(
4050
(a, b) =>
4151
new Date(b.date_created).getTime() - new Date(a.date_created).getTime(),
4252
);
@@ -49,7 +59,7 @@ export function LatestScripts({ items }: { items: Category[] }) {
4959
const goToPreviousPage = () => {
5060
setPage((prevPage) => prevPage - 1);
5161
};
52-
62+
5363
const startIndex = (page - 1) * ITEMS_PER_PAGE;
5464
const endIndex = page * ITEMS_PER_PAGE;
5565

0 commit comments

Comments
 (0)