From 39304ff2bd799c37b23606979e3701f0ae84b509 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 25 Nov 2021 16:41:58 +0700 Subject: [PATCH] add subscribe and unsubscribe buttons for channels and playlists, #81 --- tubearchivist/home/templates/home/channel.html | 2 +- tubearchivist/home/templates/home/channel_id.html | 2 +- tubearchivist/home/templates/home/playlist.html | 8 ++++++++ tubearchivist/home/templates/home/playlist_id.html | 2 +- tubearchivist/home/views.py | 8 ++++++++ tubearchivist/static/css/style.css | 2 +- tubearchivist/static/script.js | 10 +++++++++- 7 files changed, 29 insertions(+), 5 deletions(-) diff --git a/tubearchivist/home/templates/home/channel.html b/tubearchivist/home/templates/home/channel.html index f83c5ea..99930d2 100644 --- a/tubearchivist/home/templates/home/channel.html +++ b/tubearchivist/home/templates/home/channel.html @@ -86,7 +86,7 @@ {% if channel.source.channel_subscribed %} {% else %} - false + {% endif %}

diff --git a/tubearchivist/home/templates/home/channel_id.html b/tubearchivist/home/templates/home/channel_id.html index 74b3092..75eaf76 100644 --- a/tubearchivist/home/templates/home/channel_id.html +++ b/tubearchivist/home/templates/home/channel_id.html @@ -28,7 +28,7 @@ {% if channel_info.channel_subscribed %} {% else %} - false + {% endif %}

{% if channel_info.channel_active %} diff --git a/tubearchivist/home/templates/home/playlist.html b/tubearchivist/home/templates/home/playlist.html index fbffba4..fa77820 100644 --- a/tubearchivist/home/templates/home/playlist.html +++ b/tubearchivist/home/templates/home/playlist.html @@ -62,6 +62,14 @@

{{ playlist.source.playlist_channel }}

{{ playlist.source.playlist_name }}

+

Last refreshed: {{ playlist.source.playlist_last_refresh }}

+

Subscribed: + {% if playlist.source.playlist_subscribed %} + + {% else %} + + {% endif %} +

{% endfor %} diff --git a/tubearchivist/home/templates/home/playlist_id.html b/tubearchivist/home/templates/home/playlist_id.html index 115f302..713bb68 100644 --- a/tubearchivist/home/templates/home/playlist_id.html +++ b/tubearchivist/home/templates/home/playlist_id.html @@ -28,7 +28,7 @@ {% if playlist_info.playlist_subscribed %} {% else %} - false + {% endif %}

{% if playlist_info.playlist_active %} diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index 6c14e82..a407187 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -997,6 +997,7 @@ class PostData: "dl_pending": self.dl_pending, "queue": self.queue_handler, "unsubscribe": self.unsubscribe, + "subscribe": self.subscribe, "sort_order": self.sort_order, "hide_watched": self.hide_watched, "show_subed_only": self.show_subed_only, @@ -1100,6 +1101,13 @@ class PostData: 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): """change the sort between published to downloaded""" sort_order = {"status": self.exec_val} diff --git a/tubearchivist/static/css/style.css b/tubearchivist/static/css/style.css index 5343796..7a2d1db 100644 --- a/tubearchivist/static/css/style.css +++ b/tubearchivist/static/css/style.css @@ -717,7 +717,7 @@ button:hover { height: unset; background-color: var(--highlight-bg); display: flex; - flex-wrap: wrap-reverse; + flex-wrap: wrap; align-content: center; } diff --git a/tubearchivist/static/script.js b/tubearchivist/static/script.js index d6c3a50..e5fdf9f 100644 --- a/tubearchivist/static/script.js +++ b/tubearchivist/static/script.js @@ -46,9 +46,17 @@ function isUnwatched(youtube_id) { } function unsubscribe(id_unsub) { + console.log(payload); var payload = JSON.stringify({'unsubscribe': id_unsub}); 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) {