This commit is contained in:
lesion 2022-08-13 11:56:59 +02:00
parent 504f15edac
commit 5c7fdf48bb
6 changed files with 22 additions and 19 deletions

View file

@ -7,13 +7,13 @@
"preview": "nuxt preview" "preview": "nuxt preview"
}, },
"devDependencies": { "devDependencies": {
"@iconify/json": "^2.1.88", "@iconify/json": "^2.1.91",
"@nuxtjs/svg": "^0.4.0", "@nuxtjs/svg": "^0.4.0",
"@nuxtjs/tailwindcss": "^5.3.1", "@nuxtjs/tailwindcss": "^5.3.1",
"daisyui": "^2.22.0", "daisyui": "^2.22.0",
"nuxt": "3.0.0-rc.6", "nuxt": "3.0.0-rc.6",
"unplugin-icons": "^0.14.8", "unplugin-icons": "^0.14.8",
"unplugin-vue-components": "^0.22.3" "unplugin-vue-components": "^0.22.4"
}, },
"dependencies": { "dependencies": {
"better-sqlite3": "^7.6.2", "better-sqlite3": "^7.6.2",

View file

@ -1,10 +1,14 @@
<script setup> <script setup>
const route = useRoute() const route = useRoute()
const { cosetta, comments } = await $fetch(`/api/cosetta/${route.params.cosetta}`) let { cosetta, comments } = reactive(await $fetch(`/api/cosetta/${route.params.cosetta}`))
const comment = { cosetta_uuid: route.params.cosetta, message: '' } const comment = reactive({ cosetta_uuid: route.params.cosetta, message: '' })
const addComment = () => $fetch(`/api/comment`, { method: 'POST', body: { ...comment } }) const addComment = async () => {
const ret = await $fetch(`/api/comment`, { method: 'POST', body: { ...comment } })
comment.message = ''
comments.unshift(ret.comment)
}
</script> </script>
<template> <template>

View file

@ -4,8 +4,8 @@ import { useBody } from 'h3'
export default defineEventHandler(async (event) => { export default defineEventHandler(async (event) => {
try { try {
const body = await useBody(event) const body = await useBody(event)
addComment(body) const comment = addComment(body)
return { success: true } return { success: true, comment }
} catch (e) { } catch (e) {
return { success: false, reason: e.message } return { success: false, reason: e.message }
} }

View file

@ -9,8 +9,8 @@ export default defineEventHandler(async (event) => {
const body = await useBody(event) const body = await useBody(event)
body.imgs = [event.req.file?.filename] body.imgs = [event.req.file?.filename]
add(body) add(body)
sendRedirect(event, '/') return sendRedirect(event, 'http://localhost:3000')
} catch (e) { } catch (e) {
return { success: false, reason: e.message } return { success: false, reason: e.message }
} }
}) })

View file

@ -7,6 +7,7 @@ function load () {
db.exec('CREATE TABLE IF NOT EXISTS cosette (uuid TEXT PRIMARY KEY, name TEXT NOT NULL, description TEXT, tags TEXT, images TEXT, updatedAt DATETIME DEFAULT CURRENT_TIMESTAMP)') db.exec('CREATE TABLE IF NOT EXISTS cosette (uuid TEXT PRIMARY KEY, name TEXT NOT NULL, description TEXT, tags TEXT, images TEXT, updatedAt DATETIME DEFAULT CURRENT_TIMESTAMP)')
db.exec('CREATE TABLE IF NOT EXISTS chan (uuid TEXT PRIMARY KEY, cosetta_uuid REFERENCES cosette(uuid), message TEXT, updatedAt DATETIME DEFAULT CURRENT_TIMESTAMP)') db.exec('CREATE TABLE IF NOT EXISTS chan (uuid TEXT PRIMARY KEY, cosetta_uuid REFERENCES cosette(uuid), message TEXT, updatedAt DATETIME DEFAULT CURRENT_TIMESTAMP)')
} }
// TODO: da gestire in qualche modo all'avvio
// load() // load()
export function add (cosetta) { export function add (cosetta) {
@ -42,10 +43,8 @@ export function getAll (limit=0, offset=0, tags=[], search='') {
export function addComment (comment) { export function addComment (comment) {
console.error('sono dentro addComment', comment)
const q = db.prepare('INSERT INTO chan (uuid, cosetta_uuid, message) VALUES(:uuid, :cosetta_uuid, :message)') const q = db.prepare('INSERT INTO chan (uuid, cosetta_uuid, message) VALUES(:uuid, :cosetta_uuid, :message)')
comment.uuid = v4() comment.uuid = v4()
console.error(comment)
q.run(comment) q.run(comment)
return comment return comment
} }

View file

@ -293,10 +293,10 @@
resolved "https://registry.yarnpkg.com/@csstools/selector-specificity/-/selector-specificity-2.0.2.tgz#1bfafe4b7ed0f3e4105837e056e0a89b108ebe36" resolved "https://registry.yarnpkg.com/@csstools/selector-specificity/-/selector-specificity-2.0.2.tgz#1bfafe4b7ed0f3e4105837e056e0a89b108ebe36"
integrity sha512-IkpVW/ehM1hWKln4fCA3NzJU8KwD+kIOvPZA4cqxoJHtE21CCzjyp+Kxbu0i5I4tBNOlXPL9mjwnWlL0VEG4Fg== integrity sha512-IkpVW/ehM1hWKln4fCA3NzJU8KwD+kIOvPZA4cqxoJHtE21CCzjyp+Kxbu0i5I4tBNOlXPL9mjwnWlL0VEG4Fg==
"@iconify/json@^2.1.88": "@iconify/json@^2.1.91":
version "2.1.88" version "2.1.91"
resolved "https://registry.yarnpkg.com/@iconify/json/-/json-2.1.88.tgz#05d987dedab3dc9f95407596be5823beb925d6b4" resolved "https://registry.yarnpkg.com/@iconify/json/-/json-2.1.91.tgz#d66e9a8e41ebbde74fa4278c31777dbf54393b1f"
integrity sha512-oPrKWtn7rZDwhAGdIMCzxpcKkXpRET3lfvVgwqiMJaCTx4jKbXJYHGw/F2PuiGkvxFi6pNNayBZ9q7+R9ZXKmg== integrity sha512-GjvdX5E09r0hjRp6woaR2bUPpziMboqk3Cdb1cVi4bZTQT4hdHOBJ8IxV9LNgBTfeNgbxWIf1w+IhFG1xawvrg==
dependencies: dependencies:
"@iconify/types" "*" "@iconify/types" "*"
pathe "^0.3.0" pathe "^0.3.0"
@ -6270,10 +6270,10 @@ unplugin-icons@^0.14.8:
local-pkg "^0.4.2" local-pkg "^0.4.2"
unplugin "^0.8.0" unplugin "^0.8.0"
unplugin-vue-components@^0.22.3: unplugin-vue-components@^0.22.4:
version "0.22.3" version "0.22.4"
resolved "https://registry.yarnpkg.com/unplugin-vue-components/-/unplugin-vue-components-0.22.3.tgz#e799e49486476b5413d3b0983874bc8a92429ad4" resolved "https://registry.yarnpkg.com/unplugin-vue-components/-/unplugin-vue-components-0.22.4.tgz#774a96339368f3b8436fa7c20e059d9fee42c983"
integrity sha512-f31VCJF0K9oXCzKizJqNpmQz2XYTA0gjq+E5zM3hB8JxZ6cy5sXxO91fK2pI1TFGeM3JCe6yC9BJDymkMbXnNg== integrity sha512-2rRZcM9OnJGXnYxQNfaceEYuPeVACcWySIjy8WBwIiN3onr980TmA3XE5pRJFt8zoQrUA+c46oyIq96noLqrEQ==
dependencies: dependencies:
"@antfu/utils" "^0.5.2" "@antfu/utils" "^0.5.2"
"@rollup/pluginutils" "^4.2.1" "@rollup/pluginutils" "^4.2.1"