diff --git a/frontend/composables/use-groups.ts b/frontend/composables/use-groups.ts index 8b2e8b682af8..f9b91283469b 100644 --- a/frontend/composables/use-groups.ts +++ b/frontend/composables/use-groups.ts @@ -1,30 +1,39 @@ import { useAsync, ref } from "@nuxtjs/composition-api"; -import { useAsyncKey } from "./use-utils"; import { useUserApi } from "~/composables/api"; -import { GroupBase } from "~/lib/api/types/user"; +import { GroupBase, GroupInDB } from "~/lib/api/types/user"; + +const groupSelfRef = ref(null); +const loading = ref(false); export const useGroupSelf = function () { const api = useUserApi(); + async function refreshGroupSelf() { + loading.value = true; + const { data } = await api.groups.getCurrentUserGroup(); + groupSelfRef.value = data; + loading.value = false; + } const actions = { get() { - const group = useAsync(async () => { - const { data } = await api.groups.getCurrentUserGroup(); + if (!(groupSelfRef.value || loading.value)) { + refreshGroupSelf(); + } - return data; - }, useAsyncKey()); - - return group; + return groupSelfRef; }, async updatePreferences() { - if (!group.value?.preferences) { + if (!groupSelfRef.value) { + await refreshGroupSelf(); + } + if (!groupSelfRef.value?.preferences) { return; } - const { data } = await api.groups.setPreferences(group.value.preferences); + const { data } = await api.groups.setPreferences(groupSelfRef.value.preferences); if (data) { - group.value.preferences = data; + groupSelfRef.value.preferences = data; } }, };