Skip to content

Commit

Permalink
Fix lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
MiraGeowerkstatt committed Dec 3, 2024
1 parent ce70ea4 commit d68e531
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/client/src/pages/detail/detailHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import DateText from "../../components/legacyComponents/dateText";
import { PromptContext } from "../../components/prompt/promptContext.tsx";
import { DetailHeaderStack } from "../../components/styledComponents.ts";
import { useFormDirty } from "./FormDirtyContext.tsx";
import { useFormDirty } from "./useFormDirty.tsx";

interface DetailHeaderProps {
editingEnabled: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/client/src/pages/detail/detailPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { DetailPageContent } from "./detailPageContent.tsx";
import { DetailSideNav } from "./detailSideNav.tsx";
import { BoreholeFormInputs } from "./form/borehole/boreholePanelInterfaces.ts";
import { LocationFormInputs, LocationFormSubmission } from "./form/location/locationPanelInterfaces.tsx";
import { FormDirtyProvider } from "./FormDirtyContext.tsx";
import { FormDirtyProvider } from "./formDirtyContext.tsx";
import { useLabelingContext } from "./labeling/labelingInterfaces.tsx";
import LabelingPanel from "./labeling/labelingPanel.tsx";
import { SaveBar } from "./saveBar";
Expand Down
2 changes: 1 addition & 1 deletion src/client/src/pages/detail/form/useFormWithSaveBar.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ForwardedRef, useCallback, useEffect, useImperativeHandle } from "react";
import { FieldValues, UseFormReturn } from "react-hook-form";
import { useHistory } from "react-router-dom";
import { useFormDirty } from "../FormDirtyContext.tsx";
import { useBlockNavigation } from "../useBlockNavigation.tsx";
import { useFormDirty } from "../useFormDirty.tsx";

interface UseFormWithSaveBarProps<T extends FieldValues> {
formMethods: UseFormReturn<T>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import React, { createContext, useContext, useState } from "react";
import React, { createContext, useState } from "react";

interface FormDirtyContextType {
isFormDirty: boolean;
setIsFormDirty: (dirty: boolean) => void;
}

const FormDirtyContext = createContext<FormDirtyContextType | undefined>(undefined);
export const FormDirtyContext = createContext<FormDirtyContextType | undefined>(undefined);

export const FormDirtyProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const [isFormDirty, setIsFormDirty] = useState(false);

return <FormDirtyContext.Provider value={{ isFormDirty, setIsFormDirty }}>{children}</FormDirtyContext.Provider>;
};

export const useFormDirty = () => {
const context = useContext(FormDirtyContext);
if (!context) throw new Error("useFormDirty must be used within a FormDirtyProvider");
return context;
};
2 changes: 1 addition & 1 deletion src/client/src/pages/detail/saveBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Box, Stack } from "@mui/material";
import { CircleCheck, CircleX } from "lucide-react";
import { theme } from "../../AppTheme.ts";
import { DeleteButton, SaveButton } from "../../components/buttons/buttons.tsx";
import { useFormDirty } from "./FormDirtyContext.tsx";
import { useFormDirty } from "./useFormDirty.tsx";

interface SaveBarProps {
triggerSubmit: () => void;
Expand Down
2 changes: 1 addition & 1 deletion src/client/src/pages/detail/useBlockNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useTranslation } from "react-i18next";
import { useHistory } from "react-router-dom";
import { Trash2, X } from "lucide-react";
import { PromptContext } from "../../components/prompt/promptContext.tsx";
import { useFormDirty } from "./FormDirtyContext.tsx";
import { useFormDirty } from "./useFormDirty.tsx";

interface UseBlockNavigationResult {
handleBlockedNavigation: (nextLocation: string) => boolean;
Expand Down
10 changes: 10 additions & 0 deletions src/client/src/pages/detail/useFormDirty.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { useContext } from "react";
import { FormDirtyContext } from "./formDirtyContext.tsx";

export const useFormDirty = () => {
const context = useContext(FormDirtyContext);
if (!context) {
throw new Error("useFormDirty must be used within a FormDirtyProvider");
}
return context;
};

0 comments on commit d68e531

Please sign in to comment.