From 588cb983c2d8a9d3fb08778c9776955e296acb45 Mon Sep 17 00:00:00 2001 From: Chubby Granny Chaser Date: Tue, 4 Jun 2024 16:59:47 +0100 Subject: [PATCH] fix: adding sorting to download list --- .../src/pages/downloads/download-list.tsx | 10 ++++++---- .../src/pages/downloads/downloads.tsx | 19 ++++++++++++++----- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/renderer/src/pages/downloads/download-list.tsx b/src/renderer/src/pages/downloads/download-list.tsx index 8619f340..546827b1 100644 --- a/src/renderer/src/pages/downloads/download-list.tsx +++ b/src/renderer/src/pages/downloads/download-list.tsx @@ -11,7 +11,7 @@ import { import { Downloader, formatBytes } from "@shared"; import { DOWNLOADER_NAME } from "@renderer/constants"; -import { useAppSelector, useDownload } from "@renderer/hooks"; +import { useAppSelector, useDownload, useLibrary } from "@renderer/hooks"; import * as styles from "./download-list.css"; import { useTranslation } from "react-i18next"; @@ -25,6 +25,8 @@ export function DownloadList({ library }: DownloadListProps) { const { t } = useTranslation("downloads"); + const { updateLibrary } = useLibrary(); + const userPreferences = useAppSelector( (state) => state.userPreferences.value ); @@ -42,8 +44,8 @@ export function DownloadList({ library }: DownloadListProps) { const openGameInstaller = (gameId: number) => window.electron.openGameInstaller(gameId).then((isBinaryInPath) => { - // if (!isBinaryInPath) setShowBinaryNotFoundModal(true); - // updateLibrary(); + if (!isBinaryInPath) setShowBinaryNotFoundModal(true); + updateLibrary(); }); const getFinalDownloadSize = (game: LibraryGame) => { @@ -92,7 +94,7 @@ export function DownloadList({ library }: DownloadListProps) { return ( <>

{formatDownloadProgress(game.progress)}

-

{t(game.downloadQueue ? "queued" : "paused")}

+

{t(game.downloadQueue && lastPacket ? "queued" : "paused")}

); } diff --git a/src/renderer/src/pages/downloads/downloads.tsx b/src/renderer/src/pages/downloads/downloads.tsx index db62107c..3fefb226 100644 --- a/src/renderer/src/pages/downloads/downloads.tsx +++ b/src/renderer/src/pages/downloads/downloads.tsx @@ -11,7 +11,7 @@ import { LibraryGame } from "@types"; import { orderBy } from "lodash-es"; export function Downloads() { - const { library, updateLibrary } = useLibrary(); + const { library } = useLibrary(); const { t } = useTranslation("downloads"); @@ -41,18 +41,27 @@ export function Downloads() { return { ...prev, downloading: [...prev.downloading, next] }; } - if (next.downloadQueue) { + if (next.downloadQueue || next.status === "paused") { return { ...prev, queued: [...prev.queued, next] }; } return { ...prev, complete: [...prev.complete, next] }; }, initialValue); + const queued = orderBy( + result.queued, + (game) => game.downloadQueue?.id ?? -1, + ["desc"] + ); + + const complete = orderBy(result.complete, (game) => + game.status === "complete" ? 0 : 1 + ); + return { ...result, - queued: orderBy(result.queued, (game) => game.downloadQueue?.id, [ - "desc", - ]), + queued, + complete, }; }, [library, lastPacket?.game.id]);