All files / src/hooks useNavigationState.ts

100% Statements 8/8
100% Branches 0/0
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 25 26 27 28                4x   65x     111x 111x   33x                      
import { NAVIGATION_STATE } from "../const";
import { NavigationState } from "../type";
import { create } from "zustand";
interface NavigationStateStore {
  navigationState: NavigationState;
  setNavigationState: (state: NavigationState) => void;
}
 
export const useNavigationStore = create<NavigationStateStore>((set) => ({
  navigationState: NAVIGATION_STATE.IDLE,
  setNavigationState: (state) => set({ navigationState: state }),
}));
export default function useNavigationState() {
  const navigationState = useNavigationStore((s) => s.navigationState);
  const setNavigationState = useNavigationStore((s) => s.setNavigationState);
 
  return {
    navigationState,
    setNavigationState,
    isIdle: navigationState === NAVIGATION_STATE.IDLE,
    isConfiguring: navigationState === NAVIGATION_STATE.ROUTE_CONFIGURING,
    isNavigating: navigationState === NAVIGATION_STATE.NAVIGATING,
    isCancellingNavigation:
      navigationState === NAVIGATION_STATE.NAVIGATION_CANCELLING,
    isSearching: navigationState === NAVIGATION_STATE.SEARCHING,
  };
}