Fix bug latency on commentThread title edition
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import React, { useMemo } from 'react';
|
import React, { useEffect, useMemo, useState } from 'react';
|
||||||
import { getOperationName } from '@apollo/client/utilities';
|
import { getOperationName } from '@apollo/client/utilities';
|
||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
|
|
||||||
@ -87,6 +87,11 @@ export function CommentThread({
|
|||||||
},
|
},
|
||||||
skip: !commentThreadId,
|
skip: !commentThreadId,
|
||||||
});
|
});
|
||||||
|
const commentThread = data?.findManyCommentThreads[0];
|
||||||
|
|
||||||
|
const [title, setTitle] = useState<string | null | undefined>(
|
||||||
|
commentThread?.title,
|
||||||
|
);
|
||||||
|
|
||||||
const [updateCommentThreadTitleMutation] =
|
const [updateCommentThreadTitleMutation] =
|
||||||
useUpdateCommentThreadTitleMutation();
|
useUpdateCommentThreadTitleMutation();
|
||||||
@ -109,11 +114,16 @@ export function CommentThread({
|
|||||||
function updateTitleFromBody(body: string) {
|
function updateTitleFromBody(body: string) {
|
||||||
const title = JSON.parse(body)[0]?.content[0]?.text;
|
const title = JSON.parse(body)[0]?.content[0]?.text;
|
||||||
if (!commentThread?.title || commentThread?.title === '') {
|
if (!commentThread?.title || commentThread?.title === '') {
|
||||||
|
setTitle(title);
|
||||||
debounceUpdateTitle(title);
|
debounceUpdateTitle(title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const commentThread = data?.findManyCommentThreads[0];
|
useEffect(() => {
|
||||||
|
if (commentThread?.title) {
|
||||||
|
setTitle(commentThread.title);
|
||||||
|
}
|
||||||
|
}, [commentThread?.title]);
|
||||||
|
|
||||||
if (!commentThread) {
|
if (!commentThread) {
|
||||||
return <></>;
|
return <></>;
|
||||||
@ -128,8 +138,11 @@ export function CommentThread({
|
|||||||
</StyledTopActionsContainer>
|
</StyledTopActionsContainer>
|
||||||
<StyledEditableTitleInput
|
<StyledEditableTitleInput
|
||||||
placeholder="Note title (optional)"
|
placeholder="Note title (optional)"
|
||||||
onChange={(event) => debounceUpdateTitle(event.target.value)}
|
onChange={(event) => {
|
||||||
value={commentThread?.title ?? ''}
|
setTitle(event.target.value);
|
||||||
|
debounceUpdateTitle(event.target.value);
|
||||||
|
}}
|
||||||
|
value={title ?? ''}
|
||||||
/>
|
/>
|
||||||
<PropertyBox>
|
<PropertyBox>
|
||||||
<PropertyBoxItem
|
<PropertyBoxItem
|
||||||
|
|||||||
Reference in New Issue
Block a user