cosette/pages/c/[cosetta].vue

55 lines
1.9 KiB
Vue
Raw Normal View History

2022-08-11 09:57:51 +02:00
<script setup>
2022-08-16 14:43:33 +02:00
const route = useRoute()
2022-08-22 16:03:08 +02:00
const { $socket } = useNuxtApp()
2022-08-11 09:57:51 +02:00
2022-08-16 14:43:33 +02:00
let { cosetta, comments } = reactive(await $fetch(`/api/cosetta/${route.params.cosetta}`))
2022-08-12 18:23:03 +02:00
2022-08-16 14:43:33 +02:00
const comment = reactive({ cosetta_uuid: route.params.cosetta, message: '' })
const addComment = async () => {
const ret = await $fetch(`/api/comment`, { method: 'POST', body: { ...comment } })
comment.message = ''
2022-08-22 16:03:08 +02:00
const db_comment = await $fetch(`/api/comment/${ret.comment.uuid}`)
comments.unshift(db_comment)
$socket.emit("newComment", db_comment, route.params.cosetta )
2022-08-16 14:43:33 +02:00
}
2022-08-11 09:57:51 +02:00
2022-08-22 16:03:08 +02:00
onMounted(() => {
$socket.emit("joinRoom", route.params.cosetta)
$socket.on("newComment", (newComment) => {
comments.unshift(newComment.message)
})
})
2022-08-11 09:57:51 +02:00
</script>
<template>
<section class="bg-white py-8">
2022-08-12 18:23:03 +02:00
<div class="container mx-auto pt-4 pb-12">
2022-08-22 17:18:45 +02:00
<img v-if='cosetta.images' :src="`/${cosetta.images[0]}`" />
2022-08-16 14:43:33 +02:00
<h2 class="text-pink-500 text-2xl card-title uppercase mb-2 divider" v-text='cosetta.name' />
<div class="px-6 pt-4 pb-2">
<span v-for='tag in cosetta.tags' :key='tag'
class="inline-block bg-gray-200 rounded-full px-3 py-1 text-sm font-semibold text-gray-700 mr-2 mb-2"
v-text='tag' />
</div>
<p class='pt-1 text-gray-700 text-xl'>{{ cosetta.description }}</p>
2022-08-12 18:23:03 +02:00
</div>
<div class="container mx-auto">
<p class="font-bold text-xl uppercase">chiacchiere</p>
<div class='form-control'>
<div class='input-group'>
2022-08-16 14:43:33 +02:00
<input v-model='comment.message' class="input input-bordered w-full text-sm" @keypress:enter="addComment" />
2022-08-12 18:23:03 +02:00
<button class="btn btn-success" @click='addComment'>Invia</button>
</div>
<div class='mt-2' v-for='comment in comments' :key='comment.uuid'>
2022-08-16 14:43:33 +02:00
<span class="label-text-alt" v-text='comment.updatedAt' />
<div class="alert" v-text='comment.message' />
2022-08-12 18:23:03 +02:00
</div>
</div>
2022-08-11 09:57:51 +02:00
</div>
</section>
</template>