38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import { defineStore } from 'pinia'
|
|
import { computed, ref } from 'vue'
|
|
|
|
const ACTIVE_ORG_KEY = 'crewli_active_org'
|
|
const ACTIVE_EVENT_KEY = 'crewli_active_event'
|
|
|
|
export const useOrganisationStore = defineStore('organisation', () => {
|
|
const activeOrganisationId = ref<string | null>(localStorage.getItem(ACTIVE_ORG_KEY))
|
|
const activeEventId = ref<string | null>(localStorage.getItem(ACTIVE_EVENT_KEY))
|
|
const hasOrganisation = computed(() => !!activeOrganisationId.value)
|
|
|
|
function setActiveOrganisation(id: string) {
|
|
activeOrganisationId.value = id
|
|
localStorage.setItem(ACTIVE_ORG_KEY, id)
|
|
}
|
|
|
|
function setActiveEvent(id: string) {
|
|
activeEventId.value = id
|
|
localStorage.setItem(ACTIVE_EVENT_KEY, id)
|
|
}
|
|
|
|
function clear() {
|
|
activeOrganisationId.value = null
|
|
activeEventId.value = null
|
|
localStorage.removeItem(ACTIVE_ORG_KEY)
|
|
localStorage.removeItem(ACTIVE_EVENT_KEY)
|
|
}
|
|
|
|
return {
|
|
activeOrganisationId,
|
|
activeEventId,
|
|
hasOrganisation,
|
|
setActiveOrganisation,
|
|
setActiveEvent,
|
|
clear,
|
|
}
|
|
})
|