From be3d6757d62a224787a3a4bfb27c6f05f34e4c56 Mon Sep 17 00:00:00 2001 From: Jeff Davidson Date: Wed, 2 Oct 2024 20:21:24 -0700 Subject: [PATCH] Reset puzzle modal form upon successful submission. See #2274 --- imports/client/components/PuzzleListPage.tsx | 11 +++++++++-- imports/client/components/PuzzleModalForm.tsx | 10 ++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/imports/client/components/PuzzleListPage.tsx b/imports/client/components/PuzzleListPage.tsx index ae7daab1e..b76e78056 100644 --- a/imports/client/components/PuzzleListPage.tsx +++ b/imports/client/components/PuzzleListPage.tsx @@ -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( diff --git a/imports/client/components/PuzzleModalForm.tsx b/imports/client/components/PuzzleModalForm.tsx index 757ae9299..be5f1378c 100644 --- a/imports/client/components/PuzzleModalForm.tsx +++ b/imports/client/components/PuzzleModalForm.tsx @@ -47,6 +47,7 @@ enum PuzzleModalFormSubmitState { } export type PuzzleModalFormHandle = { + reset: () => void; show: () => void; }; @@ -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; @@ -231,6 +240,7 @@ const PuzzleModalForm = React.forwardRef( useImperativeHandle(forwardedRef, () => ({ show, + reset, })); useEffect(() => {