lesion 1 year ago
parent
commit
5c7fdf48bb
6 changed files with 22 additions and 19 deletions
  1. 2 2
      package.json
  2. 7 3
      pages/c/[cosetta].vue
  3. 2 2
      server/api/comment.post.js
  4. 2 2
      server/api/cosette.post.js
  5. 1 2
      server/controller.js
  6. 8 8
      yarn.lock

+ 2 - 2
package.json

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

+ 7 - 3
pages/c/[cosetta].vue

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

+ 2 - 2
server/api/comment.post.js

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

+ 2 - 2
server/api/cosette.post.js

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

+ 1 - 2
server/controller.js

@@ -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 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()
 
 export function add (cosetta) {
@@ -42,10 +43,8 @@ export function getAll (limit=0, offset=0, tags=[], search='') {
 
 
 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)')
   comment.uuid = v4()
-  console.error(comment)
   q.run(comment)
   return comment
 }

+ 8 - 8
yarn.lock

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