diff --git a/client/src/composables/hashedUserId.ts b/client/src/composables/hashedUserId.ts index ead22c34bcb..1453423a75a 100644 --- a/client/src/composables/hashedUserId.ts +++ b/client/src/composables/hashedUserId.ts @@ -1,7 +1,8 @@ import { useLocalStorage } from "@vueuse/core"; +import { storeToRefs } from "pinia"; import { computed, ref, watch } from "vue"; -import { useCurrentUser } from "./user"; +import { useUserStore } from "@/stores/userStore"; async function hash32(value: string): Promise { const valueUtf8 = new TextEncoder().encode(value); @@ -31,7 +32,7 @@ let unhashedId: string | null = null; * One way hashed ID of the current User */ export function useHashedUserId() { - const { currentUser } = useCurrentUser(true); + const { currentUser } = storeToRefs(useUserStore()); // salt the local store, to make a user untraceable by id across different clients const localStorageSalt = useLocalStorage("local-storage-salt", createSalt()); diff --git a/client/src/composables/user.ts b/client/src/composables/user.ts index fd16e731159..ecc6bddadcf 100644 --- a/client/src/composables/user.ts +++ b/client/src/composables/user.ts @@ -1,34 +1,8 @@ -import type { Ref } from "vue"; -import { computed, onMounted, ref, unref } from "vue"; +import { storeToRefs } from "pinia"; +import { computed, ref } from "vue"; import { useUserStore } from "@/stores/userStore"; -// TODO: support computed for "noFetch" -/** - * composable user store wrapper - * @param noFetch when true, the user will not be fetched from the server - * @param fetchOnce when true, the user will only be fetched from the server if it is not already in the store - * @returns currentUser computed - */ -export function useCurrentUser(noFetch: boolean | Ref = false, fetchOnce: boolean | Ref = false) { - // TODO: add store typing - const userStore = useUserStore(); - const currentUser = computed(() => userStore.currentUser); - const currentFavorites = computed(() => userStore.currentFavorites); - onMounted(() => { - if (!unref(noFetch) && !(Object.keys(currentUser).length > 0 && unref(fetchOnce))) { - userStore.loadUser(); - } - }); - const addFavoriteTool = async (toolId: string) => { - await userStore.addFavoriteTool(toolId); - }; - const removeFavoriteTool = async (toolId: string) => { - await userStore.removeFavoriteTool(toolId); - }; - return { currentUser, currentFavorites, addFavoriteTool, removeFavoriteTool }; -} - export function useCurrentTheme() { const userStore = useUserStore(); const currentTheme = computed(() => userStore.currentTheme); @@ -48,7 +22,7 @@ const localTags = ref([]); * Keeps tracks of the tags the current user has used. */ export function useUserTags() { - const { currentUser } = useCurrentUser(true); + const { currentUser } = storeToRefs(useUserStore()); const userTags = computed(() => { let tags: string[]; if (currentUser.value && !currentUser.value.isAnonymous) {