File tree Expand file tree Collapse file tree 3 files changed +30
-17
lines changed Expand file tree Collapse file tree 3 files changed +30
-17
lines changed Original file line number Diff line number Diff line change @@ -46,3 +46,8 @@ export const EVENT_STATUS_COLOR_MAP = {
4646 DEBUG : "gray" ,
4747 SUCCESS : "green" ,
4848} ;
49+
50+ export const LOCAL_STORAGE_KEYS = {
51+ CACHED_EVENTS : "cached_events" ,
52+ THEME : "theme" ,
53+ } ;
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import {
1111 SMTP ,
1212 VarDump ,
1313} from "~/config/types" ;
14- import { ALL_EVENTS , EVENT_TYPES } from "~/config/constants" ;
14+ import { ALL_EVENTS , EVENT_TYPES , LOCAL_STORAGE_KEYS } from "~/config/constants" ;
1515
1616type TCachedEventsEmptyMap = Record < OneOfValues < typeof EVENT_TYPES > , EventId [ ] > ;
1717
@@ -28,7 +28,7 @@ const initialCachedEventsIdsMap: TCachedEventsEmptyMap = {
2828
2929const { localStorage } = window ;
3030const getCachedEventsIdsMap = ( ) : TCachedEventsEmptyMap => {
31- const storageValue = localStorage ?. getItem ( "cached_events" ) ;
31+ const storageValue = localStorage ?. getItem ( LOCAL_STORAGE_KEYS . CACHED_EVENTS ) ;
3232
3333 if ( storageValue ) {
3434 return JSON . parse ( storageValue ) as TCachedEventsEmptyMap ;
@@ -99,7 +99,7 @@ export const useEventStore = defineStore("useEventStore", {
9999 } ) ;
100100
101101 localStorage ?. setItem (
102- "cached_events" ,
102+ LOCAL_STORAGE_KEYS . CACHED_EVENTS ,
103103 JSON . stringify ( this . cachedEventsIdsMap )
104104 ) ;
105105 } ,
@@ -109,7 +109,7 @@ export const useEventStore = defineStore("useEventStore", {
109109 this . cachedEventsIdsMap [ eventType ] . length = 0 ;
110110
111111 localStorage ?. setItem (
112- "cached_events" ,
112+ LOCAL_STORAGE_KEYS . CACHED_EVENTS ,
113113 JSON . stringify ( this . cachedEventsIdsMap )
114114 ) ;
115115 } ,
Original file line number Diff line number Diff line change 1- import { defineStore } from 'pinia' ;
1+ import { defineStore } from "pinia" ;
2+ import { LOCAL_STORAGE_KEYS } from "~/config/constants" ;
23
34export const THEME_MODES = {
4- LIGHT : ' light' ,
5- DARK : ' dark' ,
6- }
5+ LIGHT : " light" ,
6+ DARK : " dark" ,
7+ } ;
78
89const checkDarkTheme = ( ) => {
910 if ( process . client ) {
10- return window ?. localStorage . getItem ( 'theme' ) === THEME_MODES . DARK || window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches
11+ return (
12+ window ?. localStorage . getItem ( LOCAL_STORAGE_KEYS . THEME ) ===
13+ THEME_MODES . DARK ||
14+ window . matchMedia ( "(prefers-color-scheme: dark)" ) . matches
15+ ) ;
1116 }
1217
1318 return {
14- themeType : false
15- }
16- }
19+ themeType : false ,
20+ } ;
21+ } ;
1722
18- export const useThemeStore = defineStore ( ' themeStore' , {
23+ export const useThemeStore = defineStore ( " themeStore" , {
1924 state : ( ) => ( {
20- themeType : checkDarkTheme ( ) ? THEME_MODES . DARK : THEME_MODES . LIGHT
25+ themeType : checkDarkTheme ( ) ? THEME_MODES . DARK : THEME_MODES . LIGHT ,
2126 } ) ,
2227 actions : {
2328 themeChange ( ) {
24- const newType = this . themeType === THEME_MODES . DARK ? THEME_MODES . LIGHT : THEME_MODES . DARK ;
29+ const newType =
30+ this . themeType === THEME_MODES . DARK
31+ ? THEME_MODES . LIGHT
32+ : THEME_MODES . DARK ;
2533
26- window ?. localStorage . setItem ( 'theme' , newType ) ;
34+ window ?. localStorage . setItem ( LOCAL_STORAGE_KEYS . THEME , newType ) ;
2735 this . themeType = newType ;
2836 } ,
2937 } ,
30- } )
38+ } ) ;
You can’t perform that action at this time.
0 commit comments