mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-23 21:44:55 +03:00
feat: add/remove game from library
This commit is contained in:
parent
c6105bcdfd
commit
3a86e3569a
@ -1,4 +1,4 @@
|
|||||||
import { GearIcon, NoEntryIcon, PlusCircleIcon } from "@primer/octicons-react";
|
import { GearIcon, PlusCircleIcon } from "@primer/octicons-react";
|
||||||
import { Button } from "@renderer/components";
|
import { Button } from "@renderer/components";
|
||||||
import { useAppSelector, useDownload, useLibrary } from "@renderer/hooks";
|
import { useAppSelector, useDownload, useLibrary } from "@renderer/hooks";
|
||||||
import { useContext, useState } from "react";
|
import { useContext, useState } from "react";
|
||||||
@ -12,7 +12,7 @@ export function HeroPanelActions() {
|
|||||||
useState(false);
|
useState(false);
|
||||||
const [showGameOptionsModal, setShowGameOptionsModal] = useState(false);
|
const [showGameOptionsModal, setShowGameOptionsModal] = useState(false);
|
||||||
|
|
||||||
const { removeGameFromLibrary, isGameDeleting } = useDownload();
|
const { isGameDeleting } = useDownload();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
game,
|
game,
|
||||||
@ -60,15 +60,11 @@ export function HeroPanelActions() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const toggleGameOnLibrary = async () => {
|
const addGameToLibrary = async () => {
|
||||||
setToggleLibraryGameDisabled(true);
|
setToggleLibraryGameDisabled(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (game) {
|
|
||||||
await removeGameFromLibrary(game.id);
|
|
||||||
} else {
|
|
||||||
await window.electron.addGameToLibrary(objectID!, gameTitle, "steam");
|
await window.electron.addGameToLibrary(objectID!, gameTitle, "steam");
|
||||||
}
|
|
||||||
|
|
||||||
updateLibrary();
|
updateLibrary();
|
||||||
updateGame();
|
updateGame();
|
||||||
@ -96,15 +92,15 @@ export function HeroPanelActions() {
|
|||||||
|
|
||||||
const deleting = game ? isGameDeleting(game?.id) : false;
|
const deleting = game ? isGameDeleting(game?.id) : false;
|
||||||
|
|
||||||
const toggleGameOnLibraryButton = (
|
const addGameToLibraryButton = (
|
||||||
<Button
|
<Button
|
||||||
theme="outline"
|
theme="outline"
|
||||||
disabled={toggleLibraryGameDisabled}
|
disabled={toggleLibraryGameDisabled}
|
||||||
onClick={toggleGameOnLibrary}
|
onClick={addGameToLibrary}
|
||||||
className={styles.heroPanelAction}
|
className={styles.heroPanelAction}
|
||||||
>
|
>
|
||||||
{game ? <NoEntryIcon /> : <PlusCircleIcon />}
|
<PlusCircleIcon />
|
||||||
{game ? t("remove_from_library") : t("add_to_library")}
|
{t("add_to_library")}
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -119,27 +115,10 @@ export function HeroPanelActions() {
|
|||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
|
|
||||||
if (game?.status === "removed") {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{showDownloadOptionsButton}
|
|
||||||
|
|
||||||
<Button
|
|
||||||
onClick={() => removeGameFromLibrary(game.id).then(updateGame)}
|
|
||||||
theme="outline"
|
|
||||||
disabled={deleting}
|
|
||||||
className={styles.heroPanelAction}
|
|
||||||
>
|
|
||||||
{t("remove_from_list")}
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (repacks.length && !game) {
|
if (repacks.length && !game) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{toggleGameOnLibraryButton}
|
{addGameToLibraryButton}
|
||||||
{showDownloadOptionsButton}
|
{showDownloadOptionsButton}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
@ -169,8 +148,6 @@ export function HeroPanelActions() {
|
|||||||
|
|
||||||
<div className={styles.separator} />
|
<div className={styles.separator} />
|
||||||
|
|
||||||
{game.progress !== 1 && toggleGameOnLibraryButton}
|
|
||||||
|
|
||||||
{isGameRunning ? (
|
{isGameRunning ? (
|
||||||
<Button
|
<Button
|
||||||
onClick={closeGame}
|
onClick={closeGame}
|
||||||
@ -194,5 +171,5 @@ export function HeroPanelActions() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return toggleGameOnLibraryButton;
|
return addGameToLibraryButton;
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,12 @@ export function HeroPanelPlaytime() {
|
|||||||
} else if (game.progress !== 1) {
|
} else if (game.progress !== 1) {
|
||||||
downloadContent = (
|
downloadContent = (
|
||||||
<p className={styles.downloadDetailsRow}>
|
<p className={styles.downloadDetailsRow}>
|
||||||
{isGameDownloading ? progress : formatDownloadProgress(game.progress)}
|
Download em andamento
|
||||||
|
<small>
|
||||||
|
{isGameDownloading
|
||||||
|
? progress
|
||||||
|
: formatDownloadProgress(game.progress)}
|
||||||
|
</small>
|
||||||
</p>
|
</p>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ export const actions = style({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const downloadDetailsRow = style({
|
export const downloadDetailsRow = style({
|
||||||
gap: `${SPACING_UNIT * 2}px`,
|
gap: `${SPACING_UNIT}px`,
|
||||||
display: "flex",
|
display: "flex",
|
||||||
alignItems: "flex-end",
|
alignItems: "flex-end",
|
||||||
});
|
});
|
||||||
|
@ -4,7 +4,7 @@ import { Button, Modal, TextField } from "@renderer/components";
|
|||||||
import type { Game } from "@types";
|
import type { Game } from "@types";
|
||||||
import * as styles from "./game-options-modal.css";
|
import * as styles from "./game-options-modal.css";
|
||||||
import { gameDetailsContext } from "../game-details.context";
|
import { gameDetailsContext } from "../game-details.context";
|
||||||
import { TrashIcon } from "@primer/octicons-react";
|
import { NoEntryIcon, TrashIcon } from "@primer/octicons-react";
|
||||||
import { DeleteGameModal } from "@renderer/pages/downloads/delete-game-modal";
|
import { DeleteGameModal } from "@renderer/pages/downloads/delete-game-modal";
|
||||||
import { useDownload } from "@renderer/hooks";
|
import { useDownload } from "@renderer/hooks";
|
||||||
|
|
||||||
@ -25,12 +25,19 @@ export function GameOptionsModal({
|
|||||||
|
|
||||||
const [showDeleteModal, setShowDeleteModal] = useState(false);
|
const [showDeleteModal, setShowDeleteModal] = useState(false);
|
||||||
|
|
||||||
const { removeGameInstaller, isGameDeleting } = useDownload();
|
const { removeGameInstaller, removeGameFromLibrary, isGameDeleting } =
|
||||||
|
useDownload();
|
||||||
|
|
||||||
const deleting = game ? isGameDeleting(game?.id) : false;
|
const deleting = game ? isGameDeleting(game?.id) : false;
|
||||||
|
|
||||||
const { t } = useTranslation("game_details");
|
const { t } = useTranslation("game_details");
|
||||||
|
|
||||||
|
const handleRemoveGameFromLibrary = async () => {
|
||||||
|
await removeGameFromLibrary(game.id);
|
||||||
|
updateGame();
|
||||||
|
onClose();
|
||||||
|
};
|
||||||
|
|
||||||
const handleChangeExecutableLocation = async () => {
|
const handleChangeExecutableLocation = async () => {
|
||||||
const location = await selectGameExecutable();
|
const location = await selectGameExecutable();
|
||||||
|
|
||||||
@ -133,6 +140,17 @@ export function GameOptionsModal({
|
|||||||
<TrashIcon />
|
<TrashIcon />
|
||||||
Remover arquivos
|
Remover arquivos
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
onClick={handleRemoveGameFromLibrary}
|
||||||
|
style={{ alignSelf: "flex-end" }}
|
||||||
|
theme="outline"
|
||||||
|
disabled={deleting}
|
||||||
|
title={t("create_shortcut")}
|
||||||
|
>
|
||||||
|
<NoEntryIcon />
|
||||||
|
Remover da biblioteca
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
Loading…
Reference in New Issue
Block a user