Skip to content

Commit 6c6ecbe

Browse files
authored
Merge pull request #193 from buggregator/improve/polish-settings-store
polish names of functions to sync with localstorage
2 parents dcc7f48 + d2ccd16 commit 6c6ecbe

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

src/shared/stores/events/events-store.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { defineStore } from "pinia";
22
import {PAGE_TYPES} from "../../constants";
33
import type { EventId, EventType , ServerEvent, TEventsGroup} from '../../types';
44
import {EVENT_TYPES} from "../../types";
5-
import { getLockedIds, syncCachedIdsLocalStorage, syncLockedIdsLocalStorage, getCachedIds } from "./local-storage-actions";
5+
import { getStoredLockedIds, setStoredCachedIds, setStoredLockedIds, getStoredCachedIds } from "./local-storage-actions";
66
import type {TEventsCachedIdsMap} from "./types";
77

88
const MAX_EVENTS_COUNT = 500;
@@ -22,8 +22,8 @@ const initialCachedIds: TEventsCachedIdsMap = {
2222
export const useEventsStore = defineStore("eventsStore", {
2323
state: () => ({
2424
events: [] as ServerEvent<unknown>[],
25-
cachedIds: getCachedIds() || initialCachedIds,
26-
lockedIds: getLockedIds() || [],
25+
cachedIds: getStoredCachedIds() || initialCachedIds,
26+
lockedIds: getStoredLockedIds() || [],
2727
}),
2828
getters: {
2929
eventsCounts: ({events}) => (eventType: EVENT_TYPES | undefined): number => {
@@ -118,11 +118,11 @@ export const useEventsStore = defineStore("eventsStore", {
118118
this.cachedIds[cachedType].push(event.uuid);
119119
});
120120

121-
syncCachedIdsLocalStorage(this.cachedIds);
121+
setStoredCachedIds(this.cachedIds);
122122
},
123123
removeCachedByType(type: TEventsGroup) {
124124
this.cachedIds[type].length = 0;
125-
syncCachedIdsLocalStorage(this.cachedIds);
125+
setStoredCachedIds(this.cachedIds);
126126
},
127127
removeCachedByIds(uuids: EventId[]) {
128128
this.cachedIdsTypesList.forEach((type) => {
@@ -131,14 +131,14 @@ export const useEventsStore = defineStore("eventsStore", {
131131
);
132132
});
133133

134-
syncCachedIdsLocalStorage(this.cachedIds);
134+
setStoredCachedIds(this.cachedIds);
135135
},
136136
removeCachedById(eventUuid: EventId) {
137137
this.removeCachedByIds([eventUuid]);
138138
},
139139
removeCachedAll() {
140140
this.cachedIds = initialCachedIds;
141-
syncCachedIdsLocalStorage(this.cachedIds);
141+
setStoredCachedIds(this.cachedIds);
142142
},
143143
syncCachedWithActive(activeIds: EventId[]) {
144144
if (!activeIds.length) {
@@ -153,18 +153,18 @@ export const useEventsStore = defineStore("eventsStore", {
153153
);
154154
});
155155

156-
syncCachedIdsLocalStorage(this.cachedIds);
156+
setStoredCachedIds(this.cachedIds);
157157
},
158158
// locked ids
159159
removeLockedIds(eventUuid: EventId) {
160160
this.lockedIds = this.lockedIds.filter((id) => id !== eventUuid);
161161

162-
syncLockedIdsLocalStorage(this.lockedIds);
162+
setStoredLockedIds(this.lockedIds);
163163
},
164164
addLockedIds(eventUuid: EventId) {
165165
this.lockedIds.push(eventUuid);
166166

167-
syncLockedIdsLocalStorage(this.lockedIds);
167+
setStoredLockedIds(this.lockedIds);
168168
}
169169
},
170170
});

src/shared/stores/events/local-storage-actions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {TEventsCachedIdsMap} from "./types";
33

44
const { localStorage } = window;
55

6-
export const getCachedIds = (): TEventsCachedIdsMap | null => {
6+
export const getStoredCachedIds = (): TEventsCachedIdsMap | null => {
77
const storageValue = localStorage?.getItem(LOCAL_STORAGE_KEYS.CACHED_EVENTS);
88

99
if (storageValue) {
@@ -13,12 +13,12 @@ export const getCachedIds = (): TEventsCachedIdsMap | null => {
1313
return null;
1414
};
1515

16-
export const syncCachedIdsLocalStorage = (cachedEventMap: TEventsCachedIdsMap) => {
16+
export const setStoredCachedIds = (cachedEventMap: TEventsCachedIdsMap) => {
1717
localStorage?.setItem(LOCAL_STORAGE_KEYS.CACHED_EVENTS, JSON.stringify(cachedEventMap));
1818
}
1919

2020

21-
export const getLockedIds = (): EventId[] | null => {
21+
export const getStoredLockedIds = (): EventId[] | null => {
2222
const storageValue = localStorage?.getItem(LOCAL_STORAGE_KEYS.LOCKED_EVENTS);
2323

2424
if (storageValue) {
@@ -28,6 +28,6 @@ export const getLockedIds = (): EventId[] | null => {
2828
return null;
2929
};
3030

31-
export const syncLockedIdsLocalStorage = (lockedIds: EventId[]) => {
31+
export const setStoredLockedIds = (lockedIds: EventId[]) => {
3232
localStorage?.setItem(LOCAL_STORAGE_KEYS.LOCKED_EVENTS, JSON.stringify(lockedIds));
3333
}

src/shared/stores/settings/local-storage-actions.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {LOCAL_STORAGE_KEYS} from "../../types";
22
import {THEME_MODES} from "./constants";
33

4-
export const checkIfThemeActive = () => {
4+
export const getStoredActiveTheme = () => {
55
if (!process.client) {
66
return THEME_MODES.LIGHT;
77
}
@@ -20,7 +20,7 @@ export const checkIfThemeActive = () => {
2020
return THEME_MODES.LIGHT
2121
};
2222

23-
export const syncThemeLocalStorage = (themeName: string) => {
23+
export const setStoredActiveTheme = (themeName: string) => {
2424
window?.localStorage.setItem(LOCAL_STORAGE_KEYS.THEME, themeName);
2525

2626
if (themeName === THEME_MODES.LIGHT) {
@@ -30,7 +30,7 @@ export const syncThemeLocalStorage = (themeName: string) => {
3030
}
3131
}
3232

33-
export const getFixedHeaderState = () => {
33+
export const getStoredFixedHeader = () => {
3434
if (!process.client) {
3535
return false;
3636
}
@@ -48,7 +48,7 @@ export const getFixedHeaderState = () => {
4848
return isFixed;
4949
}
5050

51-
export const syncFixedHeaderLocalStorage = (state: boolean) => {
51+
export const setStoredFixedHeader = (state: boolean) => {
5252
window?.localStorage.setItem(LOCAL_STORAGE_KEYS.NAVBAR, String(state));
5353

5454
if (state) {
@@ -58,23 +58,23 @@ export const syncFixedHeaderLocalStorage = (state: boolean) => {
5858
}
5959
}
6060

61-
export const getEventsCountVisibleState = (): boolean => {
61+
export const getStoredEventsCountVisibility = (): boolean => {
6262
const storageValue = window?.localStorage?.getItem(LOCAL_STORAGE_KEYS.EVENT_COUNTS) || "true";
6363

6464
return storageValue === "true";
6565
};
6666

67-
export const syncEventsCountVisibleLocalStorage = (state: boolean) => {
67+
export const setStoredEventsCountVisibility = (state: boolean) => {
6868
window?.localStorage?.setItem(LOCAL_STORAGE_KEYS.EVENT_COUNTS, String(state));
6969
}
7070

7171

72-
export const getActiveCodeEditorState = (): string => {
72+
export const getStoredPrimaryCodeEditor = (): string => {
7373
const storedCodeEditor = window?.localStorage?.getItem(LOCAL_STORAGE_KEYS.CODE_EDITOR);
7474

7575
return storedCodeEditor || '';
7676
};
7777

78-
export const setActiveCodeEditorState = (editor: string) => {
78+
export const setStoredPrimaryCodeEditor = (editor: string) => {
7979
window?.localStorage?.setItem(LOCAL_STORAGE_KEYS.CODE_EDITOR, editor);
8080
}

src/shared/stores/settings/settings-store.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import {useSettings} from "../../lib/use-settings";
33
import type { TSettings } from "../../types";
44
import {THEME_MODES} from "./constants";
55
import {
6-
getEventsCountVisibleState,
7-
getFixedHeaderState,
8-
checkIfThemeActive,
9-
syncEventsCountVisibleLocalStorage,
10-
syncFixedHeaderLocalStorage,
11-
syncThemeLocalStorage, getActiveCodeEditorState, setActiveCodeEditorState,
6+
getStoredEventsCountVisibility,
7+
getStoredFixedHeader,
8+
getStoredActiveTheme,
9+
setStoredEventsCountVisibility,
10+
setStoredFixedHeader,
11+
setStoredActiveTheme, getStoredPrimaryCodeEditor, setStoredPrimaryCodeEditor,
1212
} from "./local-storage-actions";
1313

1414
export const useSettingsStore = defineStore("settingsStore", {
@@ -18,10 +18,10 @@ export const useSettingsStore = defineStore("settingsStore", {
1818
isEnabled: false,
1919
loginUrl: '/login',
2020
},
21-
codeEditor: getActiveCodeEditorState() || 'phpstorm',
22-
themeType: checkIfThemeActive(),
23-
isFixedHeader: getFixedHeaderState(),
24-
isVisibleEventCounts: getEventsCountVisibleState(),
21+
codeEditor: getStoredPrimaryCodeEditor() || 'phpstorm',
22+
themeType: getStoredActiveTheme(),
23+
isFixedHeader: getStoredFixedHeader(),
24+
isVisibleEventCounts: getStoredEventsCountVisibility(),
2525
}),
2626
actions: {
2727
initialize() {
@@ -43,22 +43,22 @@ export const useSettingsStore = defineStore("settingsStore", {
4343
? THEME_MODES.LIGHT
4444
: THEME_MODES.DARK;
4545

46-
syncThemeLocalStorage(this.themeType)
46+
setStoredActiveTheme(this.themeType)
4747
},
4848
changeNavbar() {
4949
this.isFixedHeader = !this.isFixedHeader;
5050

51-
syncFixedHeaderLocalStorage(this.isFixedHeader)
51+
setStoredFixedHeader(this.isFixedHeader)
5252
},
5353
changeEventCountsVisibility() {
5454
this.isVisibleEventCounts = !this.isVisibleEventCounts;
5555

56-
syncEventsCountVisibleLocalStorage(this.isVisibleEventCounts)
56+
setStoredEventsCountVisibility(this.isVisibleEventCounts)
5757
},
5858
changeActiveCodeEditor(editor: string) {
5959
this.codeEditor = editor;
6060

61-
setActiveCodeEditorState(editor);
61+
setStoredPrimaryCodeEditor(editor);
6262
}
6363
},
6464
});

0 commit comments

Comments
 (0)