Skip to content

Commit

Permalink
fix: Discussion bugs (#10596)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Krick <matt.krick@gmail.com>
  • Loading branch information
mattkrick authored Dec 12, 2024
1 parent 2703dab commit 5114948
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
5 changes: 3 additions & 2 deletions packages/client/components/DiscussionThreadInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ const DiscussionThreadInput = (props: Props) => {
const inputBottomRef = useRef<HTMLDivElement>(null)
useEffect(() => {
containerRef.current?.scrollIntoView({behavior: 'smooth', block: 'center'})
}, [])
editor?.commands.focus('end')
}, [discussionId])
const containerRef = useRef<HTMLDivElement>(null)
useClickAway(containerRef, clearReplyingTo)
if (!editor) return null
Expand All @@ -285,7 +286,7 @@ const DiscussionThreadInput = (props: Props) => {
<SendCommentButton commentSubmitState={commentSubmitState} onSubmit={onSubmit} />
</div>
{isActionsContainerVisible && (
<div className='flex items-center justify-center border-t-[1px] border-solid border-t-slate-200'>
<div className='flex items-center justify-center border-t-[1px] border-solid border-t-slate-200 py-1'>
{allowTasks && <AddTaskButton onClick={addTask} disabled={isActionsContainerDisabled} />}
{allowPolls && <AddPollButton onClick={addPoll} disabled={isActionsContainerDisabled} />}
</div>
Expand Down
6 changes: 1 addition & 5 deletions packages/client/hooks/useTipTapCommentEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ export const useTipTapCommentEditor = (
})
].filter(isValid),
editable: !readOnly,
autofocus: true,
onCreate: ({editor}) => {
// Focus the editor and move the cursor to the end of the content
editor.commands.focus('end')
}
autofocus: true
},
[readOnly]
)
Expand Down
16 changes: 5 additions & 11 deletions packages/client/mutations/UpdateTaskMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
SharedUpdater,
StandardMutation
} from '../types/relayMutations'
import updateProxyRecord from '../utils/relay/updateProxyRecord'
import handleAddNotifications from './handlers/handleAddNotifications'
import handleRemoveTasks from './handlers/handleRemoveTasks'
import handleUpsertTasks from './handlers/handleUpsertTasks'
Expand Down Expand Up @@ -107,23 +106,18 @@ const UpdateTaskMutation: StandardMutation<TUpdateTaskMutation, OptionalHandlers
updateTaskTaskUpdater(payload, {atmosphere, store: store as any})
},
optimisticUpdater: (store) => {
const {id, content, userId} = updatedTask
const {id, content, userId, status, sortOrder} = updatedTask
const task = store.get(id)
if (!task) return
const now = new Date()
const optimisticTask = {
// do not update content because that will cause the editor to rebuild itself
// we only want a rebuild if someone else changes the content
id,
userId,
updatedAt: now.toJSON()
}
updateProxyRecord(task, optimisticTask)
status && task.setValue(status, 'status')
sortOrder && task.setValue(sortOrder, 'sortOrder')
if (userId) {
task.setValue(userId, 'userId')
task.setLinkedRecord(store.get(userId)!, 'user')
}
if (content) {
// do not update content because that will cause the editor to rebuild itself
// we only want a rebuild if someone else changes the content
const contentJSON = JSON.parse(content)
const nextTags = getTagsFromTipTapTask(contentJSON)
task.setValue(nextTags, 'tags')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import {DataLoaderWorker} from '../../graphql'

export const buildCommentContentBlock = (
title: string,
content: string,
contentHTML: string,
explainerText?: string
) => {
const explainerBlock = explainerText ? `<i>${explainerText}</i><br>` : ''
const html = `${explainerBlock}<p><b>${title}</b></p><p>${content}</p>`
const html = `${explainerBlock}<p><b>${title}</b></p>${contentHTML}`
return generateJSON(html, serverTipTapExtensions) as JSONContent
}

Expand All @@ -42,7 +42,10 @@ const addAIGeneratedContentToThreads = async (
if (group.discussionPromptQuestion) {
const topicSummaryComment = createAIComment(
discussionId,
buildCommentContentBlock('🤖 Discussion Question', group.discussionPromptQuestion),
buildCommentContentBlock(
'🤖 Discussion Question',
`<p>${group.discussionPromptQuestion}</p>`
),
1
)
comments.push(topicSummaryComment)
Expand Down

0 comments on commit 5114948

Please sign in to comment.