From 23a561e8cd42321b60a63fb49d8bad53ecf59317 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Sun, 9 Feb 2025 15:25:52 +0100 Subject: [PATCH] added simple comment view --- .../src/components/display/RecipeActivity.vue | 77 ++++++++++++++----- 1 file changed, 59 insertions(+), 18 deletions(-) diff --git a/vue3/src/components/display/RecipeActivity.vue b/vue3/src/components/display/RecipeActivity.vue index f2dcf8283..bd938e546 100644 --- a/vue3/src/components/display/RecipeActivity.vue +++ b/vue3/src/components/display/RecipeActivity.vue @@ -4,13 +4,14 @@ {{ $t('Activity') }} + - + {{ c.createdBy.displayName }} - + {{ c.comment }} @@ -30,6 +31,29 @@ + + + + + + {{$t('Rating')}}
+ +
+ + + + + + + + +
+
+ + {{ $t('Create') }} + +
+ @@ -38,6 +62,9 @@ import {onMounted, PropType, ref} from "vue"; import {ApiApi, CookLog, Recipe} from "@/openapi"; import {DateTime} from "luxon"; +import {ErrorMessageType, useMessageStore} from "@/stores/MessageStore"; +import {VDateInput} from 'vuetify/labs/VDateInput' +import {VNumberInput} from 'vuetify/labs/VNumberInput' const props = defineProps({ recipe: { @@ -46,8 +73,18 @@ const props = defineProps({ }, }) +const newCookLog = ref({} as CookLog); + const cookLogs = ref([] as CookLog[]) +onMounted(() => { + refreshActivity() + resetForm() +}) + +/** + * load cook logs from database for given recipe + */ function refreshActivity() { const api = new ApiApi() api.apiCookLogList({recipe: props.recipe.id}).then(r => { @@ -58,24 +95,28 @@ function refreshActivity() { }) } -function createCookLog(form: any) { - const api = new ApiApi() - let cookLog = { - recipe: props.recipe.id, - comment: form.data.comment, - servings: form.data.servings, - rating: form.data.rating, - } as CookLog - api.apiCookLogCreate({cookLogRequest: cookLog}).then(r => { - console.log('success', r) - }).catch(err => { - console.log('error', err) - }) +/** + * reset new cook log from with proper defaults + */ +function resetForm() { + newCookLog.value.servings = props.recipe.servings + newCookLog.value.createdAt = new Date() + newCookLog.value.recipe = props.recipe.id! } -onMounted(() => { - refreshActivity() -}) +/** + * create new cook log in database + */ +function saveCookLog() { + const api = new ApiApi() + + api.apiCookLogCreate({cookLog: newCookLog.value}).then(r => { + cookLogs.value.push(r) + resetForm() + }).catch(err => { + useMessageStore().addError(ErrorMessageType.CREATE_ERROR, err) + }) +}