remove useCurrentUser

This commit is contained in:
Laila Los
2023-11-07 14:05:59 +01:00
parent ea0fe8053b
commit ed57567988
2 changed files with 6 additions and 31 deletions
+3 -2
View File
@@ -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<string> {
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());
+3 -29
View File
@@ -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<boolean> = false, fetchOnce: boolean | Ref<boolean> = 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<string[]>([]);
* 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) {