mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-09 03:37:45 +03:00
feat: added debounce to the launch options input and removed unnecessary fragment in the clear button
This commit is contained in:
parent
c098d8ffcf
commit
423693040b
@ -1,4 +1,4 @@
|
|||||||
import { useContext, useState } from "react";
|
import { useContext, useRef, 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";
|
||||||
@ -8,6 +8,7 @@ import { DeleteGameModal } from "@renderer/pages/downloads/delete-game-modal";
|
|||||||
import { useDownload, useToast } from "@renderer/hooks";
|
import { useDownload, useToast } from "@renderer/hooks";
|
||||||
import { RemoveGameFromLibraryModal } from "./remove-from-library-modal";
|
import { RemoveGameFromLibraryModal } from "./remove-from-library-modal";
|
||||||
import { FileDirectoryIcon, FileIcon } from "@primer/octicons-react";
|
import { FileDirectoryIcon, FileIcon } from "@primer/octicons-react";
|
||||||
|
import { debounce } from "lodash-es";
|
||||||
|
|
||||||
export interface GameOptionsModalProps {
|
export interface GameOptionsModalProps {
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
@ -45,6 +46,13 @@ export function GameOptionsModal({
|
|||||||
const isGameDownloading =
|
const isGameDownloading =
|
||||||
game.status === "active" && lastPacket?.game.id === game.id;
|
game.status === "active" && lastPacket?.game.id === game.id;
|
||||||
|
|
||||||
|
const debounceUpdateLaunchOptions = useRef(
|
||||||
|
debounce(async (value: string) => {
|
||||||
|
await window.electron.updateLaunchOptions(game.id, value);
|
||||||
|
updateGame();
|
||||||
|
}, 1000)
|
||||||
|
).current;
|
||||||
|
|
||||||
const handleRemoveGameFromLibrary = async () => {
|
const handleRemoveGameFromLibrary = async () => {
|
||||||
if (isGameDownloading) {
|
if (isGameDownloading) {
|
||||||
await cancelDownload(game.id);
|
await cancelDownload(game.id);
|
||||||
@ -121,8 +129,7 @@ export function GameOptionsModal({
|
|||||||
const value = event.target.value;
|
const value = event.target.value;
|
||||||
|
|
||||||
setLaunchOptions(value);
|
setLaunchOptions(value);
|
||||||
|
debounceUpdateLaunchOptions(value);
|
||||||
window.electron.updateLaunchOptions(game.id, value).then(updateGame);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClearLaunchOptions = async () => {
|
const handleClearLaunchOptions = async () => {
|
||||||
@ -256,16 +263,11 @@ export function GameOptionsModal({
|
|||||||
placeholder={t("launch_options_placeholder")}
|
placeholder={t("launch_options_placeholder")}
|
||||||
onChange={handleChangeLaunchOptions}
|
onChange={handleChangeLaunchOptions}
|
||||||
rightContent={
|
rightContent={
|
||||||
<>
|
game.launchOptions && (
|
||||||
{game.launchOptions && (
|
<Button onClick={handleClearLaunchOptions} theme="outline">
|
||||||
<Button
|
|
||||||
onClick={handleClearLaunchOptions}
|
|
||||||
theme="outline"
|
|
||||||
>
|
|
||||||
{t("clear")}
|
{t("clear")}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)
|
||||||
</>
|
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user