mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
remove useCurrentUser
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user