analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
1 lines • 3.09 kB
Source Map (JSON)
{"version":3,"sources":["../src/store/comparatorStore.ts"],"sourcesContent":["import { create } from 'zustand';\nimport { createJSONStorage, persist } from 'zustand/middleware';\nimport type { ComparisonItem, ComparatorStoreState } from '../types/comparator';\nimport { COMPARATOR_CHART_COLORS } from '../types/comparator';\n\nexport interface CreateComparatorStoreConfig {\n storageKey?: string;\n chartColors?: string[];\n}\n\nexport function createComparatorStore(\n config: CreateComparatorStoreConfig = {}\n) {\n const {\n storageKey = 'comparator-storage',\n chartColors = COMPARATOR_CHART_COLORS,\n } = config;\n\n return create<ComparatorStoreState>()(\n persist(\n (set, get) => ({\n comparisonType: null,\n selectedItems: [],\n\n setComparisonType: (type) => set({ comparisonType: type }),\n\n setSelectedItems: (items) => set({ selectedItems: items }),\n\n addItem: (item) => {\n const { selectedItems } = get();\n if (selectedItems.length >= 5) return;\n if (selectedItems.some((i) => i.id === item.id)) return;\n\n const newItem: ComparisonItem = {\n ...item,\n color: chartColors[selectedItems.length],\n };\n\n set({ selectedItems: [...selectedItems, newItem] });\n },\n\n removeItem: (itemId) => {\n const { selectedItems } = get();\n const newItems = selectedItems\n .filter((i) => i.id !== itemId)\n .map((item, idx) => ({\n ...item,\n color: chartColors[idx],\n }));\n\n set({ selectedItems: newItems });\n },\n\n clearSelection: () =>\n set({\n comparisonType: null,\n selectedItems: [],\n }),\n }),\n {\n name: storageKey,\n storage: createJSONStorage(() => localStorage),\n }\n )\n );\n}\n\n// Default store instance\nexport const useComparatorStore = createComparatorStore();\n"],"mappings":";;;;;AAAA,SAAS,cAAc;AACvB,SAAS,mBAAmB,eAAe;AASpC,SAAS,sBACd,SAAsC,CAAC,GACvC;AACA,QAAM;AAAA,IACJ,aAAa;AAAA,IACb,cAAc;AAAA,EAChB,IAAI;AAEJ,SAAO,OAA6B;AAAA,IAClC;AAAA,MACE,CAAC,KAAK,SAAS;AAAA,QACb,gB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