mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-02 20:15:24 +02:00
feat(frontend): ✨ Fractional Scaling
This commit is contained in:
parent
d1a7ec3b95
commit
5ba337ab11
11 changed files with 306 additions and 126 deletions
|
@ -1,8 +1,10 @@
|
|||
import { useAsync, ref, reactive } from "@nuxtjs/composition-api";
|
||||
import { useAsync, ref, reactive, Ref } from "@nuxtjs/composition-api";
|
||||
import { useAsyncKey } from "./use-utils";
|
||||
import { useApiSingleton } from "~/composables/use-api";
|
||||
import { Unit } from "~/api/class-interfaces/recipe-units";
|
||||
|
||||
let unitStore: Ref<Unit[] | null> | null = null;
|
||||
|
||||
export const useUnits = function () {
|
||||
const api = useApiSingleton();
|
||||
const loading = ref(false);
|
||||
|
@ -12,6 +14,7 @@ export const useUnits = function () {
|
|||
const workingUnitData = reactive({
|
||||
id: 0,
|
||||
name: "",
|
||||
fraction: true,
|
||||
abbreviation: "",
|
||||
description: "",
|
||||
});
|
||||
|
@ -24,15 +27,15 @@ export const useUnits = function () {
|
|||
return data;
|
||||
}, useAsyncKey());
|
||||
|
||||
loading.value = false
|
||||
loading.value = false;
|
||||
return units;
|
||||
},
|
||||
async refreshAll() {
|
||||
loading.value = true;
|
||||
const { data } = await api.units.getAll();
|
||||
|
||||
if (data) {
|
||||
units.value = data;
|
||||
if (data && unitStore) {
|
||||
unitStore.value = data;
|
||||
}
|
||||
|
||||
loading.value = false;
|
||||
|
@ -45,8 +48,8 @@ export const useUnits = function () {
|
|||
|
||||
loading.value = true;
|
||||
const { data } = await api.units.createOne(workingUnitData);
|
||||
if (data && units.value) {
|
||||
units.value.push(data);
|
||||
if (data && unitStore?.value) {
|
||||
unitStore.value.push(data);
|
||||
} else {
|
||||
this.refreshAll();
|
||||
}
|
||||
|
@ -62,7 +65,7 @@ export const useUnits = function () {
|
|||
|
||||
loading.value = true;
|
||||
const { data } = await api.units.updateOne(workingUnitData.id, workingUnitData);
|
||||
if (data && units.value) {
|
||||
if (data && unitStore?.value) {
|
||||
this.refreshAll();
|
||||
}
|
||||
loading.value = false;
|
||||
|
@ -70,7 +73,7 @@ export const useUnits = function () {
|
|||
async deleteOne(id: string | number) {
|
||||
loading.value = true;
|
||||
const { data } = await api.units.deleteOne(id);
|
||||
if (data && units.value) {
|
||||
if (data && unitStore?.value) {
|
||||
this.refreshAll();
|
||||
}
|
||||
},
|
||||
|
@ -83,12 +86,18 @@ export const useUnits = function () {
|
|||
setWorking(item: Unit) {
|
||||
workingUnitData.id = item.id;
|
||||
workingUnitData.name = item.name;
|
||||
workingUnitData.fraction = item.fraction;
|
||||
workingUnitData.abbreviation = item.abbreviation;
|
||||
workingUnitData.description = item.description;
|
||||
},
|
||||
flushStore() {
|
||||
unitStore = null;
|
||||
},
|
||||
};
|
||||
|
||||
const units = actions.getAll();
|
||||
if (!unitStore) {
|
||||
unitStore = actions.getAll();
|
||||
}
|
||||
|
||||
return { units, workingUnitData, deleteTargetId, actions, validForm };
|
||||
return { units: unitStore, workingUnitData, deleteTargetId, actions, validForm };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue