fix: adding sorting to download list

This commit is contained in:
Chubby Granny Chaser 2024-06-04 16:59:47 +01:00
parent 73b4b2c13c
commit 588cb983c2
No known key found for this signature in database
2 changed files with 20 additions and 9 deletions

View file

@ -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 (
<>
<p>{formatDownloadProgress(game.progress)}</p>
<p>{t(game.downloadQueue ? "queued" : "paused")}</p>
<p>{t(game.downloadQueue && lastPacket ? "queued" : "paused")}</p>
</>
);
}

View file

@ -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]);