playing with vueform

This commit is contained in:
vabene1111
2024-04-22 20:18:09 +02:00
parent 12cf9da8fc
commit 17610663c1
4 changed files with 337 additions and 11 deletions

View File

@@ -1,4 +1,4 @@
import {defineStore} from "pinia"
import {acceptHMRUpdate, defineStore} from "pinia"
import {ApiApi, MealPlan} from "@/openapi";
import {computed, ref} from "vue";
import {DateTime} from "luxon";
@@ -60,12 +60,21 @@ export const useMealPlanStore = defineStore(_STORE_ID, () => {
currently_updating.value = [new Date(0), new Date(0)]
})
}
return new Promise(() => {})
return new Promise(() => {
})
}
function createOrUpdate(object: MealPlan) {
if(object.id == undefined){
return createObject(object)
} else {
return updateObject(object)
}
}
function createObject(object: MealPlan) {
const api = new ApiApi()
return api.apiMealPlanCreate({mealPlan: object}).then((r) => {
return api.apiMealPlanCreate({mealPlanRequest: object}).then((r) => {
//StandardToasts.makeStandardToast(this, StandardToasts.SUCCESS_CREATE)
plans.value.set(r.id, r)
return r
@@ -76,7 +85,7 @@ export const useMealPlanStore = defineStore(_STORE_ID, () => {
function updateObject(object: MealPlan) {
const api = new ApiApi()
return api.apiMealPlanUpdate({id: object.id, mealPlan: object}).then((r) => {
return api.apiMealPlanUpdate({id: object.id, mealPlanRequest: object}).then((r) => {
//StandardToasts.makeStandardToast(this, StandardToasts.SUCCESS_UPDATE)
plans.value.set(r.id, r)
}).catch((err) => {
@@ -112,5 +121,10 @@ export const useMealPlanStore = defineStore(_STORE_ID, () => {
// return JSON.parse(s)
// }
// }
return {plans, currently_updating, plan_list, refreshFromAPI, createObject, updateObject, deleteObject}
return {plans, currently_updating, plan_list, refreshFromAPI, createObject, updateObject, deleteObject, createOrUpdate}
})
// enable hot reload for store
if (import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(useMealPlanStore, import.meta.hot))
}