analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
1 lines • 2.74 kB
Source Map (JSON)
{"version":3,"sources":["../src/store/appStore.ts"],"sourcesContent":["import { create } from 'zustand';\nimport { createJSONStorage, persist } from 'zustand/middleware';\nimport { KEYS } from '@/utils/keys';\n\n/**\n * Interface defining the application state\n */\ninterface AppState {\n institutionId: string | null;\n initialized: boolean;\n\n setInstitutionId: (institutionId: string | null) => void;\n setInitialized: (initialized: boolean) => void;\n initialize: (id: string | null) => void;\n}\n\n/**\n * Zustand store for managing application-wide state with persistence\n * @returns {AppState} The application state store\n */\nexport const useAppStore = create<AppState>()(\n persist(\n (set, get) => ({\n institutionId: null,\n initialized: false,\n\n /**\n * Set the institution ID\n * @param {string | null} institutionId - The institution ID from meta tag\n * @returns {void}\n */\n setInstitutionId: (institutionId: string | null): void => {\n set({ institutionId });\n },\n\n /**\n * Set the initialized state\n * @param {boolean} initialized - Whether the app has been initialized\n * @returns {void}\n */\n setInitialized: (initialized: boolean): void => {\n set({ initialized });\n },\n\n /**\n * Initialize the app by reading the institution ID from meta tag.\n * The meta tag is the source of truth on each load: if the incoming\n * id differs from the persisted one (e.g. institution changed since\n * the last session), it overwrites the stale value.\n * @returns {void}\n */\n initialize: (id: string | null): void => {\n const { initialized, institutionId } = get();\n\n if (initialized && institutionId === id) {\n return; // Already initialized with the same institution\n }\n\n set({\n institutionId: id,\n initialized: true,\n });\n },\n }),\n {\n name: KEYS.APP_STORAGE,\n storage: createJSONStorage(() => localStorage),\n }\n )\n);\n"],"mappings":";AAAA,SAAS,cAAc;AACvB,SAAS,mBAAmB,eAAe;AAmBpC,IAAM,cAAc,OAAiB;AAAA,EAC1C;AAAA,IACE,CAAC,KAAK,SAAS;AAAA,MACb,eAAe;AAAA,MACf,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAOb,kBAAkB,CAAC,kBAAuC;AACxD,YAAI,EAAE,cAAc,CAAC;AAAA,MACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAOA,gBAAgB,CAAC,gBAA+B;AAC9C,YAAI,EAAE,YAAY,CAAC;AAAA,MACrB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MASA,YAAY,CAAC,OAA4B;AACvC,cAAM,EAAE,aAAa,cAAc,IAAI,IAAI;AAE3C,YAAI,eAAe,kBAAkB,IAAI;AACvC;AAAA,QACF;AAEA,YAAI;AAAA,UACF,eAAe;AAAA,UACf,aAAa;AAAA,QACf,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA,SAAS,kBAAkB,MAAM,YAAY;AAAA,IAC/C;AAAA,EACF;AACF;","names":[]}