Skip to content

Commit

Permalink
update codestyle for enums
Browse files Browse the repository at this point in the history
  • Loading branch information
Kreezag committed Sep 11, 2024
1 parent 6227d5d commit 43c0473
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 73 deletions.
16 changes: 8 additions & 8 deletions src/shared/stores/events/local-storage-actions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {type EventId, SESSION_STORAGE_KEYS} from "../../types";
import {type EventId, SessionStorageKeys} from "../../types";
import type {TEventsCachedIdsMap} from "./types";

const { sessionStorage } = window;

export const getStoredCachedIds = (): TEventsCachedIdsMap | null => {
const storageValue = sessionStorage?.getItem(SESSION_STORAGE_KEYS.CACHED_EVENTS);
const storageValue = sessionStorage?.getItem(SessionStorageKeys.CachedEvents);

if (storageValue) {
return JSON.parse(storageValue) as TEventsCachedIdsMap;
Expand All @@ -14,12 +14,12 @@ export const getStoredCachedIds = (): TEventsCachedIdsMap | null => {
};

export const setStoredCachedIds = (cachedEventMap: TEventsCachedIdsMap) => {
sessionStorage?.setItem(SESSION_STORAGE_KEYS.CACHED_EVENTS, JSON.stringify(cachedEventMap));
sessionStorage?.setItem(SessionStorageKeys.CachedEvents, JSON.stringify(cachedEventMap));
}


export const getStoredLockedIds = (): EventId[] | null => {
const storageValue = sessionStorage?.getItem(SESSION_STORAGE_KEYS.LOCKED_EVENTS);
const storageValue = sessionStorage?.getItem(SessionStorageKeys.LockedEvents);

if (storageValue) {
return JSON.parse(storageValue) as EventId[];
Expand All @@ -29,19 +29,19 @@ export const getStoredLockedIds = (): EventId[] | null => {
};

export const setStoredLockedIds = (lockedIds: EventId[]) => {
sessionStorage?.setItem(SESSION_STORAGE_KEYS.LOCKED_EVENTS, JSON.stringify(lockedIds));
sessionStorage?.setItem(SessionStorageKeys.LockedEvents, JSON.stringify(lockedIds));
}

export const getStoredProject = (): string | null => sessionStorage?.getItem(SESSION_STORAGE_KEYS.PROJECT) || null;
export const getStoredProject = (): string | null => sessionStorage?.getItem(SessionStorageKeys.Project) || null;


export const removeStoredProject = () => {
sessionStorage?.removeItem(SESSION_STORAGE_KEYS.PROJECT);
sessionStorage?.removeItem(SessionStorageKeys.Project);
}

export const setStoredProject = (project: string | null) => {
if (project) {
sessionStorage?.setItem(SESSION_STORAGE_KEYS.PROJECT, project);
sessionStorage?.setItem(SessionStorageKeys.Project, project);
} else {
removeStoredProject()
}
Expand Down
8 changes: 4 additions & 4 deletions src/shared/stores/profile/local-storage-actions.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {LOCAL_STORAGE_KEYS} from "../../types";
import {LocalStorageKeys} from "../../types";

export const getStoredToken = (): string => {
const storedCodeEditor = window?.localStorage?.getItem(LOCAL_STORAGE_KEYS.TOKEN);
const storedCodeEditor = window?.localStorage?.getItem(LocalStorageKeys.Token);

return storedCodeEditor || '';
};

export const setStoredToken = (token: string) => {
localStorage?.setItem(LOCAL_STORAGE_KEYS.TOKEN, token);
localStorage?.setItem(LocalStorageKeys.Token, token);
}

export const removeStoredToken = () => {
localStorage?.removeItem(LOCAL_STORAGE_KEYS.TOKEN);
localStorage?.removeItem(LocalStorageKeys.Token);
}
18 changes: 9 additions & 9 deletions src/shared/stores/settings/local-storage-actions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {LOCAL_STORAGE_KEYS} from "../../types";
import {LocalStorageKeys} from "../../types";
import {THEME_MODES} from "./constants";

export const getStoredActiveTheme = () => {
const isStoredTheme = window?.localStorage.getItem(LOCAL_STORAGE_KEYS.THEME);
const isStoredTheme = window?.localStorage.getItem(LocalStorageKeys.Theme);
const isSystemDarkTheme = window.matchMedia("(prefers-color-scheme: dark)").matches;

if (isStoredTheme) {
Expand All @@ -27,7 +27,7 @@ export const getStoredActiveTheme = () => {
};

export const setStoredActiveTheme = (themeName: string) => {
window?.localStorage.setItem(LOCAL_STORAGE_KEYS.THEME, themeName);
window?.localStorage.setItem(LocalStorageKeys.Theme, themeName);

if (themeName === THEME_MODES.LIGHT) {
window?.document?.documentElement?.classList?.remove(THEME_MODES.DARK);
Expand All @@ -37,7 +37,7 @@ export const setStoredActiveTheme = (themeName: string) => {
}

export const getStoredFixedHeader = () => {
const storedValue: string = window?.localStorage.getItem(LOCAL_STORAGE_KEYS.NAVBAR) || "true";
const storedValue: string = window?.localStorage.getItem(LocalStorageKeys.Navbar) || "true";

const isFixed: boolean = storedValue === "true"

Expand All @@ -51,7 +51,7 @@ export const getStoredFixedHeader = () => {
}

export const setStoredFixedHeader = (state: boolean) => {
window?.localStorage.setItem(LOCAL_STORAGE_KEYS.NAVBAR, String(state));
window?.localStorage.setItem(LocalStorageKeys.Navbar, String(state));

if (state) {
window?.document?.documentElement?.classList?.add("navbar-fixed");
Expand All @@ -61,22 +61,22 @@ export const setStoredFixedHeader = (state: boolean) => {
}

export const getStoredEventsCountVisibility = (): boolean => {
const storageValue = window?.localStorage?.getItem(LOCAL_STORAGE_KEYS.EVENT_COUNTS) || "true";
const storageValue = window?.localStorage?.getItem(LocalStorageKeys.EventCounts) || "true";

return storageValue === "true";
};

export const setStoredEventsCountVisibility = (state: boolean) => {
window?.localStorage?.setItem(LOCAL_STORAGE_KEYS.EVENT_COUNTS, String(state));
window?.localStorage?.setItem(LocalStorageKeys.EventCounts, String(state));
}


export const getStoredPrimaryCodeEditor = (): string => {
const storedCodeEditor = window?.localStorage?.getItem(LOCAL_STORAGE_KEYS.CODE_EDITOR);
const storedCodeEditor = window?.localStorage?.getItem(LocalStorageKeys.CodeEditor);

return storedCodeEditor || '';
};

export const setStoredPrimaryCodeEditor = (editor: string) => {
window?.localStorage?.setItem(LOCAL_STORAGE_KEYS.CODE_EDITOR, editor);
window?.localStorage?.setItem(LocalStorageKeys.CodeEditor, editor);
}
20 changes: 10 additions & 10 deletions src/shared/types/local-storage.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

export enum LOCAL_STORAGE_KEYS {
THEME = "theme",
NAVBAR = "navbar",
EVENT_COUNTS = "event_counts",
CODE_EDITOR = "code_editor",
TOKEN = "token",
export enum LocalStorageKeys {
Theme = "theme",
Navbar = "navbar",
EventCounts = "event_counts",
CodeEditor = "code_editor",
Token = "token",
}

export enum SESSION_STORAGE_KEYS {
PROJECT = "project",
CACHED_EVENTS = "cached_events",
LOCKED_EVENTS = "locked_events",
export enum SessionStorageKeys {
Project = "project",
CachedEvents = "cached_events",
LockedEvents = "locked_events",
}
9 changes: 4 additions & 5 deletions src/shared/ui/sorting-wrapper/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

export enum SORTING_ORDER {
ASC = 'asc',
DESC = 'desc',
DEFAULT = 'default',
export enum SortingOrder {
Asc = 'asc',
Desc = 'desc',
Default = 'default',
}
4 changes: 2 additions & 2 deletions src/shared/ui/sorting-wrapper/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SORTING_ORDER } from "./constants";
import { SortingOrder } from "./constants";
import SortingWrapper from "./sorting-wrapper.vue";

export { SortingWrapper, SORTING_ORDER };
export { SortingWrapper, SortingOrder };
56 changes: 28 additions & 28 deletions src/shared/ui/sorting-wrapper/sorting-wrapper.stories.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { action } from "@storybook/addon-actions";
import type { Meta, StoryObj } from "@storybook/vue3";
import type { ComponentProps } from "vue-component-type-helpers";
import { SORTING_ORDER } from "./constants";
import { SortingOrder } from "./constants";
import SortingWrapper from "./sorting-wrapper.vue";


Expand All @@ -16,37 +16,37 @@ export default {
setup() {
return {
args,
SORTING_ORDER,
SORTING_ORDER: SortingOrder,
};
},
template: `
<div>
<div>
<sorting-wrapper
@change-sort="(a) => action('Change Sort')(a)"
>
Default sort
</sorting-wrapper>
</div>
<br>
<div>
<sorting-wrapper
@change-sort="(a) => action('Change Sort')(a)"
:sort="SORTING_ORDER.ASC"
>
ASC sort
</sorting-wrapper>
</div>
<br>
<div>
<sorting-wrapper
@change-sort="(a) => action('Change Sort')(a)"
:sort="SORTING_ORDER.DESC"
>
DESC sort
</sorting-wrapper>
</div>
</div>`,
<div>
<sorting-wrapper
@change-sort="(a) => action('Change Sort')(a)"
>
Default sort
</sorting-wrapper>
</div>
<br>
<div>
<sorting-wrapper
@change-sort="(a) => action('Change Sort')(a)"
:sort="SORTING_ORDER.Asc"
>
ASC sort
</sorting-wrapper>
</div>
<br>
<div>
<sorting-wrapper
@change-sort="(a) => action('Change Sort')(a)"
:sort="SORTING_ORDER.Desc"
>
DESC sort
</sorting-wrapper>
</div>
</div>`,
})
} as Meta<typeof SortingWrapper>;

Expand Down
14 changes: 7 additions & 7 deletions src/shared/ui/sorting-wrapper/sorting-wrapper.vue
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<script lang="ts" setup>
import { SORTING_ORDER } from './constants'
import { SortingOrder } from './constants'
type Props = {
sort: SORTING_ORDER
sort: SortingOrder
}
type Emits = {
changeSort: [value: SORTING_ORDER]
changeSort: [value: SortingOrder]
}
const props = withDefaults(defineProps<Props>(), {
sort: SORTING_ORDER.DEFAULT
sort: SortingOrder.Default
})
const emit = defineEmits<Emits>()
const changeSortOrder = () => {
const sortOrderList = [SORTING_ORDER.ASC, SORTING_ORDER.DESC, SORTING_ORDER.DEFAULT]
const sortOrderList = [SortingOrder.Asc, SortingOrder.Desc, SortingOrder.Default]
const nextSortOrderIndex = sortOrderList.findIndex((sortOrder) => sortOrder === props.sort)
Expand All @@ -34,13 +34,13 @@ const changeSortOrder = () => {
<span
class="sorting-wrapper__marker sorting-wrapper__marker--asc"
:class="{
'sorting-wrapper__marker--active': sort === SORTING_ORDER.ASC
'sorting-wrapper__marker--active': sort === SortingOrder.Asc
}"
/>
<span
class="sorting-wrapper__marker sorting-wrapper__marker--desc"
:class="{
'sorting-wrapper__marker--active': sort === SORTING_ORDER.DESC
'sorting-wrapper__marker--active': sort === SortingOrder.Desc
}"
/>
</span>
Expand Down

0 comments on commit 43c0473

Please sign in to comment.