Skip to content

Commit

Permalink
fix: question comments showing edited state
Browse files Browse the repository at this point in the history
  • Loading branch information
benfurber committed Mar 4, 2025
1 parent 8ce9765 commit 70a7c42
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/pages/common/CommentsSupabase/CommentSectionSupabase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,14 @@ export const CommentSectionSupabase = ({ sourceId }: CommentsSupabaseProps) => {
const editComment = async (id: number, comment: string) => {
try {
const result = await commentService.editcomment(sourceId, id, comment)
const now = new Date()

if (result.status === 204) {
setComments((comments) =>
comments.map((x) => {
if (x.id === id) {
x.comment = comment
x.modifiedAt = now
}
return x
}),
Expand Down Expand Up @@ -160,6 +162,7 @@ export const CommentSectionSupabase = ({ sourceId }: CommentsSupabaseProps) => {
const editReply = async (id: number, replyText: string, parentId: number) => {
try {
const result = await commentService.editcomment(sourceId, id, replyText)
const now = new Date()

if (result.status === 204) {
setComments((comments) =>
Expand All @@ -168,6 +171,7 @@ export const CommentSectionSupabase = ({ sourceId }: CommentsSupabaseProps) => {
comment.replies = comment.replies?.map((reply) => {
if (reply.id === id) {
reply.comment = replyText
reply.modifiedAt = now
}
return reply
})
Expand Down

0 comments on commit 70a7c42

Please sign in to comment.