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
Fix #8: allow users to favorite articles #24
Open
blopker
wants to merge
1
commit into
main
Choose a base branch
from
feature/favorites
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,34 @@ | ||
<turbo-frame id="favorite-{{ article.slug }}"> | ||
{% if request.method == 'POST' %} | ||
<script> | ||
document | ||
.querySelectorAll("#favorite-{{article.slug}}") | ||
.forEach((e) => e.attributeChangedCallback("src")); | ||
</script> | ||
|
||
{% else %} {% 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' %}" | ||
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 %} {% 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' %}" | ||
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"> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sneaky... sneaky... 😉