From 758651013d2069586dcb79f629271d3ee15d32b1 Mon Sep 17 00:00:00 2001 From: James Morris Date: Thu, 4 Aug 2022 16:46:22 +0100 Subject: [PATCH] Tidying up dialog calls for bio with correct autofocus - Removed only showing bio in modal, now showing both always - Changed how the modal is called with parameters to focus on bio if clicked refs https://github.com/TryGhost/Team/issues/1716 --- apps/comments-ui/src/components/Form.js | 35 +++--- .../src/components/modals/AddDetailsDialog.js | 100 ++++++++---------- 2 files changed, 60 insertions(+), 75 deletions(-) diff --git a/apps/comments-ui/src/components/Form.js b/apps/comments-ui/src/components/Form.js index 6b82ddce94..c4fdc2a2eb 100644 --- a/apps/comments-ui/src/components/Form.js +++ b/apps/comments-ui/src/components/Form.js @@ -302,26 +302,13 @@ const Form = (props) => { editor.commands.focus(); }; - const handleAddBoth = (event) => { + const handleShowDialog = (event, options) => { event.preventDefault(); setPreventClosing(true); dispatchAction('openPopup', { type: 'addDetailsDialog', - callback: () => { - editor?.commands.focus(); - setPreventClosing(false); - } - }); - }; - - const handleAddBio = (event) => { - event.preventDefault(); - setPreventClosing(true); - - dispatchAction('openPopup', { - type: 'addDetailsDialog', - bioOnly: true, + bioAutofocus: options.bioAutofocus ?? false, callback: () => { editor?.commands.focus(); setPreventClosing(false); @@ -422,9 +409,21 @@ const Form = (props) => { leaveFrom="opacity-100" leaveTo="opacity-0" > - -
- + +
+
diff --git a/apps/comments-ui/src/components/modals/AddDetailsDialog.js b/apps/comments-ui/src/components/modals/AddDetailsDialog.js index 3d2013c09a..dc146dab0b 100644 --- a/apps/comments-ui/src/components/modals/AddDetailsDialog.js +++ b/apps/comments-ui/src/components/modals/AddDetailsDialog.js @@ -26,37 +26,27 @@ const AddNameDialog = (props) => { }; const submit = async () => { - // When it's both name and bio - if (!props.bioOnly) { - if (name.trim() !== '') { - await dispatchAction('updateMember', { - name, - bio - }); - close(true); - } else { - setError({name: 'Enter your name'}); - setName(''); - inputNameRef.current?.focus(); - } - // When it's only bio - } else { + if (name.trim() !== '') { await dispatchAction('updateMember', { + name, bio }); - close(true); + } else { + setError({name: 'Enter your name'}); + setName(''); + inputNameRef.current?.focus(); } }; // using breaks transitions in browsers. So we need to use a timer useEffect(() => { const timer = setTimeout(() => { - if (!props.bioOnly) { - inputNameRef.current?.focus(); - } else { + if (props.bioAutofocus) { inputBioRef.current?.focus(); - } + } else { + inputNameRef.current?.focus(); + } }, 200); return () => { @@ -69,43 +59,39 @@ const AddNameDialog = (props) => {

Add context to your comments

For a healthy discussion, let other members know who you are when commenting.

- {!props.bioOnly && - <> -
- - -
{error.name}
-
-
- { - setName(e.target.value); - }} - onKeyDown={(e) => { - if (e.key === 'Enter') { - setName(e.target.value); - submit(); - } - }} - maxLength="64" - /> - - } +
+ + +
{error.name}
+
+
+ { + setName(e.target.value); + }} + onKeyDown={(e) => { + if (e.key === 'Enter') { + setName(e.target.value); + submit(); + } + }} + maxLength="64" + />
{bioCharsLeft} characters left