Skip to content

Commit

Permalink
Merge pull request #100 from egbertbouman/fix_duplicates
Browse files Browse the repository at this point in the history
Remove duplicate entries from the popular page
  • Loading branch information
egbertbouman authored Jul 30, 2024
2 parents 10a023b + a1f2dcd commit 97d8a7e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/tribler/ui/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
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'
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)
Expand Down Expand Up @@ -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;
});
}
5 changes: 3 additions & 2 deletions src/tribler/ui/src/pages/Popular/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -55,7 +55,8 @@ export default function Popular() {
const [torrentDoubleClicked, setTorrentDoubleClicked] = useState<Torrent | undefined>();

useInterval(async () => {
setTorrents((await triblerService.getPopularTorrents(true)));
const popular = await triblerService.getPopularTorrents(true);
setTorrents(filterDuplicates(popular, 'infohash'));
}, 5000, true);

const OnDoubleClick = (torrent: Torrent) => {
Expand Down

0 comments on commit 97d8a7e

Please sign in to comment.