This repository has been archived by the owner on Dec 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #8: allow users to favorite articles
- Loading branch information
Showing
8 changed files
with
121 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<turbo-frame id="favorite-{{ article.slug }}"> | ||
{% if request.user.is_authenticated %} | ||
<form | ||
method="POST" | ||
action="{% url 'article_favorite' article.slug %}" | ||
class="list-inline-item" | ||
> | ||
{% csrf_token %} | ||
<button class="btn btn-sm {{ active_class }}"> | ||
<i class="ion-heart"></i> | ||
{% if favorited %} Unfavorite Post {% else %} Favorite Post | ||
{% endif %} | ||
<span class="counter">({{ article.favorited_by__count }})</span> | ||
</button> | ||
</form> | ||
{% else %} | ||
<a | ||
href="{% url 'login' %}?next={{request.path}}" | ||
class="btn btn-sm btn-outline-primary" | ||
target="_top" | ||
> | ||
<i class="ion-heart"></i> | ||
Favorite Post | ||
<span class="counter">({{ article.favorited_by__count }})</span> | ||
</a> | ||
{% endif %} {% if request.method == 'POST' %} | ||
<script> | ||
document | ||
.querySelectorAll("#favorite-{{article.slug}}") | ||
.forEach((e) => e.attributeChangedCallback("src")); | ||
</script> | ||
{% endif %} | ||
</turbo-frame> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<turbo-frame id="favorite-{{ article.slug }}"> | ||
{% if request.user.is_authenticated %} | ||
<form | ||
method="POST" | ||
action="{% url 'article_favorite' article.slug %}?mini=true" | ||
class="list-inline-item pull-xs-right" | ||
> | ||
{% csrf_token %} | ||
<button class="btn {{ active_class }} btn-sm pull-xs-right"> | ||
<i class="ion-heart"></i> {{ article.favorited_by__count }} | ||
</button> | ||
</form> | ||
{% else %} | ||
<a | ||
href="{% url 'login' %}?next={{request.path}}" | ||
class="btn btn-sm btn-outline-primary pull-xs-right" | ||
target="_top" | ||
> | ||
<i class="ion-heart"></i> {{ article.favorited_by__count }} | ||
</a> | ||
{% endif %} | ||
</turbo-frame> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,10 +18,15 @@ | |
<!-- Import the custom Bootstrap 4 theme from our hosted CDN --> | ||
<link rel="stylesheet" href="https://demo.productionready.io/main.css" /> | ||
<script | ||
src="https://unpkg.com/@hotwired/[email protected].2/dist/turbo.es2017-umd.js" | ||
src="https://unpkg.com/@hotwired/[email protected].3/dist/turbo.es2017-umd.js" | ||
defer | ||
data-turbo-track="reload" | ||
></script> | ||
<script> | ||
function toTop() { | ||
window.scrollTo(0, 0); | ||
} | ||
</script> | ||
</head> | ||
<body> | ||
<nav class="navbar navbar-light"> | ||
|