add subscribe and unsubscribe buttons for channels and playlists, #81

This commit is contained in:
simon 2021-11-25 16:41:58 +07:00
parent bad129d630
commit 39304ff2bd
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
7 changed files with 29 additions and 5 deletions

View File

@ -86,7 +86,7 @@
{% if channel.source.channel_subscribed %} {% if channel.source.channel_subscribed %}
<button type="button" id="{{ channel.source.channel_id }}" onclick="unsubscribe(this.id)" title="Unsubscribe from {{ channel.source.channel_name }}">Unsubscribe</button> <button type="button" id="{{ channel.source.channel_id }}" onclick="unsubscribe(this.id)" title="Unsubscribe from {{ channel.source.channel_name }}">Unsubscribe</button>
{% else %} {% else %}
false <button type="button" id="{{ channel.source.channel_id }}" onclick="subscribe(this.id)" title="Subscribe to {{ channel.source.channel_name }}">Subscribe</button>
{% endif %} {% endif %}
</p> </p>
</div> </div>

View File

@ -28,7 +28,7 @@
{% if channel_info.channel_subscribed %} {% if channel_info.channel_subscribed %}
<button type="button" id="{{ channel_info.channel_id }}" onclick="unsubscribe(this.id)" title="Unsubscribe from {{ channel_info.channel_name }}">Unsubscribe</button> <button type="button" id="{{ channel_info.channel_id }}" onclick="unsubscribe(this.id)" title="Unsubscribe from {{ channel_info.channel_name }}">Unsubscribe</button>
{% else %} {% else %}
false <button type="button" id="{{ channel_info.channel_id }}" onclick="subscribe(this.id)" title="Subscribe to {{ channel_info.channel_name }}">Subscribe</button>
{% endif %} {% endif %}
</p> </p>
{% if channel_info.channel_active %} {% if channel_info.channel_active %}

View File

@ -62,6 +62,14 @@
<div class="playlist-desc {{ view_style }}"> <div class="playlist-desc {{ view_style }}">
<a href="{% url 'channel_id' playlist.source.playlist_channel_id %}"><h3>{{ playlist.source.playlist_channel }}</h3></a> <a href="{% url 'channel_id' playlist.source.playlist_channel_id %}"><h3>{{ playlist.source.playlist_channel }}</h3></a>
<a href="{% url 'playlist_id' playlist.source.playlist_id %}"><h2>{{ playlist.source.playlist_name }}</h2></a> <a href="{% url 'playlist_id' playlist.source.playlist_id %}"><h2>{{ playlist.source.playlist_name }}</h2></a>
<p>Last refreshed: {{ playlist.source.playlist_last_refresh }}</p>
<p>Subscribed:
{% if playlist.source.playlist_subscribed %}
<button type="button" id="{{ playlist.source.playlist_id }}" onclick="unsubscribe(this.id)" title="Unsubscribe from {{ playlist.source.playlist_name }}">Unsubscribe</button>
{% else %}
<button type="button" id="{{ playlist.source.playlist_id }}" onclick="subscribe(this.id)" title="Subscribe to {{ playlist.source.playlist_name }}">Subscribe</button>
{% endif %}
</p>
</div> </div>
</div> </div>
{% endfor %} {% endfor %}

View File

@ -28,7 +28,7 @@
{% if playlist_info.playlist_subscribed %} {% if playlist_info.playlist_subscribed %}
<button type="button" id="{{ playlist_info.playlist_id }}" onclick="unsubscribe(this.id)" title="Unsubscribe from {{ playlist_info.playlist_name }}">Unsubscribe</button> <button type="button" id="{{ playlist_info.playlist_id }}" onclick="unsubscribe(this.id)" title="Unsubscribe from {{ playlist_info.playlist_name }}">Unsubscribe</button>
{% else %} {% else %}
false <button type="button" id="{{ playlist_info.playlist_id }}" onclick="subscribe(this.id)" title="Subscribe to {{ playlist_info.playlist_name }}">Subscribe</button>
{% endif %} {% endif %}
</p> </p>
{% if playlist_info.playlist_active %} {% if playlist_info.playlist_active %}

View File

@ -997,6 +997,7 @@ class PostData:
"dl_pending": self.dl_pending, "dl_pending": self.dl_pending,
"queue": self.queue_handler, "queue": self.queue_handler,
"unsubscribe": self.unsubscribe, "unsubscribe": self.unsubscribe,
"subscribe": self.subscribe,
"sort_order": self.sort_order, "sort_order": self.sort_order,
"hide_watched": self.hide_watched, "hide_watched": self.hide_watched,
"show_subed_only": self.show_subed_only, "show_subed_only": self.show_subed_only,
@ -1100,6 +1101,13 @@ class PostData:
return {"success": True} return {"success": True}
def subscribe(self):
"""subscribe to channel or playlist, called from js buttons"""
id_sub = self.exec_val
print("subscribe to " + id_sub)
subscribe_to.delay(id_sub)
return {"success": True}
def sort_order(self): def sort_order(self):
"""change the sort between published to downloaded""" """change the sort between published to downloaded"""
sort_order = {"status": self.exec_val} sort_order = {"status": self.exec_val}

View File

@ -717,7 +717,7 @@ button:hover {
height: unset; height: unset;
background-color: var(--highlight-bg); background-color: var(--highlight-bg);
display: flex; display: flex;
flex-wrap: wrap-reverse; flex-wrap: wrap;
align-content: center; align-content: center;
} }

View File

@ -46,9 +46,17 @@ function isUnwatched(youtube_id) {
} }
function unsubscribe(id_unsub) { function unsubscribe(id_unsub) {
console.log(payload);
var payload = JSON.stringify({'unsubscribe': id_unsub}); var payload = JSON.stringify({'unsubscribe': id_unsub});
sendPost(payload); sendPost(payload);
document.getElementById(id_unsub).remove(); document.getElementById(id_unsub).replaceWith("You are unsubscribed.");
}
function subscribe(id_sub) {
var payload = JSON.stringify({'subscribe': id_sub});
console.log(payload);
sendPost(payload);
document.getElementById(id_sub).replaceWith("You are subscribed.");
} }
function changeView(image) { function changeView(image) {