fix: adding direct comparison last downloaded option

This commit is contained in:
Chubby Granny Chaser 2024-09-27 03:39:42 +01:00
parent 2aa393967f
commit 43e9919b6b
No known key found for this signature in database

View File

@ -1,6 +1,5 @@
import { useCallback, useContext, useEffect, useMemo, useState } from "react"; import { useContext, useEffect, useMemo, useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import parseTorrent from "parse-torrent";
import { Badge, Button, Modal, TextField } from "@renderer/components"; import { Badge, Button, Modal, TextField } from "@renderer/components";
import type { GameRepack } from "@types"; import type { GameRepack } from "@types";
@ -33,8 +32,6 @@ export function RepacksModal({
const [repack, setRepack] = useState<GameRepack | null>(null); const [repack, setRepack] = useState<GameRepack | null>(null);
const [showSelectFolderModal, setShowSelectFolderModal] = useState(false); const [showSelectFolderModal, setShowSelectFolderModal] = useState(false);
const [infoHash, setInfoHash] = useState<string | null>(null);
const { repacks, game } = useContext(gameDetailsContext); const { repacks, game } = useContext(gameDetailsContext);
const { t } = useTranslation("game_details"); const { t } = useTranslation("game_details");
@ -43,18 +40,9 @@ export function RepacksModal({
return orderBy(repacks, (repack) => repack.uploadDate, "desc"); return orderBy(repacks, (repack) => repack.uploadDate, "desc");
}, [repacks]); }, [repacks]);
const getInfoHash = useCallback(async () => {
if (game?.uri?.startsWith("magnet:")) {
const torrent = await parseTorrent(game?.uri ?? "");
if (torrent.infoHash) setInfoHash(torrent.infoHash);
}
}, [game]);
useEffect(() => { useEffect(() => {
setFilteredRepacks(sortedRepacks); setFilteredRepacks(sortedRepacks);
}, [sortedRepacks, visible, game]);
if (game?.uri) getInfoHash();
}, [sortedRepacks, visible, game, getInfoHash]);
const handleRepackClick = (repack: GameRepack) => { const handleRepackClick = (repack: GameRepack) => {
setRepack(repack); setRepack(repack);
@ -77,9 +65,6 @@ export function RepacksModal({
}; };
const checkIfLastDownloadedOption = (repack: GameRepack) => { const checkIfLastDownloadedOption = (repack: GameRepack) => {
if (infoHash) return repack.uris.some((uri) => uri.includes(infoHash));
if (!game?.uri) return false;
return repack.uris.some((uri) => uri.includes(game?.uri ?? "")); return repack.uris.some((uri) => uri.includes(game?.uri ?? ""));
}; };