mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 14:33:33 -07:00
i think i fixed the underlying issue
This commit is contained in:
parent
a76ed4eb97
commit
8851a8c282
3 changed files with 30 additions and 46 deletions
|
@ -45,28 +45,11 @@ export const useGroupSelf = function () {
|
||||||
export const useGroups = function () {
|
export const useGroups = function () {
|
||||||
const api = useUserApi();
|
const api = useUserApi();
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
|
const groups = ref<GroupSummary[] | null>(null);
|
||||||
|
|
||||||
function getAllGroups() {
|
async function getAllGroups() {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
const asyncKey = String(Date.now());
|
const { data } = await api.groups.getAll(1, -1, { orderBy: "name", orderDirection: "asc" });
|
||||||
const { data: groups } = useAsyncData(asyncKey, async () => {
|
|
||||||
const { data } = await api.groups.getAll(1, -1, { orderBy: "name", orderDirection: "asc" }); ;
|
|
||||||
|
|
||||||
if (data) {
|
|
||||||
return data.items;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
loading.value = false;
|
|
||||||
return groups;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function refreshAllGroups() {
|
|
||||||
loading.value = true;
|
|
||||||
const { data } = await api.groups.getAll(1, -1, { orderBy: "name", orderDirection: "asc" }); ;
|
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
groups.value = data.items;
|
groups.value = data.items;
|
||||||
|
@ -78,11 +61,15 @@ export const useGroups = function () {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function refreshAllGroups() {
|
||||||
|
await getAllGroups();
|
||||||
|
}
|
||||||
|
|
||||||
async function deleteGroup(id: string | number) {
|
async function deleteGroup(id: string | number) {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
const { data } = await api.groups.deleteOne(id);
|
const { data } = await api.groups.deleteOne(id);
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
refreshAllGroups();
|
await refreshAllGroups();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,9 +80,13 @@ export const useGroups = function () {
|
||||||
if (data && groups.value) {
|
if (data && groups.value) {
|
||||||
groups.value.push(data);
|
groups.value.push(data);
|
||||||
}
|
}
|
||||||
|
loading.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const groups = getAllGroups();
|
// Initialize data on first call
|
||||||
|
if (!groups.value) {
|
||||||
|
getAllGroups();
|
||||||
|
}
|
||||||
|
|
||||||
return { groups, getAllGroups, refreshAllGroups, deleteGroup, createGroup };
|
return { groups, getAllGroups, refreshAllGroups, deleteGroup, createGroup };
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,29 +48,12 @@ export const useHouseholdSelf = function () {
|
||||||
export const useAdminHouseholds = function () {
|
export const useAdminHouseholds = function () {
|
||||||
const api = useAdminApi();
|
const api = useAdminApi();
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
|
const households = ref<HouseholdInDB[] | null>(null);
|
||||||
|
|
||||||
function getAllHouseholds() {
|
async function getAllHouseholds() {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
const asyncKey = String(Date.now());
|
|
||||||
const { data: households } = useAsyncData(asyncKey, async () => {
|
|
||||||
const { data } = await api.households.getAll(1, -1, { orderBy: "name, group.name", orderDirection: "asc" });
|
const { data } = await api.households.getAll(1, -1, { orderBy: "name, group.name", orderDirection: "asc" });
|
||||||
|
|
||||||
if (data) {
|
|
||||||
return data.items;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
loading.value = false;
|
|
||||||
return households;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function refreshAllHouseholds() {
|
|
||||||
loading.value = true;
|
|
||||||
const { data } = await api.households.getAll(1, -1, { orderBy: "name, group.name", orderDirection: "asc" }); ;
|
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
households.value = data.items;
|
households.value = data.items;
|
||||||
}
|
}
|
||||||
|
@ -81,11 +64,15 @@ export const useAdminHouseholds = function () {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function refreshAllHouseholds() {
|
||||||
|
await getAllHouseholds();
|
||||||
|
}
|
||||||
|
|
||||||
async function deleteHousehold(id: string | number) {
|
async function deleteHousehold(id: string | number) {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
const { data } = await api.households.deleteOne(id);
|
const { data } = await api.households.deleteOne(id);
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
refreshAllHouseholds();
|
await refreshAllHouseholds();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,9 +83,9 @@ export const useAdminHouseholds = function () {
|
||||||
if (data && households.value) {
|
if (data && households.value) {
|
||||||
households.value.push(data);
|
households.value.push(data);
|
||||||
}
|
}
|
||||||
|
loading.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const households = getAllHouseholds();
|
|
||||||
function useHouseholdsInGroup(groupIdRef: Ref<string>) {
|
function useHouseholdsInGroup(groupIdRef: Ref<string>) {
|
||||||
return computed(
|
return computed(
|
||||||
() => {
|
() => {
|
||||||
|
@ -109,10 +96,14 @@ export const useAdminHouseholds = function () {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!households.value) {
|
||||||
|
getAllHouseholds();
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
households,
|
households,
|
||||||
useHouseholdsInGroup,
|
useHouseholdsInGroup,
|
||||||
getAllHouseholds,
|
getAllGroups: getAllHouseholds,
|
||||||
refreshAllHouseholds,
|
refreshAllHouseholds,
|
||||||
deleteHousehold,
|
deleteHousehold,
|
||||||
createHousehold,
|
createHousehold,
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<v-container fluid>
|
<v-container fluid>
|
||||||
|
{{ groups?.length }}
|
||||||
|
|
||||||
<BaseDialog
|
<BaseDialog
|
||||||
v-model="createDialog"
|
v-model="createDialog"
|
||||||
:title="$t('household.create-household')"
|
:title="$t('household.create-household')"
|
||||||
|
@ -14,7 +16,6 @@
|
||||||
:items="groups"
|
:items="groups"
|
||||||
item-title="name"
|
item-title="name"
|
||||||
item-value="id"
|
item-value="id"
|
||||||
:return-object="false"
|
|
||||||
variant="filled"
|
variant="filled"
|
||||||
:label="$t('household.household-group')"
|
:label="$t('household.household-group')"
|
||||||
:rules="[validators.required]"
|
:rules="[validators.required]"
|
||||||
|
@ -131,6 +132,7 @@ useSeoMeta({
|
||||||
|
|
||||||
const { groups } = useGroups();
|
const { groups } = useGroups();
|
||||||
const { households, deleteHousehold, createHousehold } = useAdminHouseholds();
|
const { households, deleteHousehold, createHousehold } = useAdminHouseholds();
|
||||||
|
|
||||||
const refNewHouseholdForm = ref<VForm | null>(null);
|
const refNewHouseholdForm = ref<VForm | null>(null);
|
||||||
|
|
||||||
const createDialog = ref(false);
|
const createDialog = ref(false);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue