@@ -70,36 +70,35 @@ export const useMarkReportAsRead = () => {
7070export const useToggleReportBookmark = ( ) => {
7171 const queryClient = useQueryClient ( ) ;
7272
73- return async ( reportId : string , isBookmarked : boolean ) => {
74- return useMutation ( {
75- mutationFn : ( ) => toggleReportBookmark ( reportId , isBookmarked ) ,
76- onSuccess : ( updatedReport : MedicalReport ) => {
77- // Update the reports cache
78- queryClient . setQueryData < MedicalReport [ ] > ( [ QueryKey . Reports ] , ( oldReports ) => {
79- if ( ! oldReports ) return undefined ;
80- return oldReports . map ( ( report ) =>
81- report . id === updatedReport . id ? updatedReport : report ,
82- ) ;
83- } ) ;
84-
85- // Update the latest reports cache
86- queryClient . setQueryData < MedicalReport [ ] > ( [ QueryKey . LatestReports ] , ( oldReports ) => {
87- if ( ! oldReports ) return undefined ;
88- return oldReports . map ( ( report ) =>
89- report . id === updatedReport . id ? updatedReport : report ,
90- ) ;
91- } ) ;
73+ return useMutation ( {
74+ mutationFn : ( { reportId, isBookmarked } : { reportId : string ; isBookmarked : boolean } ) =>
75+ toggleReportBookmark ( reportId , isBookmarked ) ,
76+ onSuccess : ( updatedReport : MedicalReport ) => {
77+ // Update the reports cache
78+ queryClient . setQueryData < MedicalReport [ ] > ( [ QueryKey . Reports ] , ( oldReports ) => {
79+ if ( ! oldReports ) return undefined ;
80+ return oldReports . map ( ( report ) =>
81+ report . id === updatedReport . id ? updatedReport : report ,
82+ ) ;
83+ } ) ;
9284
93- // Update the bookmark status in the report detail page
94- queryClient . setQueryData < MedicalReport | undefined > (
95- [ QueryKey . ReportDetail , reportId ] ,
96- ( oldReport ) => {
97- if ( ! oldReport ) return undefined ;
98- if ( oldReport . id !== updatedReport . id ) return oldReport ;
99- return { ...oldReport , bookmarked : updatedReport . bookmarked } ;
100- } ,
85+ // Update the latest reports cache
86+ queryClient . setQueryData < MedicalReport [ ] > ( [ QueryKey . LatestReports ] , ( oldReports ) => {
87+ if ( ! oldReports ) return undefined ;
88+ return oldReports . map ( ( report ) =>
89+ report . id === updatedReport . id ? updatedReport : report ,
10190 ) ;
102- } ,
103- } ) ;
104- } ;
91+ } ) ;
92+
93+ // Update the bookmark status in the report detail page
94+ queryClient . setQueryData < MedicalReport | undefined > (
95+ [ QueryKey . ReportDetail , reportId ] ,
96+ ( oldReport ) => {
97+ if ( ! oldReport ) return undefined ;
98+ if ( oldReport . id !== updatedReport . id ) return oldReport ;
99+ return { ...oldReport , bookmarked : updatedReport . bookmarked } ;
100+ } ,
101+ ) ;
102+ } ,
103+ } ) ;
105104} ;
0 commit comments