mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 00:33:49 +03:00
fix: sorting repacks modal
This commit is contained in:
parent
7a13739d49
commit
dc94a886e6
@ -27,7 +27,6 @@ export const createDataSource = (
|
|||||||
DownloadQueue,
|
DownloadQueue,
|
||||||
UserAuth,
|
UserAuth,
|
||||||
],
|
],
|
||||||
synchronize: true,
|
|
||||||
database: databasePath,
|
database: databasePath,
|
||||||
...options,
|
...options,
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useCallback, useContext, useEffect, useState } from "react";
|
import { useCallback, useContext, useEffect, useMemo, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import parseTorrent from "parse-torrent";
|
import parseTorrent from "parse-torrent";
|
||||||
|
|
||||||
@ -12,6 +12,7 @@ import { format } from "date-fns";
|
|||||||
import { DownloadSettingsModal } from "./download-settings-modal";
|
import { DownloadSettingsModal } from "./download-settings-modal";
|
||||||
import { gameDetailsContext } from "@renderer/context";
|
import { gameDetailsContext } from "@renderer/context";
|
||||||
import { Downloader } from "@shared";
|
import { Downloader } from "@shared";
|
||||||
|
import { orderBy } from "lodash-es";
|
||||||
|
|
||||||
export interface RepacksModalProps {
|
export interface RepacksModalProps {
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
@ -38,16 +39,20 @@ export function RepacksModal({
|
|||||||
|
|
||||||
const { t } = useTranslation("game_details");
|
const { t } = useTranslation("game_details");
|
||||||
|
|
||||||
|
const sortedRepacks = useMemo(() => {
|
||||||
|
return orderBy(repacks, (repack) => repack.uploadDate, "desc");
|
||||||
|
}, [repacks]);
|
||||||
|
|
||||||
const getInfoHash = useCallback(async () => {
|
const getInfoHash = useCallback(async () => {
|
||||||
const torrent = await parseTorrent(game?.uri ?? "");
|
const torrent = await parseTorrent(game?.uri ?? "");
|
||||||
if (torrent.infoHash) setInfoHash(torrent.infoHash);
|
if (torrent.infoHash) setInfoHash(torrent.infoHash);
|
||||||
}, [game]);
|
}, [game]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setFilteredRepacks(repacks);
|
setFilteredRepacks(sortedRepacks);
|
||||||
|
|
||||||
if (game?.uri) getInfoHash();
|
if (game?.uri) getInfoHash();
|
||||||
}, [repacks, visible, game, getInfoHash]);
|
}, [sortedRepacks, visible, game, getInfoHash]);
|
||||||
|
|
||||||
const handleRepackClick = (repack: GameRepack) => {
|
const handleRepackClick = (repack: GameRepack) => {
|
||||||
setRepack(repack);
|
setRepack(repack);
|
||||||
@ -58,7 +63,7 @@ export function RepacksModal({
|
|||||||
const term = event.target.value.toLocaleLowerCase();
|
const term = event.target.value.toLocaleLowerCase();
|
||||||
|
|
||||||
setFilteredRepacks(
|
setFilteredRepacks(
|
||||||
repacks.filter((repack) => {
|
sortedRepacks.filter((repack) => {
|
||||||
const lowerCaseTitle = repack.title.toLowerCase();
|
const lowerCaseTitle = repack.title.toLowerCase();
|
||||||
const lowerCaseRepacker = repack.repacker.toLowerCase();
|
const lowerCaseRepacker = repack.repacker.toLowerCase();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user