Skip to content

Commit

Permalink
chore
Browse files Browse the repository at this point in the history
  • Loading branch information
kobakazu0429 committed Dec 13, 2023
1 parent b97ff3b commit 3d073fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/components/Editor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { getCode, recoveryCode } from "../editor/utils";
import { connectLanguageServer } from "../editor/lsp";
const ws = writable(connectLanguageServer(getUser().id));
const ws = writable(connectLanguageServer(getUser()?.id));
settings.subscribe(async (s) => {
const userId = s.config.find((c) => c.key === "User ID");
Expand Down
16 changes: 9 additions & 7 deletions src/localStorage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,26 @@ export const visited = () => {
}

const user = getUser();
settings.update((self) => {
const config = self.config.find((c) => c.key === "User ID");
if (config) config.value = user.id;
return self;
});
if (user) {
settings.update((self) => {
const config = self.config.find((c) => c.key === "User ID");
if (config) config.value = user.id;
return self;
});
}
};

export const isVisited = () => {
return (store.local.get(VISITED_KEY) as boolean | null) ?? false;
};

export const getUser = (): User => {
export const getUser = (): User | undefined => {
const user = store.local.get(USER_KEY);
return user;
};

export const updateUser = (user: Partial<User>) => {
const prevUser = getUser();
const prevUser = getUser()!;
const newUser: User = { ...prevUser, ...user };
store.local.set(USER_KEY, newUser);
};

0 comments on commit 3d073fc

Please sign in to comment.