import { defineStore } from "pinia"; import { MainView, ColourScheme, PersonalEvent } from "../types"; import { useStudenthubStore } from "./studenthub"; import { TaughtClass } from "../api/types/semesters/versions/class"; import { Module } from "../api/types/modules"; const SELECTED_DEGREE_PROGRAM_KEY = "selectedDegreeProgram"; const HIDE_COMPLETED_CLASSES_KEY = "hideCompletedClasses"; window .matchMedia("(prefers-color-scheme: dark)") .addEventListener("change", (event) => { const stateStore = useStateStore(); stateStore.colourScheme = event.matches ? ColourScheme.Dark : ColourScheme.Blinding; }); export const useStateStore = defineStore("state", { state: () => { const colourScheme = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? ColourScheme.Dark : ColourScheme.Blinding; return { currentView: MainView.ModulePlanner, colourScheme: colourScheme, inspectingClass: null as TaughtClass | null, inspectingModule: null as Module | null, inspectingPersonalEvent: null as boolean | null | PersonalEvent, showingSettings: false, showingModuleSearch: false, showingClassUpgradeModal: false, showingOldPlanReminderModal: false, upgradingClassVersion: false, lastSelectedDegreeProgram: localStorage[SELECTED_DEGREE_PROGRAM_KEY] ?? "", __hideCompletedClasses: null as boolean | null, highlightBBModules: false, highlightVTModules: false, highlightFirstPhaseModules: false, highlightEnglishModules: false, highlightMSPModules: false, highlightContextModules: false, hasShownHelpWantedModal: false, }; }, getters: { hideCompletedClasses(): boolean { const studenthubStore = useStudenthubStore(); if (!studenthubStore.hasAllStudenthubData) return false; if (this.__hideCompletedClasses != null) return this.__hideCompletedClasses; this.__hideCompletedClasses = localStorage[HIDE_COMPLETED_CLASSES_KEY] == "true"; return this.__hideCompletedClasses; }, hasHighlightedModules(): boolean { return ( this.highlightBBModules || this.highlightVTModules || this.highlightFirstPhaseModules || this.highlightEnglishModules || this.highlightMSPModules || this.highlightContextModules ); }, }, actions: { updateLastSelectedDegreeProgram(prg: string) { localStorage[SELECTED_DEGREE_PROGRAM_KEY] = prg; }, updateHideCompletedClasses(state: boolean) { localStorage[HIDE_COMPLETED_CLASSES_KEY] = state ? "true" : "false"; this.__hideCompletedClasses = state; }, }, });