All files / components/screens/philosophy/hooks usePhilosophyState.ts

100% Statements 10/10
100% Branches 0/0
100% Functions 4/4
100% Lines 10/10

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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89                                                                                            16x     16x             16x 5x               16x 1x               16x 2x   2x     16x                
import { useCallback, useState } from "react";
import { TrigramStance } from "../../../../types";
 
/**
 * Philosophy topic types for navigation
 * 
 * **Korean**: 철학 주제
 */
export type PhilosophyTopic = "trigrams" | "values" | "archetypes";
 
/**
 * Philosophy screen state management hook
 * 
 * **Korean**: 철학 화면 상태 관리 훅
 * 
 * Manages the state for the Philosophy Screen including:
 * - Selected trigram for detailed view
 * - Current topic being viewed
 * - Navigation between different philosophy sections
 * 
 * @example
 * ```typescript
 * const {
 *   selectedTrigram,
 *   topic,
 *   selectTrigram,
 *   setTopic,
 *   clearSelection
 * } = usePhilosophyState();
 * 
 * // Select a trigram
 * selectTrigram(TrigramStance.GEON);
 * 
 * // Change topic
 * setTopic("values");
 * 
 * // Clear selection
 * clearSelection();
 * ```
 * 
 * @returns Philosophy state and control functions
 * 
 * @public
 * @category Philosophy Hooks
 */
export function usePhilosophyState() {
  const [selectedTrigram, setSelectedTrigram] = useState<TrigramStance | null>(
    null
  );
  const [topic, setTopicInternal] = useState<PhilosophyTopic>("trigrams");
 
  /**
   * Select a trigram for detailed view
   * 
   * **Korean**: 트라이그램 선택
   */
  const selectTrigram = useCallback((stance: TrigramStance) => {
    setSelectedTrigram(stance);
  }, []);
 
  /**
   * Clear trigram selection
   * 
   * **Korean**: 선택 해제
   */
  const clearSelection = useCallback(() => {
    setSelectedTrigram(null);
  }, []);
 
  /**
   * Change the current philosophy topic
   * 
   * **Korean**: 주제 변경
   */
  const setTopic = useCallback((newTopic: PhilosophyTopic) => {
    setTopicInternal(newTopic);
    // Clear selection when changing topics
    setSelectedTrigram(null);
  }, []);
 
  return {
    selectedTrigram,
    topic,
    selectTrigram,
    clearSelection,
    setTopic,
  };
}