Skip to content

Commit 6e05f2a

Browse files
committed
Enhance report handling and data fetching:
- Update markReportAsRead to include auth config in the request. - Modify useGetLatestReports to always refetch data on mount and window focus. - Improve ProcessingPage to handle response and redirect upon processing completion. - Add location tracking in ReportsListPage to refetch reports on navigation.
1 parent 66e62c7 commit 6e05f2a

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

frontend/src/common/api/reportService.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,13 @@ export const fetchAllReports = async (): Promise<MedicalReport[]> => {
141141
*/
142142
export const markReportAsRead = async (reportId: string): Promise<MedicalReport> => {
143143
try {
144-
const response = await axios.patch(`${API_URL}/api/reports/${reportId}`, {
145-
status: 'READ',
146-
});
144+
const response = await axios.patch(
145+
`${API_URL}/api/reports/${reportId}`,
146+
{
147+
status: 'READ',
148+
},
149+
await getAuthConfig(),
150+
);
147151

148152
return response.data;
149153
} catch (error) {

frontend/src/common/hooks/useReports.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export const useGetLatestReports = (limit = 3) => {
1515
return useQuery({
1616
queryKey: [LATEST_REPORTS_KEY, limit],
1717
queryFn: () => fetchLatestReports(limit),
18+
refetchOnMount: true,
19+
refetchOnWindowFocus: true,
20+
staleTime: 0, // Consider data immediately stale so it always refreshes
1821
});
1922
};
2023

frontend/src/pages/Processing/ProcessingPage.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,21 @@ const ProcessingPage: React.FC = () => {
8282

8383
try {
8484
// Send POST request to backend API
85-
await axios.post(
85+
const response = await axios.post(
8686
`${API_URL}/api/document-processor/process-file`,
8787
{ reportId },
8888
await getAuthConfig(),
8989
);
9090

91+
const data = response.data;
92+
93+
if (data.status === 'processed') {
94+
setIsProcessing(false);
95+
96+
// Redirect to report detail page
97+
history.push(`/tabs/reports/${reportId}`);
98+
}
99+
91100
// Start checking the status every 2 seconds
92101
statusCheckIntervalRef.current = window.setInterval(checkReportStatus, 2000);
93102
} catch (error) {

frontend/src/pages/Reports/ReportsListPage.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
IonModal,
1616
} from '@ionic/react';
1717
import { useTranslation } from 'react-i18next';
18-
import { useHistory } from 'react-router-dom';
18+
import { useHistory, useLocation } from 'react-router-dom';
1919
import { useQuery, useQueryClient } from '@tanstack/react-query';
2020
import { fetchAllReports, toggleReportBookmark } from 'common/api/reportService';
2121
import { useMarkReportAsRead } from 'common/hooks/useReports';
@@ -40,6 +40,7 @@ type SortDirection = 'desc' | 'asc';
4040
const ReportsListPage: React.FC = () => {
4141
const { t } = useTranslation(['report', 'common']);
4242
const history = useHistory();
43+
const location = useLocation();
4344
const queryClient = useQueryClient();
4445
const [filter, setFilter] = useState<FilterOption>('all');
4546
const [sortDirection, setSortDirection] = useState<SortDirection>('desc'); // Default sort by newest first
@@ -61,11 +62,19 @@ const ReportsListPage: React.FC = () => {
6162
data: reports = [],
6263
isLoading,
6364
isError,
65+
refetch,
6466
} = useQuery({
6567
queryKey: ['reports'],
6668
queryFn: fetchAllReports,
69+
refetchOnMount: true,
6770
});
6871

72+
// Refetch reports when navigating to this page
73+
useEffect(() => {
74+
// This will run when the component mounts or when the location changes
75+
refetch();
76+
}, [location.pathname, refetch]);
77+
6978
const { mutate: markAsRead } = useMarkReportAsRead();
7079

7180
// Filter and sort reports based on selected filter, categories, and sort direction

0 commit comments

Comments
 (0)