Skip to content

Commit

Permalink
chore: fixed click inside & set focus after comment submit
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisVorop committed Jul 26, 2023
1 parent b070d63 commit d370029
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@sentry/nextjs": "7.60.0",
"@tanstack/react-query": "4.29.5",
"@tanstack/react-query-devtools": "4.29.5",
"@taskany/bricks": "1.24.0",
"@taskany/bricks": "1.25.0",
"@taskany/colors": "1.1.0",
"@taskany/icons": "1.0.0",
"@tippyjs/react": "4.2.6",
Expand Down
5 changes: 2 additions & 3 deletions src/components/CommentCreateForm/CommentCreateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ const CommentCreateForm: React.FC<CommentCreateFormProps> = ({ goalId, states, o
const [pushState, setPushState] = useState<State | undefined>();

const createComment = useCallback(
(form: GoalCommentSchema) => {
// FIXME: maybe async/await would be better API
create(({ id }) => {
async (form: GoalCommentSchema) => {
await create(({ id }) => {
onSubmit?.(id);
setPushState(undefined);
})(form);
Expand Down
24 changes: 15 additions & 9 deletions src/components/CommentForm/CommentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface CommentFormProps {
description?: string;

renderActionButton: (props: { busy?: boolean }) => React.ReactNode;
onSubmit?: (form: GoalCommentSchema) => void;
onSubmit?: (form: GoalCommentSchema) => void | Promise<void>;
onFocus?: () => void;
onCancel?: () => void;
}
Expand Down Expand Up @@ -85,26 +85,32 @@ export const CommentForm: React.FC<CommentFormProps> = ({
},
});

const setBusyAndCommentFocused = useCallback((busy: boolean, commentFocused: boolean) => {
setBusy(busy);
setCommentFocused(commentFocused);
}, []);

const onCommentFocus = useCallback(() => {
setCommentFocused(true);
onFocus?.();
}, [onFocus]);

const onCommentCancel = useCallback(() => {
reset();
setBusy(false);
setCommentFocused(false);
setBusyAndCommentFocused(false, false);
onCancel?.();
}, [onCancel, reset]);
}, [onCancel, reset, setBusyAndCommentFocused]);

const onCommentSubmit = useCallback(
(form: GoalCommentSchema) => {
setBusy(true);
setCommentFocused(false);
onSubmit?.(form);
async (form: GoalCommentSchema) => {
setBusyAndCommentFocused(true, false);
reset();

await onSubmit?.(form);

setBusyAndCommentFocused(false, true);
},
[onSubmit, reset],
[onSubmit, reset, setBusyAndCommentFocused],
);

useClickOutside(ref, () => {
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useCommentResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const useCommentResource = () => {
const [data] = await notifyPromise(promise, 'commentCreate');

data && cb(data);
return data;
};

const update =
Expand Down

0 comments on commit d370029

Please sign in to comment.