sushilideaclan01's picture
Add custom angle and concept refinement features
68556d7
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),
}));