mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-04 21:15:22 +02:00
Merge branch 'mealie-next' into l10n_mealie-next
This commit is contained in:
commit
abb2c8110c
5 changed files with 45 additions and 16 deletions
|
@ -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, GroupSummary } from "~/lib/api/types/user";
|
||||
|
||||
const groupSelfRef = ref<GroupSummary | 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;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -48,6 +48,13 @@ export interface GroupInDB {
|
|||
users?: UserOut[];
|
||||
preferences?: ReadGroupPreferences;
|
||||
}
|
||||
export interface GroupSummary {
|
||||
name: string;
|
||||
id: string;
|
||||
slug: string;
|
||||
preferences?: ReadGroupPreferences;
|
||||
|
||||
}
|
||||
export interface CategoryBase {
|
||||
name: string;
|
||||
id: string;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { BaseCRUDAPI } from "../base/base-clients";
|
||||
import { CategoryBase, GroupBase, GroupInDB, UserOut } from "~/lib/api/types/user";
|
||||
import { CategoryBase, GroupBase, GroupInDB, GroupSummary, UserOut } from "~/lib/api/types/user";
|
||||
import {
|
||||
CreateInviteToken,
|
||||
GroupAdminUpdate,
|
||||
|
@ -35,7 +35,7 @@ export class GroupAPI extends BaseCRUDAPI<GroupBase, GroupInDB, GroupAdminUpdate
|
|||
/** Returns the Group Data for the Current User
|
||||
*/
|
||||
async getCurrentUserGroup() {
|
||||
return await this.requests.get<GroupInDB>(routes.groupsSelf);
|
||||
return await this.requests.get<GroupSummary>(routes.groupsSelf);
|
||||
}
|
||||
|
||||
async getCategories() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue