Skip to content

Commit

Permalink
chore: fixed model background refetch
Browse files Browse the repository at this point in the history
  • Loading branch information
jeafreezy committed Nov 25, 2024
1 parent a603e6d commit dc4e544
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
10 changes: 5 additions & 5 deletions frontend/src/app/providers/models-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ const ModelsContext = createContext<{
validateEditMode: boolean;
}>({
formData: initialFormState,
setFormData: () => {},
handleChange: () => {},
setFormData: () => { },
handleChange: () => { },
createNewTrainingDatasetMutation: {} as UseMutationResult<
TTrainingDataset,
Error,
Expand All @@ -238,13 +238,13 @@ const ModelsContext = createContext<{
>,
hasLabeledTrainingAreas: false,
hasAOIsWithGeometry: false,
resetState: () => {},
resetState: () => { },
isEditMode: false,
modelId: "",
getFullPath: () => "",
handleModelCreationAndUpdate: () => {},
handleModelCreationAndUpdate: () => { },
trainingDatasetCreationInProgress: false,
handleTrainingDatasetCreation: () => {},
handleTrainingDatasetCreation: () => { },
validateEditMode: false,
});

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/routes/models/model-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const ModelDetailsPage = () => {
openDialog: openModelFilesDialog,
} = useDialog();
const navigate = useNavigate();
const { data, isPending, isError, error } = useModelDetails(id as string);
const { data, isPending, isError, error } = useModelDetails(id as string, id !== undefined, 10000);
const { user } = useAuth();

useEffect(() => {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/app/routes/start-mapping/start-mapping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const StartMappingPage = () => {
const { modelId } = useParams();
const { isError, isPending, data, error } = useModelDetails(
modelId as string,
modelId !== undefined
);
const navigate = useNavigate();
const { currentZoom } = useMap();
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/features/models/api/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ export const getModelsQueryOptions = ({
});
};

export const getModelDetailsQueryOptions = (id: string) => {
export const getModelDetailsQueryOptions = (id: string, refetchInterval: boolean | number) => {
return queryOptions({
queryKey: [queryKeys.MODEL_DETAILS(id)],
queryFn: () => getModelDetails(id),
refetchInterval: 10000,
//@ts-expect-error bad type definition
refetchInterval: refetchInterval
});
};

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/features/models/hooks/use-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export const useModels = ({
});
};

export const useModelDetails = (id: string, enabled: boolean = true) => {
export const useModelDetails = (id: string, enabled: boolean = true, refetchInterval: boolean | number = false) => {
return useQuery({
...getModelDetailsQueryOptions(id),
...getModelDetailsQueryOptions(id, refetchInterval),
//@ts-expect-error bad type definition
throwOnError: (error) => error.response?.status >= 500,
retry: (_, error) => {
Expand Down

0 comments on commit dc4e544

Please sign in to comment.