Skip to content

Commit

Permalink
update: change toast to upvote
Browse files Browse the repository at this point in the history
  • Loading branch information
HermanMartinus committed May 29, 2023
1 parent ef005df commit 1a229be
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
8 changes: 5 additions & 3 deletions templates/discover.html
Expand Up @@ -45,8 +45,10 @@ <h1>
<span>(<a href="{{ post.blog.dynamic_domain }}">{{ post.blog.useful_domain }}</a>)</span>
<br>
<small>Published {{ post.published_date|timesince }} ago</small>
-
<small><b>{{ post.upvotes }} toast{{ post.upvotes|pluralize }}</b></small>
<small>
<svg style="height:16px;margin: 0 -8px -4px 0;" viewBox="0 0 24 24" width="24" height="24" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round" class="css-i6dzq1"><polyline points="17 11 12 6 7 11"></polyline><polyline points="17 18 12 13 7 18"></polyline></svg>
{{ post.upvotes }}
</small>
{% if request.user.is_staff %}
<details>
<summary></summary>
Expand Down Expand Up @@ -97,7 +99,7 @@ <h1>
Score = log10(U) + (S / D * 8600)

Where,
U = Upvotes (toasts) of a post
U = Upvotes of a post
S = Seconds since Jan 1st, 2020
D = Days modifier (currently at 14)

Expand Down
7 changes: 4 additions & 3 deletions templates/search.html
Expand Up @@ -39,9 +39,10 @@ <h1>
<span>(<a href="{{ post.blog.dynamic_domain }}">{{ post.blog.useful_domain }}</a>)</span>
<br>
<small>Published {{ post.published_date|timesince }} ago</small>
-
<small><b>{{ post.upvotes }} toast{{ post.upvotes|pluralize }}</b></small>
<br>
<small>
<svg style="height:16px;margin: 0 -8px -4px 0;" viewBox="0 0 24 24" width="24" height="24" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round" class="css-i6dzq1"><polyline points="17 11 12 6 7 11"></polyline><polyline points="17 18 12 13 7 18"></polyline></svg>
{{ post.upvotes }}
</small>
<p>
{{ post.content|unmark }}
</p>
Expand Down
25 changes: 20 additions & 5 deletions templates/snippets/upvote_form.html
Expand Up @@ -4,12 +4,27 @@
<input hidden name="title" style="display:none"/>
{% csrf_token %}
{% if upvoted %}
<button disabled=true>▵ Toasted</button>
<button
disabled=true
style="padding:0; margin:0; border:0;background-color:inherit;color: salmon;"
title="Toasted"
>
{% else %}
<button>▵ Toast this post</button>
<button
style="padding:0; margin:0; border:0;background-color:inherit;color: inherit;"
title="Toast this post"
>
{% endif %}
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round" class="css-i6dzq1">
<polyline points="17 11 12 6 7 11"></polyline>
<polyline points="17 18 12 13 7 18"></polyline>
</svg>
<br>
<small class="upvote-count">{{ post.upvotes }}</small>
</button>

</form>
- <small class="upvote-count">{{ post.upvotes }} toast{{ post.upvotes|pluralize }}</small>

</small>
<script>
document.querySelector('#upvote-form').addEventListener('submit', (e) => {
Expand All @@ -21,8 +36,8 @@
});
const button = form.querySelector('button')
button.disabled = true
button.innerText = "▵ Toasted"
button.style.color = "salmon"
const upvoteCount = document.querySelector('.upvote-count')
upvoteCount.innerHTML = `${(parseInt(upvoteCount.innerHTML.split(" ")[0]) + 1)} toasts`
upvoteCount.innerHTML = `${(parseInt(upvoteCount.innerHTML.split(" ")[0]) + 1)}`
});
</script>

0 comments on commit 1a229be

Please sign in to comment.