Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return Comments Submit #3058

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 124 additions & 4 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 @@ -49,7 +49,7 @@
"@sentry/nextjs": "7.99.0",
"@tanstack/react-query": "4.29.5",
"@tanstack/react-query-devtools": "4.29.6",
"@taskany/bricks": "5.52.2",
"@taskany/bricks": "5.53.0",
"@taskany/colors": "1.13.1",
"@taskany/icons": "2.0.7",
"@tippyjs/react": "4.2.6",
Expand Down
7 changes: 6 additions & 1 deletion src/components/CommentCreateForm/CommentCreateForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useCallback, useMemo } from 'react';
import { State as StateDataType } from '@prisma/client';

Check warning on line 2 in src/components/CommentCreateForm/CommentCreateForm.tsx

View workflow job for this annotation

GitHub Actions / build

'@prisma/client' import is restricted from being used. Use the trpc procedures inferred types instead
import { nullable, useLatest } from '@taskany/bricks';
import { IconDownSmallSolid, IconUpSmallSolid } from '@taskany/icons';
import { Avatar, Button } from '@taskany/bricks/harmony';
Expand Down Expand Up @@ -50,11 +50,13 @@
const [description, setDescription] = useState(currentDescription);
const descriptionRef = useLatest(description);
const [focused, setFocused] = useState(Boolean(currentDescription));
const [controls, setControls] = useState(focused);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<{ message: string } | undefined>();

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

Expand All @@ -76,19 +78,21 @@

setBusy(true);
setFocused(false);
setControls(false);

await onSubmit?.(form);

setDescription('');
setPushState(form.stateId ? statesMap[form.stateId] : undefined);

setBusy(false);
setFocused(true);
setControls(true);
},
[onSubmit, statesMap],
);

const onCancelCreate = useCallback(() => {
setControls(false);
setBusy(false);
setPushState(stateId ? statesMap[stateId] : undefined);
setDescription('');
Expand Down Expand Up @@ -137,6 +141,7 @@
<CommentForm
description={description}
focused={focused}
controls={controls}
busy={busy}
onChange={onCommentChange}
onSubmit={onCommentFormSubmit('pushState')}
Expand Down
1 change: 0 additions & 1 deletion src/components/CommentForm/CommentForm.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

.CommentFormWrapper {
position: relative;
background-color: var(--input-fill);
}

.CommentFormWrapper::before {
Expand Down
6 changes: 4 additions & 2 deletions src/components/CommentForm/CommentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import s from './CommentForm.module.css';
interface CommentFormProps {
actionButton: React.ReactNode;
focused?: boolean;
controls?: boolean;
autoFocus?: boolean;
busy?: boolean;
description?: string;
Expand All @@ -31,6 +32,7 @@ export const CommentForm: React.FC<CommentFormProps> = ({
description = '',
autoFocus,
focused,
controls,
busy,
actionButton,
onChange,
Expand Down Expand Up @@ -80,7 +82,7 @@ export const CommentForm: React.FC<CommentFormProps> = ({
<FormControlEditor
disabled={busy}
placeholder={tr('Leave a comment')}
height={focused ? 120 : 80}
height={controls ? 120 : 80}
onCancel={onCommentCancel}
onBlur={onBlur}
onFocus={onFocus}
Expand All @@ -96,7 +98,7 @@ export const CommentForm: React.FC<CommentFormProps> = ({
))}
</FormControl>

{nullable(focused, () => (
{nullable(controls, () => (
<FormActions>
<div className={s.FormHelpButton}>
<HelpButton slug="comments" />
Expand Down
18 changes: 16 additions & 2 deletions src/components/CommentView/CommentView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const CommentView: FC<CommentViewProps> = ({

const [editMode, setEditMode] = useState(false);
const [focused, setFocused] = useState(false);
const [controls, setControls] = useState(focused);
const [busy, setBusy] = useState(false);
const [commentDescription, setCommentDescription] = useState({ description });
const { reactionsProps } = useReactionsResource(reactions);
Expand All @@ -100,7 +101,7 @@ export const CommentView: FC<CommentViewProps> = ({
setEditMode(false);
setBusy(true);
setFocused(false);

setControls(false);
onChange?.({ description: form.description });

// optimistic update
Expand All @@ -118,11 +119,20 @@ export const CommentView: FC<CommentViewProps> = ({

const onCommentCancel = useCallback(() => {
setEditMode(false);
setFocused(false);
setControls(false);
setCommentDescription({ description });
onCancel?.();
}, [description, onCancel]);

const onCommentFocus = useCallback(() => {
setFocused(true);
setControls(true);
}, []);

const onCommentBlur = useCallback(() => {
setFocused(false);
}, []);

const dropdownItems = useMemo(() => {
const items = [
{
Expand All @@ -142,6 +152,7 @@ export const CommentView: FC<CommentViewProps> = ({
onClick: () => {
setEditMode(true);
setFocused(true);
setControls(true);
},
},
{
Expand Down Expand Up @@ -187,9 +198,12 @@ export const CommentView: FC<CommentViewProps> = ({
<CommentForm
description={commentDescription.description}
focused={focused}
controls={controls}
busy={busy}
autoFocus
onChange={setCommentDescription}
onFocus={onCommentFocus}
onBlur={onCommentBlur}
onSubmit={onCommentSubmit}
onCancel={onCommentCancel}
actionButton={
Expand Down
Loading