aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMark Powers <mark@marks.kitchen>2020-12-30 22:28:39 -0600
committerMark Powers <mark@marks.kitchen>2020-12-30 22:28:39 -0600
commit5137bb9b277fcd45327680166c9e39f26ec48c45 (patch)
treea6084de81b4e993d29b34cecf8bf664212fbf654 /src
parent572671a916335fbbe8766b37b683b8a585c49abd (diff)
Add like button to posts
Diffstat (limited to 'src')
-rw-r--r--src/css/styles.css17
-rw-r--r--src/index.js6
-rw-r--r--src/server.js10
-rw-r--r--src/templates/feed.html5
4 files changed, 34 insertions, 4 deletions
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 @@
<a class="tag" href="/tags/{{this}}">{{this}}</a>
{{/each}}
</span>
+ <a class="cool btn btn-secondary" href="/post/like/{{this.type}}/{{this.id}}">
+ &#128077; ({{this.likes}})
+ </a>
</p>
</div>
{{/each}}
-</div> \ No newline at end of file
+</div>