mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-05-24 01:12:54 -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 { 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<GroupInDB | null>(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;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user