Skip to content

Commit

Permalink
Refactor loadUser function and create Interface for User
Browse files Browse the repository at this point in the history
  • Loading branch information
heisner-tillman committed Oct 20, 2023
1 parent 737e096 commit 2f97458
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions client/src/stores/userStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ import {
removeFavoriteToolQuery,
setCurrentThemeQuery,
} from "@/stores/users/queries";
import { expand } from "rxjs";


type AnonymousUser = components["schemas"]["AnonUserModel"]
type User = components["schemas"]["DetailedUserModel"]
type DetailedAnonymousUser = components["schemas"]["AnonUserModel"]
type DetailedUserModelUser = components["schemas"]["DetailedUserModel"]

interface AnonymousUser extends DetailedAnonymousUser {
isAnonymous: true
}

interface User extends DetailedUserModelUser {
isAnonymous: false;
}
interface Preferences {
theme: string;
favorites: { tools: string[] };
Expand Down Expand Up @@ -55,10 +62,10 @@ export const useUserStore = defineStore("userStore", () => {
.then(async (user) => {
if ('email' in user) {
currentUser.value = { ...user, isAnonymous: false };
currentPreferences.value = user.preferences;
currentPreferences.value = user.preferences as unknown as Preferences;
}
else {
currentUser.value = { isAnonymous: true };
currentUser.value = { ...user, isAnonymous: true };
currentPreferences.value = null;
}
// TODO: This is a hack to get around the fact that the API returns a string
Expand Down

0 comments on commit 2f97458

Please sign in to comment.