Skip to content

Commit

Permalink
✨ session username
Browse files Browse the repository at this point in the history
  • Loading branch information
haliphax committed Aug 15, 2023
1 parent 7c507c4 commit 2db28ee
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/front-end/scripts/store/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const SESSION_PREFIX = `${LOCALSTORAGE_GLOBAL_PREFIX}session.`;
const keys = {
darkMode: `${SESSION_PREFIX}darkMode`,
sessionId: `${SESSION_PREFIX}sessionId`,
userName: `${SESSION_PREFIX}userName`,
};

const session: Module<SessionState, StoreState> = {
Expand All @@ -16,6 +17,10 @@ const session: Module<SessionState, StoreState> = {
state.settings.darkMode = payload;
localStorage.setItem(keys.darkMode, payload.toString());
},
"session.settings.userName"(state, payload: string) {
state.userName = payload;
localStorage.setItem(keys.userName, payload);
},
},
state() {
let sessionId = localStorage.getItem(keys.sessionId);
Expand All @@ -27,7 +32,7 @@ const session: Module<SessionState, StoreState> = {

return {
id: sessionId,
name: "Me",
userName: localStorage.getItem(keys.userName) ?? "User",
settings: {
darkMode: JSON.parse(localStorage.getItem(keys.darkMode) ?? "false"),
},
Expand Down
2 changes: 1 addition & 1 deletion src/front-end/scripts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type SessionSettings = {

export type SessionState = {
id: string;
name: string;
userName: string;
settings: SessionSettings;
};

Expand Down
2 changes: 1 addition & 1 deletion src/vuex.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Store } from "vuex";
import { StoreState } from "../front-end/scripts/types";
import { StoreState } from "./front-end/scripts/types";

declare module "@vue/runtime-core" {
interface ComponentCustomProperties {
Expand Down

0 comments on commit 2db28ee

Please sign in to comment.