analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
53 lines (52 loc) • 1.51 kB
JavaScript
// src/store/appStore.ts
import { create } from "zustand";
import { createJSONStorage, persist } from "zustand/middleware";
var useAppStore = create()(
persist(
(set, get) => ({
institutionId: null,
initialized: false,
/**
* Set the institution ID
* @param {string | null} institutionId - The institution ID from meta tag
* @returns {void}
*/
setInstitutionId: (institutionId) => {
set({ institutionId });
},
/**
* Set the initialized state
* @param {boolean} initialized - Whether the app has been initialized
* @returns {void}
*/
setInitialized: (initialized) => {
set({ initialized });
},
/**
* Initialize the app by reading the institution ID from meta tag.
* The meta tag is the source of truth on each load: if the incoming
* id differs from the persisted one (e.g. institution changed since
* the last session), it overwrites the stale value.
* @returns {void}
*/
initialize: (id) => {
const { initialized, institutionId } = get();
if (initialized && institutionId === id) {
return;
}
set({
institutionId: id,
initialized: true
});
}
}),
{
name: "@app-storage:analytica:v2" /* APP_STORAGE */,
storage: createJSONStorage(() => localStorage)
}
)
);
export {
useAppStore
};
//# sourceMappingURL=chunk-C2KAIQ4I.mjs.map