mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-06-02 13:15:23 -04:00
add shared group self to composable
This commit is contained in:
parent
f83ab6ecc1
commit
b6ccb9fbdb
@ -1,30 +1,39 @@
|
|||||||
import { useAsync, ref } from "@nuxtjs/composition-api";
|
import { useAsync, ref } from "@nuxtjs/composition-api";
|
||||||
import { useAsyncKey } from "./use-utils";
|
|
||||||
import { useUserApi } from "~/composables/api";
|
import { useUserApi } from "~/composables/api";
|
||||||
import { GroupBase } from "~/lib/api/types/user";
|
import { GroupBase, GroupInDB } from "~/lib/api/types/user";
|
||||||
|
|
||||||
|
const groupSelfRef = ref<GroupInDB | null>(null);
|
||||||
|
const loading = ref(false);
|
||||||
|
|
||||||
export const useGroupSelf = function () {
|
export const useGroupSelf = function () {
|
||||||
const api = useUserApi();
|
const api = useUserApi();
|
||||||
|
async function refreshGroupSelf() {
|
||||||
|
loading.value = true;
|
||||||
|
const { data } = await api.groups.getCurrentUserGroup();
|
||||||
|
groupSelfRef.value = data;
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
get() {
|
get() {
|
||||||
const group = useAsync(async () => {
|
if (!(groupSelfRef.value || loading.value)) {
|
||||||
const { data } = await api.groups.getCurrentUserGroup();
|
refreshGroupSelf();
|
||||||
|
}
|
||||||
|
|
||||||
return data;
|
return groupSelfRef;
|
||||||
}, useAsyncKey());
|
|
||||||
|
|
||||||
return group;
|
|
||||||
},
|
},
|
||||||
async updatePreferences() {
|
async updatePreferences() {
|
||||||
if (!group.value?.preferences) {
|
if (!groupSelfRef.value) {
|
||||||
|
await refreshGroupSelf();
|
||||||
|
}
|
||||||
|
if (!groupSelfRef.value?.preferences) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data } = await api.groups.setPreferences(group.value.preferences);
|
const { data } = await api.groups.setPreferences(groupSelfRef.value.preferences);
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
group.value.preferences = data;
|
groupSelfRef.value.preferences = data;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user