add ability to remove a tag from a paper as well

This commit is contained in:
Andrej Karpathy
2021-11-14 21:49:34 -08:00
parent 7cbb90a480
commit abb83effed
3 changed files with 51 additions and 21 deletions
+24
View File
@@ -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/<pid>/<tag>')
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/<tag>')
def delete_tag(tag=None):
user = 'root'
+9 -4
View File
@@ -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) => <UTag key={ix} tag={utxt} />);
const similar_url = "/?rank=tags&pid=" + p.id;
return (
<div class='rel_paper'>
<div class="rel_add" onClick={adder}>+</div>
<div class="rel_score">{p.weight.toFixed(2)}</div>
<div class='rel_title'><a href={'http://arxiv.org/abs/' + p.id}>{p.title}</a></div>
<div class='rel_authors'>{p.authors}</div>
<div class="rel_time">{p.time}</div>
<div class='rel_tags'>{p.tags}</div>
<div class='rel_utags'>{utags}</div>
<div class='rel_utags'>
<div class="rel_utag rel_utag_add" onClick={adder}>+</div>
<div class="rel_utag rel_utag_sub" onClick={subber}>-</div>
{utags}
</div>
<div class='rel_abs'>{p.summary}</div>
<div class='rel_more'><a href={similar_url}>similar</a></div>
</div>
@@ -64,7 +69,7 @@ const TagList = props => {
.then(response => console.log(response.text()));
return (
<div>
<div class="rel_del" onClick={deleter}>-</div>
<div class="rel_tag" onClick={deleter}>-</div>
<div id="tagList" class="rel_utags">
{tlst}
</div>
+18 -17
View File
@@ -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;