All files / src/shared/stores searchDestination.store.ts

100% Statements 7/7
100% Branches 2/2
100% Functions 5/5
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24                    10x       10x     38x     520x 175x    
import { create } from 'zustand'
 
export interface SearchDestination {
  source?: 'notification'
  path: string
  keys: string[]
  query: string
  babyId: string | null
}
// Ephemeral handoff from global search to a feature page; never persisted.
export const useSearchDestinationStore = create<{
  revision: number
  target: SearchDestination | null
  set: (target: SearchDestination | null) => void
}>((set) => ({
  revision: 0,
  target: null,
  set: (target) => set((state) => ({ target, revision: state.revision + 1 })),
}))
export function useSearchDestination(path: string) {
  const target = useSearchDestinationStore((state) => state.target)
  return target?.path === path ? target : null
}