Skip to content

Commit ac1286b

Browse files
committed
Rename fetch functions to use hooks
1 parent 63daae0 commit ac1286b

3 files changed

Lines changed: 18 additions & 21 deletions

File tree

frontend/src/components/Contexts/InspectionsContext.tsx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ interface IValueData {
1616
isError: boolean
1717
}
1818
interface IInspectionsContext {
19-
fetchImageData: (inspectionId: string) => IImageData
20-
fetchAnalysisData: (inspectionId: string) => IImageData
21-
fetchValueData: (inspectionId: string) => IValueData
19+
useImageData: (inspectionId: string) => IImageData
20+
useAnalysisData: (inspectionId: string) => IImageData
21+
useValueData: (inspectionId: string) => IValueData
2222
}
2323

2424
interface Props {
2525
children: React.ReactNode
2626
}
2727

2828
const defaultInspectionsContext = {
29-
fetchImageData: () => ({ data: undefined, isPending: false, isError: true }),
30-
fetchAnalysisData: () => ({ data: undefined, isPending: false, isError: true }),
31-
fetchValueData: () => ({ data: undefined, isPending: false, isError: true }),
29+
useImageData: () => ({ data: undefined, isPending: false, isError: true }),
30+
useAnalysisData: () => ({ data: undefined, isPending: false, isError: true }),
31+
useValueData: () => ({ data: undefined, isPending: false, isError: true }),
3232
}
3333

3434
const InspectionsContext = createContext<IInspectionsContext>(defaultInspectionsContext)
@@ -85,8 +85,7 @@ export const InspectionsProvider: FC<Props> = ({ children }) => {
8585
}
8686
}, [registerEvent, connectionReady])
8787

88-
const fetchImageData = (inspectionId: string): IImageData => {
89-
// eslint-disable-next-line react-hooks/rules-of-hooks -- pre-existing design issue, tracked in #2698
88+
const useImageData = (inspectionId: string): IImageData => {
9089
const result = useQuery({
9190
queryKey: ['fetchInspectionData', inspectionId],
9291
queryFn: async () => {
@@ -101,8 +100,7 @@ export const InspectionsProvider: FC<Props> = ({ children }) => {
101100
return { data: result.data, isPending: result.isPending, isError: result.isError }
102101
}
103102

104-
const fetchAnalysisData = (inspectionId: string): IImageData => {
105-
// eslint-disable-next-line react-hooks/rules-of-hooks -- pre-existing design issue, tracked in #2698
103+
const useAnalysisData = (inspectionId: string): IImageData => {
106104
const result = useQuery({
107105
queryKey: ['fetchAnalysisData', inspectionId],
108106
queryFn: async () => {
@@ -116,8 +114,7 @@ export const InspectionsProvider: FC<Props> = ({ children }) => {
116114
return { data: result.data, isPending: result.isPending, isError: result.isError }
117115
}
118116

119-
const fetchValueData = (inspectionId: string): IValueData => {
120-
// eslint-disable-next-line react-hooks/rules-of-hooks -- pre-existing design issue, tracked in #2698
117+
const useValueData = (inspectionId: string): IValueData => {
121118
const result = useQuery({
122119
queryKey: ['fetchValueData', inspectionId],
123120
queryFn: async () => {
@@ -134,9 +131,9 @@ export const InspectionsProvider: FC<Props> = ({ children }) => {
134131
return (
135132
<InspectionsContext.Provider
136133
value={{
137-
fetchImageData,
138-
fetchAnalysisData,
139-
fetchValueData,
134+
useImageData,
135+
useAnalysisData,
136+
useValueData,
140137
}}
141138
>
142139
{children}

frontend/src/pages/InspectionReportPage/InspectionReportImage.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ export const PendingResultPlaceholder = ({ isLargeImage }: { isLargeImage: boole
8181
}
8282

8383
const InspectionImageWithPlaceholder = ({ task, isLargeImage }: { task: Task; isLargeImage: boolean }) => {
84-
const { fetchImageData } = useInspectionsContext()
85-
const { data, isPending, isError } = fetchImageData(task.inspection.isarInspectionId)
84+
const { useImageData } = useInspectionsContext()
85+
const { data, isPending, isError } = useImageData(task.inspection.isarInspectionId)
8686
if (isError || !data) {
8787
const errorMsg = 'No inspection could be found'
8888
return <TextAsImage isLargeImage={isLargeImage} text={errorMsg} />
@@ -97,8 +97,8 @@ const InspectionImageWithPlaceholder = ({ task, isLargeImage }: { task: Task; is
9797
}
9898

9999
const InspectionValueWithPlaceholder = ({ task, isLargeImage }: { task: Task; isLargeImage: boolean }) => {
100-
const { fetchValueData } = useInspectionsContext()
101-
const { data, isPending, isError } = fetchValueData(task.inspection.isarInspectionId)
100+
const { useValueData } = useInspectionsContext()
101+
const { data, isPending, isError } = useValueData(task.inspection.isarInspectionId)
102102

103103
if (isError || data === undefined) {
104104
const errorMsg = 'No inspection could be found'

frontend/src/pages/MissionPage/AnalysisResultView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ const StyledImage = styled.img<{ $otherContentHeight?: string }>`
2727
border: none;
2828
`
2929
const AnalysisImage = ({ inspectionId }: { inspectionId: string }) => {
30-
const { fetchAnalysisData } = useInspectionsContext()
31-
const { data, isPending } = fetchAnalysisData(inspectionId)
30+
const { useAnalysisData } = useInspectionsContext()
31+
const { data, isPending } = useAnalysisData(inspectionId)
3232

3333
if (isPending) return <PendingResultPlaceholder isLargeImage={true} />
3434
if (!data) return <TextAsImage isLargeImage={true} text="No inspection could be found" />

0 commit comments

Comments
 (0)