2022-08-27 10:44:58 -08:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<v-card-title class="headline pb-3">
|
|
|
|
<v-icon class="mr-2">
|
|
|
|
{{ $globals.icons.commentTextMultipleOutline }}
|
|
|
|
</v-icon>
|
|
|
|
{{ $t("recipe.comments") }}
|
|
|
|
</v-card-title>
|
2025-06-20 00:09:12 +07:00
|
|
|
<v-divider class="mx-2" />
|
|
|
|
<div
|
|
|
|
v-if="user.id"
|
|
|
|
class="d-flex flex-column"
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
class="d-flex mt-3"
|
|
|
|
style="gap: 10px"
|
|
|
|
>
|
|
|
|
<UserAvatar
|
|
|
|
:tooltip="false"
|
|
|
|
size="40"
|
|
|
|
:user-id="user.id"
|
|
|
|
/>
|
2022-08-27 10:44:58 -08:00
|
|
|
|
|
|
|
<v-textarea
|
|
|
|
v-model="comment"
|
2025-06-20 00:09:12 +07:00
|
|
|
hide-details
|
|
|
|
density="compact"
|
2022-08-27 10:44:58 -08:00
|
|
|
single-line
|
2025-06-20 00:09:12 +07:00
|
|
|
variant="outlined"
|
2022-08-27 10:44:58 -08:00
|
|
|
auto-grow
|
|
|
|
rows="2"
|
|
|
|
:placeholder="$t('recipe.join-the-conversation')"
|
2025-06-20 00:09:12 +07:00
|
|
|
/>
|
2022-08-27 10:44:58 -08:00
|
|
|
</div>
|
|
|
|
<div class="ml-auto mt-1">
|
2025-06-20 00:09:12 +07:00
|
|
|
<BaseButton
|
|
|
|
size="small"
|
|
|
|
:disabled="!comment"
|
|
|
|
@click="submitComment"
|
|
|
|
>
|
|
|
|
<template #icon>
|
|
|
|
{{ $globals.icons.check }}
|
|
|
|
</template>
|
2022-08-27 10:44:58 -08:00
|
|
|
{{ $t("general.submit") }}
|
|
|
|
</BaseButton>
|
|
|
|
</div>
|
|
|
|
</div>
|
2025-06-20 00:09:12 +07:00
|
|
|
<div
|
|
|
|
v-for="recipeComment in recipe.comments"
|
|
|
|
:key="recipeComment.id"
|
|
|
|
class="d-flex my-2"
|
|
|
|
style="gap: 10px"
|
|
|
|
>
|
|
|
|
<UserAvatar
|
|
|
|
:tooltip="false"
|
|
|
|
size="40"
|
|
|
|
:user-id="recipeComment.userId"
|
|
|
|
/>
|
|
|
|
<v-card
|
|
|
|
variant="outlined"
|
|
|
|
class="flex-grow-1"
|
|
|
|
>
|
2022-08-27 10:44:58 -08:00
|
|
|
<v-card-text class="pa-3 pb-0">
|
2025-06-20 00:09:12 +07:00
|
|
|
<p class="">
|
|
|
|
{{ recipeComment.user.fullName }} • {{ $d(Date.parse(recipeComment.createdAt), "medium") }}
|
|
|
|
</p>
|
|
|
|
<SafeMarkdown :source="recipeComment.text" />
|
2022-08-27 10:44:58 -08:00
|
|
|
</v-card-text>
|
|
|
|
<v-card-actions class="justify-end mt-0 pt-0">
|
|
|
|
<v-btn
|
2025-06-20 00:09:12 +07:00
|
|
|
v-if="user.id == recipeComment.user.id || user.admin"
|
2022-08-27 10:44:58 -08:00
|
|
|
color="error"
|
2025-06-20 00:09:12 +07:00
|
|
|
variant="text"
|
|
|
|
size="x-small"
|
|
|
|
@click="deleteComment(recipeComment.id)"
|
2022-08-27 10:44:58 -08:00
|
|
|
>
|
|
|
|
{{ $t("general.delete") }}
|
|
|
|
</v-btn>
|
|
|
|
</v-card-actions>
|
|
|
|
</v-card>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2025-06-20 00:09:12 +07:00
|
|
|
<script lang="ts" setup>
|
2022-08-27 10:44:58 -08:00
|
|
|
import { useUserApi } from "~/composables/api";
|
2025-06-20 00:09:12 +07:00
|
|
|
import type { Recipe } from "~/lib/api/types/recipe";
|
2022-08-27 10:44:58 -08:00
|
|
|
import UserAvatar from "~/components/Domain/User/UserAvatar.vue";
|
2025-06-20 00:09:12 +07:00
|
|
|
import type { NoUndefinedField } from "~/lib/api/types/non-generated";
|
2022-08-27 10:44:58 -08:00
|
|
|
import { usePageUser } from "~/composables/recipe-page/shared-state";
|
2023-11-24 10:41:58 +01:00
|
|
|
import SafeMarkdown from "~/components/global/SafeMarkdown.vue";
|
2022-08-27 10:44:58 -08:00
|
|
|
|
2025-06-20 00:09:12 +07:00
|
|
|
const recipe = defineModel<NoUndefinedField<Recipe>>({ required: true });
|
|
|
|
const api = useUserApi();
|
|
|
|
const { user } = usePageUser();
|
|
|
|
const comment = ref("");
|
2022-08-27 10:44:58 -08:00
|
|
|
|
2025-06-20 00:09:12 +07:00
|
|
|
async function submitComment() {
|
|
|
|
const { data } = await api.recipes.comments.createOne({
|
|
|
|
recipeId: recipe.value.id,
|
|
|
|
text: comment.value,
|
|
|
|
});
|
2022-08-27 10:44:58 -08:00
|
|
|
|
2025-06-20 00:09:12 +07:00
|
|
|
if (data) {
|
|
|
|
recipe.value.comments.push(data);
|
|
|
|
}
|
2022-08-27 10:44:58 -08:00
|
|
|
|
2025-06-20 00:09:12 +07:00
|
|
|
comment.value = "";
|
|
|
|
}
|
2022-08-27 10:44:58 -08:00
|
|
|
|
2025-06-20 00:09:12 +07:00
|
|
|
async function deleteComment(id: string) {
|
|
|
|
const { response } = await api.recipes.comments.deleteOne(id);
|
2022-08-27 10:44:58 -08:00
|
|
|
|
2025-06-20 00:09:12 +07:00
|
|
|
if (response?.status === 200) {
|
|
|
|
recipe.value.comments = recipe.value.comments.filter(comment => comment.id !== id);
|
|
|
|
}
|
|
|
|
}
|
2022-08-27 10:44:58 -08:00
|
|
|
</script>
|