@@ -20,7 +20,7 @@ import { fetchAllReports, toggleReportBookmark } from 'common/api/reportService'
2020import { useMarkReportAsRead } from 'common/hooks/useReports' ;
2121import ReportItem from 'pages/Home/components/ReportItem/ReportItem' ;
2222import NoReportsMessage from 'pages/Home/components/NoReportsMessage/NoReportsMessage' ;
23- import { useState , useMemo } from 'react' ;
23+ import { useState , useMemo , useEffect } from 'react' ;
2424import { MedicalReport } from 'common/models/medicalReport' ;
2525import { documentTextOutline } from 'ionicons/icons' ;
2626import sortSvg from 'assets/icons/sort.svg' ;
@@ -54,6 +54,18 @@ const ReportsListPage: React.FC = () => {
5454 return reports . filter ( report => report . bookmarked ) ;
5555 } , [ reports , filter ] ) ;
5656
57+ // Check if there are any bookmarked reports
58+ const hasBookmarkedReports = useMemo ( ( ) => {
59+ return reports . some ( report => report . bookmarked ) ;
60+ } , [ reports ] ) ;
61+
62+ // Reset to 'all' filter if no bookmarked reports and current filter is 'bookmarked'
63+ useEffect ( ( ) => {
64+ if ( ! hasBookmarkedReports && filter === 'bookmarked' ) {
65+ setFilter ( 'all' ) ;
66+ }
67+ } , [ hasBookmarkedReports , filter ] ) ;
68+
5769 const handleSegmentChange = ( e : CustomEvent ) => {
5870 setFilter ( e . detail . value as FilterOption ) ;
5971 } ;
@@ -200,18 +212,20 @@ const ReportsListPage: React.FC = () => {
200212 </ IonToolbar >
201213 </ IonHeader >
202214 < IonContent className = "reports-list-page__content-container" >
203- < div className = "reports-list-page__filter" >
204- < div className = "reports-list-page__segment-wrapper" >
205- < IonSegment value = { filter } onIonChange = { handleSegmentChange } mode = "ios" >
206- < IonSegmentButton value = "all" >
207- < IonLabel > { t ( 'list.filterAll' , { ns : 'report' } ) } </ IonLabel >
208- </ IonSegmentButton >
209- < IonSegmentButton value = "bookmarked" >
210- < IonLabel > { t ( 'list.filterBookmarked' , { ns : 'report' } ) } </ IonLabel >
211- </ IonSegmentButton >
212- </ IonSegment >
215+ { ! isLoading && ! isError && reports . length > 0 && hasBookmarkedReports && (
216+ < div className = "reports-list-page__filter" >
217+ < div className = "reports-list-page__segment-wrapper" >
218+ < IonSegment value = { filter } onIonChange = { handleSegmentChange } mode = "ios" >
219+ < IonSegmentButton value = "all" >
220+ < IonLabel > { t ( 'list.filterAll' , { ns : 'report' } ) } </ IonLabel >
221+ </ IonSegmentButton >
222+ < IonSegmentButton value = "bookmarked" >
223+ < IonLabel > { t ( 'list.filterBookmarked' , { ns : 'report' } ) } </ IonLabel >
224+ </ IonSegmentButton >
225+ </ IonSegment >
226+ </ div >
213227 </ div >
214- </ div >
228+ ) }
215229 < div className = "reports-list-page__content" >
216230 < IonList className = "reports-list-page__list" lines = "none" >
217231 { renderReportsList ( ) }
0 commit comments