diff --git a/src/tribler/ui/src/lib/utils.ts b/src/tribler/ui/src/lib/utils.ts index 1d0a0cc0ac..bc00e0bdc7 100644 --- a/src/tribler/ui/src/lib/utils.ts +++ b/src/tribler/ui/src/lib/utils.ts @@ -1,6 +1,6 @@ import { type ClassValue, clsx } from "clsx" import { twMerge } from "tailwind-merge" -import { Torrent, category } from "@/models/torrent.model"; +import { category } from "@/models/torrent.model"; import TimeAgo from 'javascript-time-ago' import en from 'javascript-time-ago/locale/en' import es from 'javascript-time-ago/locale/es' @@ -8,7 +8,6 @@ import pt from 'javascript-time-ago/locale/pt' import ru from 'javascript-time-ago/locale/ru' import zh from 'javascript-time-ago/locale/zh' import Cookies from "js-cookie"; -import { useEffect, useRef } from "react"; import { useTranslation } from "react-i18next"; TimeAgo.setDefaultLocale(en.locale) @@ -143,3 +142,12 @@ export function translateHeader(name: string) { return t(name); } } + +export function filterDuplicates(data: any[], key: string) { + const seen = new Set(); + return data.filter(item => { + const duplicate = seen.has(item[key]); + seen.add(item[key]); + return !duplicate; + }); +} diff --git a/src/tribler/ui/src/pages/Popular/index.tsx b/src/tribler/ui/src/pages/Popular/index.tsx index ffa5af1028..c0430c2d5d 100644 --- a/src/tribler/ui/src/pages/Popular/index.tsx +++ b/src/tribler/ui/src/pages/Popular/index.tsx @@ -4,7 +4,7 @@ import { useState } from "react"; import { triblerService } from "@/services/tribler.service"; import { Torrent } from "@/models/torrent.model"; import { ColumnDef } from "@tanstack/react-table"; -import { categoryIcon, formatBytes, formatTimeAgo, getMagnetLink, translateHeader } from "@/lib/utils"; +import { categoryIcon, filterDuplicates, formatBytes, formatTimeAgo, getMagnetLink, translateHeader } from "@/lib/utils"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; import { useInterval } from '@/hooks/useInterval'; @@ -55,7 +55,8 @@ export default function Popular() { const [torrentDoubleClicked, setTorrentDoubleClicked] = useState(); useInterval(async () => { - setTorrents((await triblerService.getPopularTorrents(true))); + const popular = await triblerService.getPopularTorrents(true); + setTorrents(filterDuplicates(popular, 'infohash')); }, 5000, true); const OnDoubleClick = (torrent: Torrent) => {