show toast if game has no executable selected

This commit is contained in:
Zamitto 2024-06-05 22:43:03 -03:00
parent 58dff75f64
commit 4f4ada8d54
9 changed files with 40 additions and 26 deletions

View file

@ -5,7 +5,7 @@ import { useLocation, useNavigate } from "react-router-dom";
import type { LibraryGame } from "@types"; import type { LibraryGame } from "@types";
import { TextField } from "@renderer/components"; import { TextField } from "@renderer/components";
import { useDownload, useLibrary } from "@renderer/hooks"; import { useDownload, useLibrary, useToast } from "@renderer/hooks";
import { routes } from "./routes"; import { routes } from "./routes";
@ -36,6 +36,8 @@ export function Sidebar() {
const { lastPacket, progress } = useDownload(); const { lastPacket, progress } = useDownload();
const { showWarningToast } = useToast();
useEffect(() => { useEffect(() => {
updateLibrary(); updateLibrary();
}, [lastPacket?.game.id, updateLibrary]); }, [lastPacket?.game.id, updateLibrary]);
@ -131,8 +133,12 @@ export function Sidebar() {
navigate(path); navigate(path);
} }
if (event.detail == 2 && game.executablePath) { if (event.detail == 2) {
window.electron.openGame(game.id, game.executablePath); if (game.executablePath) {
window.electron.openGame(game.id, game.executablePath);
} else {
showWarningToast("Jogo não possui executável selecionado");
}
} }
}; };

View file

@ -81,3 +81,7 @@ export const successIcon = style({
export const errorIcon = style({ export const errorIcon = style({
color: vars.color.danger, color: vars.color.danger,
}); });
export const warningIcon = style({
color: vars.color.warning,
});

View file

@ -1,5 +1,6 @@
import { useCallback, useEffect, useRef, useState } from "react"; import { useCallback, useEffect, useRef, useState } from "react";
import { import {
AlertIcon,
CheckCircleFillIcon, CheckCircleFillIcon,
XCircleFillIcon, XCircleFillIcon,
XIcon, XIcon,
@ -11,7 +12,7 @@ import { SPACING_UNIT } from "@renderer/theme.css";
export interface ToastProps { export interface ToastProps {
visible: boolean; visible: boolean;
message: string; message: string;
type: "success" | "error"; type: "success" | "error" | "warning";
onClose: () => void; onClose: () => void;
} }
@ -84,6 +85,8 @@ export function Toast({ visible, message, type, onClose }: ToastProps) {
)} )}
{type === "error" && <XCircleFillIcon className={styles.errorIcon} />} {type === "error" && <XCircleFillIcon className={styles.errorIcon} />}
{type === "warning" && <AlertIcon className={styles.warningIcon} />}
<span style={{ fontWeight: "bold" }}>{message}</span> <span style={{ fontWeight: "bold" }}>{message}</span>
</div> </div>

View file

@ -29,5 +29,17 @@ export function useToast() {
[dispatch] [dispatch]
); );
return { showSuccessToast, showErrorToast }; const showWarningToast = useCallback(
(message: string) => {
dispatch(
showToast({
message,
type: "warning",
})
);
},
[dispatch]
);
return { showSuccessToast, showErrorToast, showWarningToast };
} }

View file

@ -8,6 +8,6 @@ export const heroPanelAction = style({
export const separator = style({ export const separator = style({
width: "1px", width: "1px",
backgroundColor: vars.color.border, backgroundColor: vars.color.muted,
margin: `${SPACING_UNIT / 2}px 0`, margin: `${SPACING_UNIT / 2}px 0`,
}); });

View file

@ -35,8 +35,9 @@ export function HeroPanel() {
const getInfo = () => { const getInfo = () => {
if (isGameDeleting(game?.id ?? -1)) return <p>{t("deleting")}</p>; if (isGameDeleting(game?.id ?? -1)) return <p>{t("deleting")}</p>;
if (game && (game.progress === 1 || !game.status)) if (game && (game.progress === 1 || !game.status)) {
return <HeroPanelPlaytime />; return <HeroPanelPlaytime />;
}
if (game?.status === "active") { if (game?.status === "active") {
if (lastPacket?.isDownloadingMetadata && isGameDownloading) { if (lastPacket?.isDownloadingMetadata && isGameDownloading) {

View file

@ -3,11 +3,11 @@ import { SPACING_UNIT } from "../../../theme.css";
export const optionsContainer = style({ export const optionsContainer = style({
display: "flex", display: "flex",
gap: `${SPACING_UNIT}px`, gap: `${SPACING_UNIT * 2}px`,
flexDirection: "column", flexDirection: "column",
}); });
export const downloadSourceField = style({ export const gameOptionRow = style({
display: "flex", display: "flex",
gap: `${SPACING_UNIT}px`, gap: `${SPACING_UNIT}px`,
}); });

View file

@ -1,12 +1,8 @@
import { useContext, useState } from "react"; import { useContext, useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { Button, Modal, TextField } from "@renderer/components"; 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 { SPACING_UNIT } from "../../../theme.css";
import { gameDetailsContext } from "../game-details.context"; import { gameDetailsContext } from "../game-details.context";
import { import {
FileDirectoryOpenFillIcon, FileDirectoryOpenFillIcon,
@ -80,15 +76,8 @@ export function GameOptionsModal({
deleteGame={handleDeleteGame} deleteGame={handleDeleteGame}
/> />
<div <div className={styles.optionsContainer}>
style={{ <div className={styles.gameOptionRow}>
display: "flex",
flexDirection: "column",
gap: `${SPACING_UNIT}px`,
width: "100%",
}}
>
<div className={styles.downloadSourceField}>
<Button <Button
onClick={openRepacksModal} onClick={openRepacksModal}
theme="outline" theme="outline"
@ -97,7 +86,7 @@ export function GameOptionsModal({
{t("open_download_options")} {t("open_download_options")}
</Button> </Button>
</div> </div>
<div className={styles.downloadSourceField}> <div className={styles.gameOptionRow}>
<TextField <TextField
label="Caminho do executável" label="Caminho do executável"
value={game.executablePath || ""} value={game.executablePath || ""}
@ -137,10 +126,8 @@ export function GameOptionsModal({
</Button> </Button>
</div> </div>
<div className={styles.downloadSourceField}></div>
{game.folderName && ( {game.folderName && (
<div className={styles.downloadSourceField}> <div className={styles.gameOptionRow}>
<TextField <TextField
label={t("installer_path")} label={t("installer_path")}
value={`${game.downloadPath}\\${game.folderName}`} value={`${game.downloadPath}\\${game.folderName}`}

View file

@ -11,6 +11,7 @@ export const [themeClass, vars] = createTheme({
border: "#424244", border: "#424244",
success: "#1c9749", success: "#1c9749",
danger: "#e11d48", danger: "#e11d48",
warning: "#ffc107",
}, },
opacity: { opacity: {
disabled: "0.5", disabled: "0.5",