File size: 4,122 Bytes
f201243
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68556d7
 
 
 
 
 
 
 
 
 
f201243
 
 
 
 
 
 
 
 
68556d7
 
 
 
 
 
 
 
 
 
 
 
 
f201243
 
 
 
 
 
 
 
 
 
 
 
 
68556d7
 
 
 
 
 
 
 
 
f201243
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68556d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f201243
 
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { create } from "zustand";
import type { AngleInfo, ConceptInfo, AnglesResponse, ConceptsResponse } from "../types/api";
import type { MatrixFilters } from "../types/matrix";

interface MatrixState {
  angles: AnglesResponse | null;
  concepts: ConceptsResponse | null;
  selectedAngle: AngleInfo | null;
  selectedConcept: ConceptInfo | null;
  compatibleConcepts: ConceptInfo[];
  angleFilters: MatrixFilters;
  conceptFilters: MatrixFilters;
  isLoading: boolean;
  error: string | null;
  
  // Custom angle/concept state
  customAngleText: string;
  customConceptText: string;
  customAngleRefined: AngleInfo | null;
  customConceptRefined: ConceptInfo | null;
  isRefiningAngle: boolean;
  isRefiningConcept: boolean;
  useCustomAngle: boolean;
  useCustomConcept: boolean;
  
  setAngles: (angles: AnglesResponse) => void;
  setConcepts: (concepts: ConceptsResponse) => void;
  setSelectedAngle: (angle: AngleInfo | null) => void;
  setSelectedConcept: (concept: ConceptInfo | null) => void;
  setCompatibleConcepts: (concepts: ConceptInfo[]) => void;
  setAngleFilters: (filters: Partial<MatrixFilters>) => void;
  setConceptFilters: (filters: Partial<MatrixFilters>) => void;
  setIsLoading: (isLoading: boolean) => void;
  setError: (error: string | null) => void;
  
  // Custom angle/concept setters
  setCustomAngleText: (text: string) => void;
  setCustomConceptText: (text: string) => void;
  setCustomAngleRefined: (angle: AngleInfo | null) => void;
  setCustomConceptRefined: (concept: ConceptInfo | null) => void;
  setIsRefiningAngle: (isRefining: boolean) => void;
  setIsRefiningConcept: (isRefining: boolean) => void;
  setUseCustomAngle: (use: boolean) => void;
  setUseCustomConcept: (use: boolean) => void;
  clearCustomAngle: () => void;
  clearCustomConcept: () => void;
  
  reset: () => void;
}

const initialState = {
  angles: null,
  concepts: null,
  selectedAngle: null,
  selectedConcept: null,
  compatibleConcepts: [],
  angleFilters: {},
  conceptFilters: {},
  isLoading: false,
  error: null,
  // Custom state
  customAngleText: "",
  customConceptText: "",
  customAngleRefined: null,
  customConceptRefined: null,
  isRefiningAngle: false,
  isRefiningConcept: false,
  useCustomAngle: false,
  useCustomConcept: false,
};

export const useMatrixStore = create<MatrixState>((set) => ({
  ...initialState,
  
  setAngles: (angles) => set({ angles }),
  
  setConcepts: (concepts) => set({ concepts }),
  
  setSelectedAngle: (angle) => set({ selectedAngle: angle }),
  
  setSelectedConcept: (concept) => set({ selectedConcept: concept }),
  
  setCompatibleConcepts: (concepts) => set({ compatibleConcepts: concepts }),
  
  setAngleFilters: (filters) => set((state) => ({
    angleFilters: { ...state.angleFilters, ...filters },
  })),
  
  setConceptFilters: (filters) => set((state) => ({
    conceptFilters: { ...state.conceptFilters, ...filters },
  })),
  
  setIsLoading: (isLoading) => set({ isLoading }),
  
  setError: (error) => set({ error }),
  
  // Custom angle/concept setters
  setCustomAngleText: (text) => set({ customAngleText: text }),
  
  setCustomConceptText: (text) => set({ customConceptText: text }),
  
  setCustomAngleRefined: (angle) => set({ customAngleRefined: angle }),
  
  setCustomConceptRefined: (concept) => set({ customConceptRefined: concept }),
  
  setIsRefiningAngle: (isRefining) => set({ isRefiningAngle: isRefining }),
  
  setIsRefiningConcept: (isRefining) => set({ isRefiningConcept: isRefining }),
  
  setUseCustomAngle: (use) => set({ 
    useCustomAngle: use,
    // Clear selected angle if switching to custom
    selectedAngle: use ? null : null,
  }),
  
  setUseCustomConcept: (use) => set({ 
    useCustomConcept: use,
    // Clear selected concept if switching to custom
    selectedConcept: use ? null : null,
  }),
  
  clearCustomAngle: () => set({
    customAngleText: "",
    customAngleRefined: null,
    useCustomAngle: false,
  }),
  
  clearCustomConcept: () => set({
    customConceptText: "",
    customConceptRefined: null,
    useCustomConcept: false,
  }),
  
  reset: () => set(initialState),
}));