fix: set emojis when session available

This commit is contained in:
verbiricha 2023-07-31 10:00:40 +02:00
parent ecc54d5d3d
commit 438d72d188
2 changed files with 9 additions and 5 deletions

View File

@ -87,6 +87,8 @@ export function useLoginEvents(pubkey?: string, leaveOpen = false) {
const emojis = useUserEmojiPacks(pubkey, userEmojis);
useEffect(() => {
Login.setEmojis(emojis);
}, [emojis]);
if (session) {
Login.setEmojis(emojis);
}
}, [session, emojis]);
}

View File

@ -35,12 +35,14 @@ const initialState = {
emojis: [],
};
const SESSION_KEY = "session";
export class LoginStore extends ExternalStore<LoginSession | undefined> {
#session?: LoginSession;
constructor() {
super();
const json = window.localStorage.getItem("session");
const json = window.localStorage.getItem(SESSION_KEY);
if (json) {
this.#session = { ...initialState, ...JSON.parse(json) };
if (this.#session) {
@ -126,9 +128,9 @@ export class LoginStore extends ExternalStore<LoginSession | undefined> {
#save() {
if (this.#session) {
window.localStorage.setItem("session", JSON.stringify(this.#session));
window.localStorage.setItem(SESSION_KEY, JSON.stringify(this.#session));
} else {
window.localStorage.removeItem("session");
window.localStorage.removeItem(SESSION_KEY);
}
this.notifyChange();
}