Browse Source

remove commenting feature

pull/1/head
wes 7 years ago
parent
commit
78a0be9e98
  1. 28
      src/comment.py
  2. 4
      src/posts.py
  3. 8
      src/scripts/blog.tag
  4. 17
      src/scripts/comment.tag
  5. 113
      src/scripts/comments.tag
  6. 2
      src/scripts/post.tag
  7. 2
      src/scripts/riotblog.js
  8. 50
      src/styles/riotblog.scss
  9. 10
      src/website.py

28
src/comment.py

@ -1,28 +0,0 @@
from json import dumps
from time import time
from uuid import uuid4
def comment(author, title, text, t, uid):
return {
"time" : t,
"id" : uid,
"title" : title,
"author" : author,
"text" : text
}
testcomments = {
1 : dumps(
[
comment("Person 1", "Two", "A Comment here", 1, str(uuid4())),
comment("Person 2", "One", "Some other comment", 2, str(uuid4())),
comment("Person 3", "Three", "My opinion is correct", 3, str(uuid4()))
]),
2 : dumps(
[
comment("Person 1", "Two", "A cool terrible Comment here", 1, str(uuid4())),
comment("Person 2", "One", "Some other awful comment", 2, str(uuid4())),
comment("Person 3", "Three", "My opinion is not correct", 3, str(uuid4()))
])
}

4
src/posts.py

@ -3,7 +3,6 @@
import couchdb
from flask import jsonify
from flask_marshmallow import Marshmallow
#from comment import comment
class Posts:
def __init__(self, host=None, port=None):
@ -27,6 +26,3 @@ class Posts:
def getposts(self, limit, start):
result = self.db.iterview("blogPosts/blog-posts", 10, include_docs=True, limit=limit, skip=start)
return jsonify(list(result))
def getcomments(self, postID):
return jsonify([])

8
src/scripts/blog.tag

@ -0,0 +1,8 @@
<blog>
<script>
import route from 'riot-route/lib/tag';
</script>
</blog>

17
src/scripts/comment.tag

@ -1,17 +0,0 @@
<comment>
<div class="comment centered">
<div class="card">
<div class="card-header">
<h4 class="card-title">Comment posted by {author}</h4>
</div>
<div class="card-body comment-body">
{ text }
</div>
<button if={delete !== undefined} onclick={delete} class="btn">
Delete this comment
</button>
</div>
</div>
<script>
</script>
</comment>

113
src/scripts/comments.tag

@ -1,113 +0,0 @@
<comments>
<div if={loading} class="loading comments-loader"></div>
<comment if={!loading} each={R.sortBy(R.prop("time"), R.values(this.comments))} data="{this}"></comment>
<textarea onfocus={clearplaceholder}
onblur={checkplaceholder}
oninput={echo}
__disabled={disabled}
class={"form-input comments centered " + this.maxed}
ref="textarea"
rows="10"
cols="50"
maxlength={this.maxlength}>
{ placeholder }
</textarea>
<button onclick={submit} class="btn comment-submit">
Submit Comment
</button>
<div if={this.warn} class="toast toast-danger maxwarn centered">
<button
onclick={this.closewarning}
class="btn btn-clear float-right">
</button>
Your comment is too long!
</div>
<script>
import 'whatwg-fetch';
import { default as R } from 'ramda';
this.R = R;
this.comments = [];
this.maxlength = 700;
this.placeholder = "Comment on this post";
this.focused = false;
this.maxed = "";
this.warn = false;
this.disabled = "";
this.loading = true;
clearplaceholder() {
if (!this.focused) {
this.update({
"placeholder" : "",
"focused" : true
})
}
}
checkplaceholder() {
if (this.refs.textarea.value.trim().length == 0) {
this.update({
"placeholder" : "Comment here!",
"focused" : false
});
}
}
closewarning() {
this.update({"warn" : false});
}
echo(ev) {
if (this.refs.textarea.value.length >= this.maxlength) {
this.update({
"maxed" : "maxinput",
"warn" : true
});
}
else {
this.update({
"maxed" : "",
"warn" : false
});
window.setTimeout(this.closewarning, 15000);
}
}
var self = this;
getComments(pid) {
fetch("/blog/comments/"+pid)
.then(
function(resp) {
return resp.text();
})
.then(
function(body) {
var parsed =JSON.parse(body);
parsed.map(function(comment) { self.comments[comment["id"]] = comment; } );
self.update();
self.update(
{
"loading" : false
});
});
}
submit() {
var id = Math.random();
this.comments[id] = {
"author" : "name",
"text" : this.refs.textarea.value,
"delete" : (() => { delete self.comments[id]; self.update(); })
};
this.update();
}
this.on("mount",
function() {
this.getComments(self.opts.pid);
});
</script>
</comments>

2
src/scripts/post.tag

@ -24,8 +24,6 @@
{ this.content }
</p>
<div class="divider"></div>
<comments pid={this.pid}>
</comments>
</div>
<script>

2
src/scripts/riotblog.js

@ -1,6 +1,4 @@
import riot from 'riot';
import './comments.tag';
import './comment.tag';
import './bbutton.tag';
import './post.tag';
import './posts.tag';

50
src/styles/riotblog.scss

@ -2,10 +2,6 @@
text-align: center;
}
.comment-submit {
margin-top: 10px;
}
.post-content {
max-width: 50%;
text-align: justify;
@ -24,52 +20,6 @@
}
}
.comment-block, .comments, .maxwarn {
max-width: 30%;
}
@media (max-width: 700px) {
.comment-block, .comments, .maxwarn {
max-width: 50%;
}
}
@media (max-width: 500px) {
.comment-block, .comments, .maxwarn {
max-width: 70%;
}
}
.comments {
margin-top: 5%;
}
.comment {
margin-top: 2%;
max-width: 40%;
}
@media (max-width: 700px) {
.comment {
max-width: 65%;
}
}
@media (max-width: 500px) {
.comment {
max-width: 85%;
}
}
.comments-loader {
margin-top: 2%;
}
.comment-body {
margin-left: 10px;
margin-right: 10px;
}
.rounded-button {
border-radius: 13px;
}

10
src/website.py

@ -9,8 +9,6 @@ from urllib.parse import unquote
from urllib.parse import quote, unquote
from json import dumps, loads
from comment import testcomments
from werkzeug.contrib.cache import MemcachedCache
cache = MemcachedCache(['127.0.0.1:11211'])
@ -66,14 +64,6 @@ def NeverWhere(configfile=None):
def send_style(filename):
return send_from_directory("/srv/http/riotblog/styles", filename)
@app.route("/blog/comments/<pid>")
def comments(pid):
try:
return testcomments.get(int(pid), dumps([]))
except ValueError as e:
print(e)
return dumps([])
@app.route("/blog/insert/")
def insert():
return posts.savepost(**request.args)

Loading…
Cancel
Save