11import * as React from 'react'
22import { twMerge } from 'tailwind-merge'
3- import { FaComment , FaLightbulb , FaTrash , FaChevronDown , FaChevronUp , FaSave , FaTimes } from 'react-icons/fa'
3+ import {
4+ FaComment ,
5+ FaLightbulb ,
6+ FaTrash ,
7+ FaChevronDown ,
8+ FaChevronUp ,
9+ FaSave ,
10+ FaTimes ,
11+ } from 'react-icons/fa'
412import { useMutation , useQueryClient } from '@tanstack/react-query'
5- import { deleteDocFeedback , updateDocFeedback , updateDocFeedbackCollapsed } from '~/utils/docFeedback.functions'
13+ import {
14+ deleteDocFeedback ,
15+ updateDocFeedback ,
16+ updateDocFeedbackCollapsed ,
17+ } from '~/utils/docFeedback.functions'
618import { useToast } from '~/components/ToastProvider'
719import type { DocFeedback } from '~/db/schema'
820
@@ -12,7 +24,11 @@ interface DocFeedbackNoteProps {
1224 inline ?: boolean
1325}
1426
15- export function DocFeedbackNote ( { note, anchorName, inline = false } : DocFeedbackNoteProps ) {
27+ export function DocFeedbackNote ( {
28+ note,
29+ anchorName,
30+ inline = false ,
31+ } : DocFeedbackNoteProps ) {
1632 const queryClient = useQueryClient ( )
1733 const [ isDeleting , setIsDeleting ] = React . useState ( false )
1834 const [ deleteError , setDeleteError ] = React . useState < string | null > ( null )
@@ -57,7 +73,8 @@ export function DocFeedbackNote({ note, anchorName, inline = false }: DocFeedbac
5773
5874 // Extract first line for preview
5975 const firstLine = note . content . split ( '\n' ) [ 0 ]
60- const preview = firstLine . length > 60 ? firstLine . substring ( 0 , 60 ) + '...' : firstLine
76+ const preview =
77+ firstLine . length > 60 ? firstLine . substring ( 0 , 60 ) + '...' : firstLine
6178
6279 const deleteMutation = useMutation ( {
6380 mutationFn : deleteDocFeedback ,
@@ -66,33 +83,32 @@ export function DocFeedbackNote({ note, anchorName, inline = false }: DocFeedbac
6683 await queryClient . cancelQueries ( { queryKey : [ 'docFeedback' ] } )
6784
6885 // Snapshot the previous value
69- const previousData = queryClient . getQueriesData ( { queryKey : [ 'docFeedback' ] } )
86+ const previousData = queryClient . getQueriesData ( {
87+ queryKey : [ 'docFeedback' ] ,
88+ } )
7089
7190 // Optimistically remove the note from all matching queries
72- queryClient . setQueriesData (
73- { queryKey : [ 'docFeedback' ] } ,
74- ( old : any ) => {
75- if ( ! old ) return old
76-
77- // Handle doc page structure (userFeedback)
78- if ( 'userFeedback' in old && Array . isArray ( old . userFeedback ) ) {
79- return {
80- ...old ,
81- userFeedback : old . userFeedback . filter ( ( f : any ) => f . id !== note . id ) ,
82- }
91+ queryClient . setQueriesData ( { queryKey : [ 'docFeedback' ] } , ( old : any ) => {
92+ if ( ! old ) return old
93+
94+ // Handle doc page structure (userFeedback)
95+ if ( 'userFeedback' in old && Array . isArray ( old . userFeedback ) ) {
96+ return {
97+ ...old ,
98+ userFeedback : old . userFeedback . filter ( ( f : any ) => f . id !== note . id ) ,
8399 }
100+ }
84101
85- // Handle account/notes page structure (feedback)
86- if ( 'feedback' in old && Array . isArray ( old . feedback ) ) {
87- return {
88- ...old ,
89- feedback : old . feedback . filter ( ( f : any ) => f . id !== note . id ) ,
90- }
102+ // Handle account/notes page structure (feedback)
103+ if ( 'feedback' in old && Array . isArray ( old . feedback ) ) {
104+ return {
105+ ...old ,
106+ feedback : old . feedback . filter ( ( f : any ) => f . id !== note . id ) ,
91107 }
92-
93- return old
94108 }
95- )
109+
110+ return old
111+ } )
96112
97113 return { previousData }
98114 } ,
@@ -118,41 +134,48 @@ export function DocFeedbackNote({ note, anchorName, inline = false }: DocFeedbac
118134 await queryClient . cancelQueries ( { queryKey : [ 'docFeedback' ] } )
119135
120136 // Snapshot the previous value
121- const previousData = queryClient . getQueriesData ( { queryKey : [ 'docFeedback' ] } )
137+ const previousData = queryClient . getQueriesData ( {
138+ queryKey : [ 'docFeedback' ] ,
139+ } )
122140
123141 // Optimistically update the note content
124- queryClient . setQueriesData (
125- { queryKey : [ 'docFeedback' ] } ,
126- ( old : any ) => {
127- if ( ! old ) return old
128-
129- // Handle doc page structure (userFeedback)
130- if ( 'userFeedback' in old && Array . isArray ( old . userFeedback ) ) {
131- return {
132- ...old ,
133- userFeedback : old . userFeedback . map ( ( f : any ) =>
134- f . id === note . id
135- ? { ...f , content : variables . data . content , updatedAt : new Date ( ) }
136- : f
137- ) ,
138- }
142+ queryClient . setQueriesData ( { queryKey : [ 'docFeedback' ] } , ( old : any ) => {
143+ if ( ! old ) return old
144+
145+ // Handle doc page structure (userFeedback)
146+ if ( 'userFeedback' in old && Array . isArray ( old . userFeedback ) ) {
147+ return {
148+ ...old ,
149+ userFeedback : old . userFeedback . map ( ( f : any ) =>
150+ f . id === note . id
151+ ? {
152+ ...f ,
153+ content : variables . data . content ,
154+ updatedAt : new Date ( ) ,
155+ }
156+ : f ,
157+ ) ,
139158 }
159+ }
140160
141- // Handle account/notes page structure (feedback)
142- if ( 'feedback' in old && Array . isArray ( old . feedback ) ) {
143- return {
144- ...old ,
145- feedback : old . feedback . map ( ( f : any ) =>
146- f . id === note . id
147- ? { ...f , content : variables . data . content , updatedAt : new Date ( ) }
148- : f
149- ) ,
150- }
161+ // Handle account/notes page structure (feedback)
162+ if ( 'feedback' in old && Array . isArray ( old . feedback ) ) {
163+ return {
164+ ...old ,
165+ feedback : old . feedback . map ( ( f : any ) =>
166+ f . id === note . id
167+ ? {
168+ ...f ,
169+ content : variables . data . content ,
170+ updatedAt : new Date ( ) ,
171+ }
172+ : f ,
173+ ) ,
151174 }
152-
153- return old
154175 }
155- )
176+
177+ return old
178+ } )
156179
157180 return { previousData }
158181 } ,
@@ -182,41 +205,40 @@ export function DocFeedbackNote({ note, anchorName, inline = false }: DocFeedbac
182205 await queryClient . cancelQueries ( { queryKey : [ 'docFeedback' ] } )
183206
184207 // Snapshot the previous value
185- const previousData = queryClient . getQueriesData ( { queryKey : [ 'docFeedback' ] } )
208+ const previousData = queryClient . getQueriesData ( {
209+ queryKey : [ 'docFeedback' ] ,
210+ } )
186211
187212 // Optimistically toggle collapsed state
188- queryClient . setQueriesData (
189- { queryKey : [ 'docFeedback' ] } ,
190- ( old : any ) => {
191- if ( ! old ) return old
192-
193- // Handle doc page structure (userFeedback)
194- if ( 'userFeedback' in old && Array . isArray ( old . userFeedback ) ) {
195- return {
196- ...old ,
197- userFeedback : old . userFeedback . map ( ( f : any ) =>
198- f . id === note . id
199- ? { ...f , isCollapsed : variables . data . isCollapsed }
200- : f
201- ) ,
202- }
213+ queryClient . setQueriesData ( { queryKey : [ 'docFeedback' ] } , ( old : any ) => {
214+ if ( ! old ) return old
215+
216+ // Handle doc page structure (userFeedback)
217+ if ( 'userFeedback' in old && Array . isArray ( old . userFeedback ) ) {
218+ return {
219+ ...old ,
220+ userFeedback : old . userFeedback . map ( ( f : any ) =>
221+ f . id === note . id
222+ ? { ...f , isCollapsed : variables . data . isCollapsed }
223+ : f ,
224+ ) ,
203225 }
226+ }
204227
205- // Handle account/notes page structure (feedback)
206- if ( 'feedback' in old && Array . isArray ( old . feedback ) ) {
207- return {
208- ...old ,
209- feedback : old . feedback . map ( ( f : any ) =>
210- f . id === note . id
211- ? { ...f , isCollapsed : variables . data . isCollapsed }
212- : f
213- ) ,
214- }
228+ // Handle account/notes page structure (feedback)
229+ if ( 'feedback' in old && Array . isArray ( old . feedback ) ) {
230+ return {
231+ ...old ,
232+ feedback : old . feedback . map ( ( f : any ) =>
233+ f . id === note . id
234+ ? { ...f , isCollapsed : variables . data . isCollapsed }
235+ : f ,
236+ ) ,
215237 }
216-
217- return old
218238 }
219- )
239+
240+ return old
241+ } )
220242
221243 return { previousData }
222244 } ,
@@ -316,7 +338,8 @@ export function DocFeedbackNote({ note, anchorName, inline = false }: DocFeedbac
316338 < div
317339 className = { twMerge (
318340 `flex flex-col gap-1 p-2 ${ colors . header } ` ,
319- note . isCollapsed && 'cursor-pointer hover:opacity-80 transition-opacity'
341+ note . isCollapsed &&
342+ 'cursor-pointer hover:opacity-80 transition-opacity' ,
320343 ) }
321344 onClick = { note . isCollapsed ? handleToggle : undefined }
322345 >
@@ -364,9 +387,17 @@ export function DocFeedbackNote({ note, anchorName, inline = false }: DocFeedbac
364387 handleToggle ( )
365388 } }
366389 className = { `p-1 ${ colors . icon } ${ colors . deleteHover } transition-colors` }
367- title = { note . isCollapsed ? `Expand ${ isImprovement ? 'improvement' : 'note' } ` : `Collapse ${ isImprovement ? 'improvement' : 'note' } ` }
390+ title = {
391+ note . isCollapsed
392+ ? `Expand ${ isImprovement ? 'improvement' : 'note' } `
393+ : `Collapse ${ isImprovement ? 'improvement' : 'note' } `
394+ }
368395 >
369- { note . isCollapsed ? < FaChevronDown className = "text-xs" /> : < FaChevronUp className = "text-xs" /> }
396+ { note . isCollapsed ? (
397+ < FaChevronDown className = "text-xs" />
398+ ) : (
399+ < FaChevronUp className = "text-xs" />
400+ ) }
370401 </ button >
371402 </ div >
372403 </ div >
@@ -428,7 +459,9 @@ export function DocFeedbackNote({ note, anchorName, inline = false }: DocFeedbac
428459 ) }
429460
430461 { /* Timestamp and Points */ }
431- < div className = { `mt-2 flex items-center justify-between text-xs ${ colors . timestamp } ` } >
462+ < div
463+ className = { `mt-2 flex items-center justify-between text-xs ${ colors . timestamp } ` }
464+ >
432465 < div >
433466 { new Date ( note . createdAt ) . toLocaleDateString ( 'en-US' , {
434467 month : 'short' ,
0 commit comments