state.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { defineStore } from "pinia";
  2. import { MainView, ColourScheme, PersonalEvent } from "../types";
  3. import { useStudenthubStore } from "./studenthub";
  4. import { TaughtClass } from "../api/types/semesters/versions/class";
  5. import { Module } from "../api/types/modules";
  6. const SELECTED_DEGREE_PROGRAM_KEY = "selectedDegreeProgram";
  7. const HIDE_COMPLETED_CLASSES_KEY = "hideCompletedClasses";
  8. window
  9. .matchMedia("(prefers-color-scheme: dark)")
  10. .addEventListener("change", (event) => {
  11. const stateStore = useStateStore();
  12. stateStore.colourScheme = event.matches
  13. ? ColourScheme.Dark
  14. : ColourScheme.Blinding;
  15. });
  16. export const useStateStore = defineStore("state", {
  17. state: () => {
  18. const colourScheme =
  19. window.matchMedia &&
  20. window.matchMedia("(prefers-color-scheme: dark)").matches
  21. ? ColourScheme.Dark
  22. : ColourScheme.Blinding;
  23. return {
  24. currentView: MainView.ModulePlanner,
  25. colourScheme: colourScheme,
  26. inspectingClass: null as TaughtClass | null,
  27. inspectingModule: null as Module | null,
  28. inspectingPersonalEvent: null as boolean | null | PersonalEvent,
  29. showingSettings: false,
  30. showingModuleSearch: false,
  31. showingClassUpgradeModal: false,
  32. showingOldPlanReminderModal: false,
  33. upgradingClassVersion: false,
  34. lastSelectedDegreeProgram:
  35. localStorage[SELECTED_DEGREE_PROGRAM_KEY] ?? "",
  36. __hideCompletedClasses: null as boolean | null,
  37. highlightBBModules: false,
  38. highlightVTModules: false,
  39. highlightFirstPhaseModules: false,
  40. highlightEnglishModules: false,
  41. highlightMSPModules: false,
  42. highlightContextModules: false,
  43. hasShownHelpWantedModal: false,
  44. };
  45. },
  46. getters: {
  47. hideCompletedClasses(): boolean {
  48. const studenthubStore = useStudenthubStore();
  49. if (!studenthubStore.hasAllStudenthubData) return false;
  50. if (this.__hideCompletedClasses != null)
  51. return this.__hideCompletedClasses;
  52. this.__hideCompletedClasses =
  53. localStorage[HIDE_COMPLETED_CLASSES_KEY] == "true";
  54. return this.__hideCompletedClasses;
  55. },
  56. hasHighlightedModules(): boolean {
  57. return (
  58. this.highlightBBModules ||
  59. this.highlightVTModules ||
  60. this.highlightFirstPhaseModules ||
  61. this.highlightEnglishModules ||
  62. this.highlightMSPModules ||
  63. this.highlightContextModules
  64. );
  65. },
  66. },
  67. actions: {
  68. updateLastSelectedDegreeProgram(prg: string) {
  69. localStorage[SELECTED_DEGREE_PROGRAM_KEY] = prg;
  70. },
  71. updateHideCompletedClasses(state: boolean) {
  72. localStorage[HIDE_COMPLETED_CLASSES_KEY] = state ? "true" : "false";
  73. this.__hideCompletedClasses = state;
  74. },
  75. },
  76. });