feat: add modal to confirm remove from library

This commit is contained in:
Zamitto 2024-06-07 14:23:34 -03:00
parent ceb8f164b7
commit 8669c1d660
5 changed files with 70 additions and 3 deletions

View File

@ -106,7 +106,9 @@
"open_folder": "Open folder", "open_folder": "Open folder",
"open_download_location": "Abrir local de download", "open_download_location": "Abrir local de download",
"create_shortcut": "Create shortcut", "create_shortcut": "Create shortcut",
"remove_files": "Remove files" "remove_files": "Remove files",
"remove_from_library_title": "Are you sure?",
"remove_from_library_description": "This will remove {{game}} from your library"
}, },
"activation": { "activation": {
"title": "Activate Hydra", "title": "Activate Hydra",

View File

@ -103,7 +103,9 @@
"open_folder": "Abrir pasta", "open_folder": "Abrir pasta",
"open_download_location": "Abrir local de download", "open_download_location": "Abrir local de download",
"create_shortcut": "Criar atalho", "create_shortcut": "Criar atalho",
"remove_files": "Remover arquivos" "remove_files": "Remover arquivos",
"remove_from_library_description": "Tem certeza que deseja remover {{game}} da sua biblioteca?",
"remove_from_library_title": "Tem certeza?"
}, },
"activation": { "activation": {
"title": "Ativação", "title": "Ativação",

View File

@ -7,6 +7,7 @@ import { gameDetailsContext } from "../game-details.context";
import { NoEntryIcon, 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";
import { RemoveGameFromLibraryModal } from "./remove-from-library-modal";
export interface GameOptionsModalProps { export interface GameOptionsModalProps {
visible: boolean; visible: boolean;
@ -26,6 +27,7 @@ export function GameOptionsModal({
const { updateGame, openRepacksModal } = useContext(gameDetailsContext); const { updateGame, openRepacksModal } = useContext(gameDetailsContext);
const [showDeleteModal, setShowDeleteModal] = useState(false); const [showDeleteModal, setShowDeleteModal] = useState(false);
const [showRemoveGameModal, setShowRemoveGameModal] = useState(false);
const { removeGameInstaller, removeGameFromLibrary, isGameDeleting } = const { removeGameInstaller, removeGameFromLibrary, isGameDeleting } =
useDownload(); useDownload();
@ -83,6 +85,13 @@ export function GameOptionsModal({
deleteGame={handleDeleteGame} deleteGame={handleDeleteGame}
/> />
<RemoveGameFromLibraryModal
visible={showRemoveGameModal}
onClose={() => setShowRemoveGameModal(false)}
removeGameFromLibrary={handleRemoveGameFromLibrary}
game={game}
/>
<div className={styles.optionsContainer}> <div className={styles.optionsContainer}>
<div className={styles.gameOptionRow}> <div className={styles.gameOptionRow}>
<Button <Button
@ -150,7 +159,7 @@ export function GameOptionsModal({
</Button> </Button>
<Button <Button
onClick={handleRemoveGameFromLibrary} onClick={() => setShowRemoveGameModal(true)}
style={{ alignSelf: "flex-end" }} style={{ alignSelf: "flex-end" }}
theme="outline" theme="outline"
disabled={deleting} disabled={deleting}

View File

@ -0,0 +1,10 @@
import { SPACING_UNIT } from "../../../theme.css";
import { style } from "@vanilla-extract/css";
export const deleteActionsButtonsCtn = style({
display: "flex",
width: "100%",
justifyContent: "end",
alignItems: "center",
gap: `${SPACING_UNIT}px`,
});

View File

@ -0,0 +1,44 @@
import { useTranslation } from "react-i18next";
import { Button, Modal } from "@renderer/components";
import * as styles from "./remove-from-library-modal.css";
import { Game } from "@types";
interface RemoveGameFromLibraryModalProps {
visible: boolean;
game: Game;
onClose: () => void;
removeGameFromLibrary: () => Promise<void>;
}
export function RemoveGameFromLibraryModal({
onClose,
game,
visible,
removeGameFromLibrary,
}: RemoveGameFromLibraryModalProps) {
const { t } = useTranslation("game_details");
const handleRemoveGame = async () => {
await removeGameFromLibrary();
onClose();
};
return (
<Modal
visible={visible}
title={t("remove_from_library_title")}
description={t("remove_from_library_description", { game: game.title })}
onClose={onClose}
>
<div className={styles.deleteActionsButtonsCtn}>
<Button onClick={handleRemoveGame} theme="outline">
{t("remove")}
</Button>
<Button onClick={onClose} theme="primary">
{t("cancel")}
</Button>
</div>
</Modal>
);
}