Skip to content

Commit

Permalink
move draft observation hooks to hooks directory
Browse files Browse the repository at this point in the history
  • Loading branch information
achou11 committed Dec 3, 2024
1 parent a4c5cc4 commit 4417065
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
24 changes: 2 additions & 22 deletions src/frontend/contexts/DraftObservationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ import React, {
useContext,
useState,
} from 'react';
import {
DraftState,
createDraftObservationStore,
} from '../hooks/persistedState/usePersistedDraftObservationNew';
import {useStore} from 'zustand';

import {createDraftObservationStore} from '../hooks/persistedState/usePersistedDraftObservationNew';

const DraftObservationContext = createContext<ReturnType<
typeof createDraftObservationStore
Expand All @@ -33,20 +30,3 @@ export function useDraftObservationContext() {

return result;
}

function defaultSelector(state: DraftState) {
return state;
}

export function useDraftObservation<S = DraftState>(
selector: (state: DraftState) => S = defaultSelector as any,
) {
const {store} = useDraftObservationContext();
const draftObservation = useStore(store, selector);
return draftObservation;
}

export function useDraftObservationActions() {
const {actions} = useDraftObservationContext();
return actions;
}
21 changes: 21 additions & 0 deletions src/frontend/hooks/draftObservation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {useStore} from 'zustand';

import {useDraftObservationContext} from '../contexts/DraftObservationContext';
import {DraftState} from '../hooks/persistedState/usePersistedDraftObservationNew';

function defaultSelector(state: DraftState) {
return state;
}

export function useDraftObservation<S = DraftState>(
selector: (state: DraftState) => S = defaultSelector as any,
) {
const {store} = useDraftObservationContext();
const draftObservation = useStore(store, selector);
return draftObservation;
}

export function useDraftObservationActions() {
const {actions} = useDraftObservationContext();
return actions;
}

0 comments on commit 4417065

Please sign in to comment.