From 5a5b666794b688881eb1e1635bf9f2ceb3cc4346 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Sat, 19 Dec 2020 22:35:50 -0600 Subject: Add title to posts --- src/index.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/index.js') diff --git a/src/index.js b/src/index.js index 4b9a3c6..a94f8d0 100644 --- a/src/index.js +++ b/src/index.js @@ -53,6 +53,9 @@ function setUpModels(){ type: { type: Sequelize.STRING, allowNull: false, + }, + title: { + type: Sequelize.STRING, },}), "pictures": database.define('pictures', { source: { type: Sequelize.TEXT, allowNull: false}, -- cgit v1.2.3 From 5137bb9b277fcd45327680166c9e39f26ec48c45 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Wed, 30 Dec 2020 22:28:39 -0600 Subject: Add like button to posts --- src/css/styles.css | 17 +++++++++++++++-- src/index.js | 6 +++++- src/server.js | 10 ++++++++++ src/templates/feed.html | 5 ++++- 4 files changed, 34 insertions(+), 4 deletions(-) (limited to 'src/index.js') diff --git a/src/css/styles.css b/src/css/styles.css index 3a555cb..88d8e68 100644 --- a/src/css/styles.css +++ b/src/css/styles.css @@ -8,7 +8,6 @@ --btn-hover: #0a0; --light-text: #aaa; } - body { width: 60%; @@ -142,7 +141,6 @@ p { padding: 1px 3px; border: 1px solid var(--btn-text); border-radius: 3px; - width: 100%; max-width: 100px; line-height: 2em; text-align: center; @@ -152,6 +150,7 @@ p { } .btn-primary { + width: 100%; height: 2em; font-size: 20px; background-color: var(--btn-color); @@ -162,6 +161,15 @@ p { background-color: var(--btn-hover); } +.btn-secondary { + background-color: var(--btn-color); + color: var(--btn-text); +} + +.btn-secondary:hover{ + background-color: var(--btn-hover); +} + .date { font-style: italic; margin: 0em; @@ -223,3 +231,8 @@ a.navigation:visited, a.navigation:link { .email::after { content: "@marks.kitchen"; } + +a.cool { + float: right; +} + diff --git a/src/index.js b/src/index.js index a94f8d0..7ceecf0 100644 --- a/src/index.js +++ b/src/index.js @@ -56,7 +56,11 @@ function setUpModels(){ }, title: { type: Sequelize.STRING, - },}), + }, + likes: { + type: Sequelize.INTEGER, + } + }), "pictures": database.define('pictures', { source: { type: Sequelize.TEXT, allowNull: false}, }), diff --git a/src/server.js b/src/server.js index d820cd7..cd76b5d 100644 --- a/src/server.js +++ b/src/server.js @@ -146,6 +146,15 @@ function setUpRoutes(models, jwtFunctions, database, templates) { let body = templates["blog-single"]({posts, date}); res.status(200).send(body) }) + server.get('/post/like/:type/:id', async (req, res) => { + let type = req.params.type + let id = req.params.id + var post = await models.posts.findOne({ + where: { type, id }, + }); + post.update({likes: post.likes+1}) + res.redirect(`/post/${type}/${id}`); + }) server.get('/tags/:name', async (req, res) => { const { name } = req.params; const postsWithTag = await models.tags.findAll({ attributes: ["postId"], where: { text: name } }) @@ -258,6 +267,7 @@ function setUpRoutes(models, jwtFunctions, database, templates) { const type = req.body.type req.body.description = marked(req.body.description) const newPost = await models.posts.create(req.body); + newPost.likes = 0 req.files.forEach(async (file) => { await models.pictures.create({ "source": "uploads/" + file.filename, "postId": newPost.id }); console.log("uploaded ", file.path); diff --git a/src/templates/feed.html b/src/templates/feed.html index d7494a2..ae3494c 100644 --- a/src/templates/feed.html +++ b/src/templates/feed.html @@ -21,7 +21,10 @@ {{this}} {{/each}} + + 👍 ({{this.likes}}) +

{{/each}} - \ No newline at end of file + -- cgit v1.2.3