From abb83effed35f80b5bbd55e61dfc3cdba6412c11 Mon Sep 17 00:00:00 2001 From: Andrej Karpathy Date: Sun, 14 Nov 2021 21:49:34 -0800 Subject: [PATCH] add ability to remove a tag from a paper as well --- serve.py | 24 ++++++++++++++++++++++++ static/paper_list.js | 13 +++++++++---- static/style.css | 35 ++++++++++++++++++----------------- 3 files changed, 51 insertions(+), 21 deletions(-) diff --git a/serve.py b/serve.py index 0cd1cfc..51f8c2c 100644 --- a/serve.py +++ b/serve.py @@ -251,6 +251,30 @@ def add(pid=None, tag=None): print("added paper %s to tag %s for user %s" % (pid, tag, user)) return "ok: " + str(d) # return back the user library for debugging atm +@app.route('/sub//') +def sub(pid=None, tag=None): + user = 'root' + with get_tags_db(flag='c') as tags_db: + + # if the user doesn't have any tags, there is nothing to do + if not user in tags_db: + return "user has no library of tags ¯\_(ツ)_/¯" + + # fetch the user library object + d = tags_db[user] + + # add the paper to the tag + if tag not in d: + return "user doesn't have the tag %s" % (tag, ) + else: + d[tag].remove(pid) + + # write back to database + tags_db[user] = d + + print("removed from paper %s the tag %s for user %s" % (pid, tag, user)) + return "ok: " + str(d) # return back the user library for debugging atm + @app.route('/del/') def delete_tag(tag=None): user = 'root' diff --git a/static/paper_list.js b/static/paper_list.js index 8cf02c3..ca94423 100644 --- a/static/paper_list.js +++ b/static/paper_list.js @@ -14,19 +14,24 @@ const UTag = props => { const Paper = props => { const p = props.paper; - const adder = () => fetch("/add/" + p.id + "/" + prompt("tag name:")) + const adder = () => fetch("/add/" + p.id + "/" + prompt("tag to add to this paper:")) + .then(response => console.log(response.text())); + const subber = () => fetch("/sub/" + p.id + "/" + prompt("tag to subtract from this paper:")) .then(response => console.log(response.text())); const utags = p.utags.map((utxt, ix) => ); const similar_url = "/?rank=tags&pid=" + p.id; return (
-
+
{p.weight.toFixed(2)}
{p.authors}
{p.time}
{p.tags}
-
{utags}
+
+
+
+
-
+ {utags} +
{p.summary}
@@ -64,7 +69,7 @@ const TagList = props => { .then(response => console.log(response.text())); return (
-
-
+
-
{tlst}
diff --git a/static/style.css b/static/style.css index bdd29c4..cffb11d 100644 --- a/static/style.css +++ b/static/style.css @@ -65,7 +65,18 @@ body { display: inline-block; margin-left: 5px; } -.rel_utag { +.rel_tag { /* deletes a whole tag */ + position: absolute; + color: white; + left: 7px; + cursor: pointer; + text-align: center; + border-radius: 3px; + background-color: #f55; + width: 22px; + height: 22px; +} +.rel_utag { /* shows an active tag for a paper */ background-color: #009; color: #fff; font-size: 16px; @@ -73,28 +84,18 @@ body { margin-right: 5px; padding: 0 4px 0 4px; border-radius: 4px; + cursor: pointer; } -.rel_add { - position: absolute; - width: 26px; - height: 26px; +.rel_utag_add { /* adds a paper to a tag */ background-color: #55f; - color: white; - left: 7px; - cursor: pointer; + margin-right: 2px; + width: 12px; text-align: center; - border-radius: 3px; } -.rel_del { - position: absolute; - width: 22px; - height: 22px; +.rel_utag_sub { /* subs a tag from a paper */ background-color: #f55; - color: white; - left: 7px; - cursor: pointer; + width: 12px; text-align: center; - border-radius: 3px; } .rel_utag a { color: white;