Skip to content

Commit

Permalink
don't use useSave hook 2 levels deep (1 only)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicanordlc committed Jun 18, 2024
1 parent 2ee8fd0 commit 230482f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
13 changes: 3 additions & 10 deletions frontend/src/components/Save/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button, Typography } from "@material-tailwind/react";
import { FaDownload, FaFolderOpen, FaTrash, FaUpload } from "react-icons/fa6";
import useSave, { type SaveSingle } from "@/hooks/useSave";
import { type SaveSingle } from "@/hooks/useSave";
import WithTooltip from "@/components/WithTooltip";
import NameInput from "@/components/Save/NameInput";

Expand All @@ -12,11 +12,10 @@ type SaveProps = {
onSave: SavePropsCallback;
onDelete: SavePropsCallback;
onOpenDirectory: SavePropsCallback;
onSubmit: (nameInput: string) => void;
};

const Save = (props: SaveProps) => {
const { updateSave } = useSave({ GameID: props.data.GameID });

const formatDate = (dateString: string) => {
const date = new Date(dateString);
const intlDate = new Intl.DateTimeFormat("en-US").format(date);
Expand All @@ -41,13 +40,7 @@ const Save = (props: SaveProps) => {
</WithTooltip>

<NameInput
onSubmit={async (data) => {
await updateSave({
ID: props.data.ID,
GameID: props.data.GameID,
Name: data.Name,
});
}}
onSubmit={(data) => props.onSubmit(data.Name)}
name={props.data.Name}
/>

Expand Down
8 changes: 8 additions & 0 deletions frontend/src/pages/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const Game = () => {
loadSave,
loadQuickSave,
overwriteSave,
updateSave,
} = useSave({
GameID: gameID,
});
Expand Down Expand Up @@ -190,6 +191,13 @@ const Game = () => {
onSave={() => handleOverwrite(save.ID)}
onDelete={() => handleDelete(save.ID)}
onOpenDirectory={() => handleOpenSaveDirectory(save.ID)}
onSubmit={async (nameInput) => {
await updateSave({
ID: save.ID,
GameID: save.GameID,
Name: nameInput,
});
}}
/>
))
)}
Expand Down

0 comments on commit 230482f

Please sign in to comment.