From c697b5f9829156da24bfa95b4d7ecf5e62a344de Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Thu, 24 Feb 2022 04:27:53 +0100 Subject: [PATCH] Move options lists to constants under 'Preferences' Also fix the lists for the homepage and feeds. They have to be different (e.g Search is not a feed, but a valid homepage) --- src/invidious/user/preferences.cr | 41 ++++++++++++ src/invidious/views/user/preferences.ecr | 82 +++++++++++++----------- 2 files changed, 84 insertions(+), 39 deletions(-) diff --git a/src/invidious/user/preferences.cr b/src/invidious/user/preferences.cr index b3059403..cf643a8e 100644 --- a/src/invidious/user/preferences.cr +++ b/src/invidious/user/preferences.cr @@ -2,6 +2,43 @@ struct Preferences include JSON::Serializable include YAML::Serializable + # ------------------- + # Constants + # ------------------- + + SPEEDS = {2.0, 1.75, 1.5, 1.25, 1.0, 0.75, 0.5, 0.25} + + QUALITIES = {"dash", "hd720", "medium", "small"} + + DASH_QUALITIES = { + "auto", "best", "4320p", "2160p", "1440p", "1080p", + "720p", "480p", "360p", "240p", "144p", "worst", + } + + COMMENT_SOURCES = {"none", "youtube", "reddit"} + + THEMES = {"auto", "light", "dark"} + PLAYER_STYLES = {"invidious", "youtube"} + + FEED_OPTIONS = {"none", "Popular", "trending"} + FEED_OPTIONS_USER = {"none", "Popular", "trending", "Subscriptions", "Playlists"} + + HOMEPAGES = {"Search", "Popular", "trending"} + HOMEPAGES_USER = {"Search", "Popular", "trending", "Subscriptions", "Playlists"} + + SORT_OPTIONS = { + "published", + "published - reverse", + "alphabetically", + "alphabetically - reverse", + "channel name", + "channel name - reverse", + } + + # ------------------- + # Properties + # ------------------- + property annotations : Bool = CONFIG.default_user_preferences.annotations property annotations_subscribed : Bool = CONFIG.default_user_preferences.annotations_subscribed property autoplay : Bool = CONFIG.default_user_preferences.autoplay @@ -56,6 +93,10 @@ struct Preferences property volume : Int32 = CONFIG.default_user_preferences.volume property save_player_pos : Bool = CONFIG.default_user_preferences.save_player_pos + # ------------------- + # Converter modules + # ------------------- + module BoolToString def self.to_json(value : String, json : JSON::Builder) json.string value diff --git a/src/invidious/views/user/preferences.ecr b/src/invidious/views/user/preferences.ecr index dbb5e9db..48aac80c 100644 --- a/src/invidious/views/user/preferences.ecr +++ b/src/invidious/views/user/preferences.ecr @@ -40,20 +40,20 @@
@@ -61,9 +61,9 @@
<% end %> @@ -78,9 +78,9 @@ <% preferences.comments.each_with_index do |comments, index| %> <% end %> @@ -144,18 +144,18 @@
@@ -164,30 +164,34 @@ checked<% end %>> - <% if env.get?("user") %> - <% feed_options = {"", "Popular", "Trending", "Subscriptions", "Playlists"} %> - <% else %> - <% feed_options = {"", "Popular", "Trending"} %> - <% end %> + <%- + if env.get?("user") + feed_options = Preferences::FEED_OPTIONS_USER + homepages = Preferences::HOMEPAGES_USER + else + feed_options = Preferences::FEED_OPTIONS + homepages = Preferences::HOMEPAGES + end + -%>
- <% (feed_options.size - 1).times do |index| %> + <%- (feed_options.size - 1).times do |index| -%> - <% end %> + <%- end -%>
<% if env.get? "user" %>
@@ -224,9 +228,9 @@
@@ -263,21 +267,21 @@
- <% (feed_options.size - 1).times do |index| %> + <%- (feed_options.size - 1).times do |index| -%> - <% end %> + <%- end -%>