Skip to content

Commit

Permalink
Reset puzzle modal form upon successful submission.
Browse files Browse the repository at this point in the history
See #2274
  • Loading branch information
jpd236 committed Dec 21, 2024
1 parent e9650de commit be3d675
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
11 changes: 9 additions & 2 deletions imports/client/components/PuzzleListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,16 @@ const PuzzleListView = ({
return;
}

createPuzzle.call({ docType, ...rest }, callback);
function onAddComplete(error?: Error) {
if (!error && addModalRef.current) {
addModalRef.current.reset();
}
callback(error);
}

createPuzzle.call({ docType, ...rest }, onAddComplete);
},
[],
[addModalRef],
);

const setSearchString = useCallback(
Expand Down
10 changes: 10 additions & 0 deletions imports/client/components/PuzzleModalForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ enum PuzzleModalFormSubmitState {
}

export type PuzzleModalFormHandle = {
reset: () => void;
show: () => void;
};

Expand Down Expand Up @@ -194,6 +195,14 @@ const PuzzleModalForm = React.forwardRef(
}
}, []);

const reset = useCallback(() => {
setTitle("");
setUrl("");
setTags([]);
setExpectedAnswerCount(1);
setDocType("spreadsheet");
}, []);

const currentTitle = useMemo(() => {
if (!titleDirty && puzzle) {
return puzzle.title;
Expand Down Expand Up @@ -231,6 +240,7 @@ const PuzzleModalForm = React.forwardRef(

useImperativeHandle(forwardedRef, () => ({
show,
reset,
}));

useEffect(() => {
Expand Down

0 comments on commit be3d675

Please sign in to comment.