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/css/styles.css | 4 ++++
src/html/admin.html | 3 +++
src/index.js | 3 +++
src/server.js | 40 ++--------------------------------------
src/templates/feed.html | 3 +++
5 files changed, 15 insertions(+), 38 deletions(-)
(limited to 'src')
diff --git a/src/css/styles.css b/src/css/styles.css
index f406104..ab634ec 100644
--- a/src/css/styles.css
+++ b/src/css/styles.css
@@ -30,6 +30,10 @@ h1 {
margin-left: 20px;
}
+.card-title {
+ margin-left: 0;
+}
+
@keyframes zoom-left {
0% {left: 100%; }
100% {left: 0;}
diff --git a/src/html/admin.html b/src/html/admin.html
index 3eaa60a..29e4b87 100644
--- a/src/html/admin.html
+++ b/src/html/admin.html
@@ -41,6 +41,9 @@
Create Post
\ No newline at end of file
+
--
cgit v1.2.3
From f2d7673d9743676fcd01d7ab26e7e60d9e21bc8f Mon Sep 17 00:00:00 2001
From: Mark Powers
Date: Wed, 30 Dec 2020 22:51:22 -0600
Subject: Fix likes starting at 0
---
src/server.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'src')
diff --git a/src/server.js b/src/server.js
index cd76b5d..07da08c 100644
--- a/src/server.js
+++ b/src/server.js
@@ -266,8 +266,8 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
try {
const type = req.body.type
req.body.description = marked(req.body.description)
+ req.body.likes = 0
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);
--
cgit v1.2.3
From 5b5dc610bc0da17fd006982de50b4dc74b134a54 Mon Sep 17 00:00:00 2001
From: Mark Powers
Date: Tue, 5 Jan 2021 20:25:10 -0600
Subject: Refactor likes to use JS to avoid redirect
---
src/css/styles.css | 3 ++-
src/js/like.js | 11 +++++++++++
src/server.js | 2 +-
src/templates/feed.html | 4 ++--
src/templates/header.html | 2 +-
5 files changed, 17 insertions(+), 5 deletions(-)
create mode 100644 src/js/like.js
(limited to 'src')
diff --git a/src/css/styles.css b/src/css/styles.css
index 88d8e68..4572569 100644
--- a/src/css/styles.css
+++ b/src/css/styles.css
@@ -147,6 +147,7 @@ p {
vertical-align: middle;
white-space: nowrap;
text-decoration: none;
+ cursor: pointer;
}
.btn-primary {
@@ -232,7 +233,7 @@ a.navigation:visited, a.navigation:link {
content: "@marks.kitchen";
}
-a.cool {
+.cool {
float: right;
}
diff --git a/src/js/like.js b/src/js/like.js
new file mode 100644
index 0000000..cd1e015
--- /dev/null
+++ b/src/js/like.js
@@ -0,0 +1,11 @@
+function likePost(type, id){
+ fetch(`/post/like/${type}/${id}`)
+ .then(response => response.json())
+ .then(response => {
+ console.log(response)
+ let btn_id=`btn_${type}_${id}`
+ let el = document.getElementById(btn_id)
+ el.innerText = `👍 (${response.likes})`
+ })
+}
+
diff --git a/src/server.js b/src/server.js
index 07da08c..773feb0 100644
--- a/src/server.js
+++ b/src/server.js
@@ -153,7 +153,7 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
where: { type, id },
});
post.update({likes: post.likes+1})
- res.redirect(`/post/${type}/${id}`);
+ res.status(200).send({likes: post.likes});
})
server.get('/tags/:name', async (req, res) => {
const { name } = req.params;
diff --git a/src/templates/feed.html b/src/templates/feed.html
index ae3494c..3ea4f16 100644
--- a/src/templates/feed.html
+++ b/src/templates/feed.html
@@ -21,9 +21,9 @@
{{this}}
{{/each}}
-
+
👍 ({{this.likes}})
-
+
{{/each}}
diff --git a/src/templates/header.html b/src/templates/header.html
index 2ceebfd..1989b04 100644
--- a/src/templates/header.html
+++ b/src/templates/header.html
@@ -2,4 +2,4 @@
-
+
--
cgit v1.2.3