Skip to content

Commit

Permalink
frontend: userselectioncontext: Fix hooks so used in component
Browse files Browse the repository at this point in the history
Because rule of hooks. Fixes lint issue.
  • Loading branch information
illume committed Jan 17, 2024
1 parent 7adc851 commit a124be1
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions frontend/app/contexts/userselectioncontext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export const CensusDispatchContext = createContext<Dispatch<{ census: number | n
export const QuadratDispatchContext = createContext<Dispatch<{ quadrat: number | null }> | null>(null);

export default function PlotProvider({children}: { children: React.ReactNode }) {
const plotListContext = usePlotListContext();
const censusListContext = useCensusListContext();
const quadratListContext = useQuadratListContext();

const [plot, plotDispatch] = useReducer(
plotsReducer,
null
Expand Down Expand Up @@ -43,7 +47,6 @@ export default function PlotProvider({children}: { children: React.ReactNode })
}

function plotsReducer(currentPlot: any, action: { plotKey: string | null }) {
let plotListContext = usePlotListContext();
if (plotListContext) {
if (action.plotKey == null) return null;
else if (plotListContext.find((p) => p.key == action.plotKey)) return plotListContext.find((p) => p.key == action.plotKey);
Expand All @@ -56,7 +59,6 @@ function plotsReducer(currentPlot: any, action: { plotKey: string | null }) {
}

function censusReducer(currentCensus: any, action: { census: number | null }) {
let censusListContext = useCensusListContext();
if (censusListContext) {
if (action.census == null) return null;
else if (censusListContext.includes(action.census)) return action.census;
Expand All @@ -69,7 +71,6 @@ function censusReducer(currentCensus: any, action: { census: number | null }) {
}

function quadratReducer(currentQuadrat: any, action: { quadrat: number | null }) {
let quadratListContext = useQuadratListContext();
if (quadratListContext) {
if (action.quadrat == null) return null;
else if (quadratListContext.includes(action.quadrat)) return action.quadrat;
Expand Down

0 comments on commit a124be1

Please sign in to comment.