From dbdf2ad23a3956617a124b193a4e7f2f2a4896e6 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Tue, 29 Oct 2024 18:27:53 +0100 Subject: [PATCH] Routes: Simplify actions in watch_ajax --- assets/js/watched_widget.js | 4 ++-- src/invidious/routes/watch.cr | 14 +++----------- src/invidious/views/components/item.ecr | 2 +- src/invidious/views/feeds/history.ecr | 2 +- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/assets/js/watched_widget.js b/assets/js/watched_widget.js index f1ac9cb4..06af62cc 100644 --- a/assets/js/watched_widget.js +++ b/assets/js/watched_widget.js @@ -6,7 +6,7 @@ function mark_watched(target) { var tile = target.parentNode.parentNode.parentNode.parentNode.parentNode; tile.style.display = 'none'; - var url = '/watch_ajax?action_mark_watched=1&redirect=false' + + var url = '/watch_ajax?action=mark_watched&redirect=false' + '&id=' + target.getAttribute('data-id'); helpers.xhr('POST', url, {payload: payload}, { @@ -22,7 +22,7 @@ function mark_unwatched(target) { var count = document.getElementById('count'); count.textContent--; - var url = '/watch_ajax?action_mark_unwatched=1&redirect=false' + + var url = '/watch_ajax?action=mark_unwatched&redirect=false' + '&id=' + target.getAttribute('data-id'); helpers.xhr('POST', url, {payload: payload}, { diff --git a/src/invidious/routes/watch.cr b/src/invidious/routes/watch.cr index aabe8dfc..27b96730 100644 --- a/src/invidious/routes/watch.cr +++ b/src/invidious/routes/watch.cr @@ -241,18 +241,10 @@ module Invidious::Routes::Watch end end - if env.params.query["action_mark_watched"]? - action = "action_mark_watched" - elsif env.params.query["action_mark_unwatched"]? - action = "action_mark_unwatched" - else - return env.redirect referer - end - - case action - when "action_mark_watched" + case action = env.params.query["action"]? + when "mark_watched" Invidious::Database::Users.mark_watched(user, id) - when "action_mark_unwatched" + when "mark_unwatched" Invidious::Database::Users.mark_unwatched(user, id) else return error_json(400, "Unsupported action #{action}") diff --git a/src/invidious/views/components/item.ecr b/src/invidious/views/components/item.ecr index dc8421a5..c966a926 100644 --- a/src/invidious/views/components/item.ecr +++ b/src/invidious/views/components/item.ecr @@ -128,7 +128,7 @@
<%- if env.get? "show_watched" -%> -
" method="post"> + " method="post"> ">