Add thin mode

This commit is contained in:
Omar Roth 2018-07-26 12:09:29 -05:00
parent 1eedd6ebf9
commit 8764b298ad
6 changed files with 33 additions and 7 deletions

View file

@ -1359,6 +1359,10 @@ post "/preferences" do |env|
dark_mode ||= "off" dark_mode ||= "off"
dark_mode = dark_mode == "on" dark_mode = dark_mode == "on"
thin_mode = env.params.body["thin_mode"]?.try &.as(String)
thin_mode ||= "off"
thin_mode = thin_mode == "on"
max_results = env.params.body["max_results"]?.try &.as(String).to_i max_results = env.params.body["max_results"]?.try &.as(String).to_i
max_results ||= 40 max_results ||= 40
@ -1376,6 +1380,7 @@ post "/preferences" do |env|
"quality" => quality, "quality" => quality,
"volume" => volume, "volume" => volume,
"dark_mode" => dark_mode, "dark_mode" => dark_mode,
"thin_mode" => thin_mode,
"max_results" => max_results, "max_results" => max_results,
"sort" => sort, "sort" => sort,
"latest_only" => latest_only, "latest_only" => latest_only,

View file

@ -24,6 +24,7 @@ DEFAULT_USER_PREFERENCES = Preferences.from_json({
"quality" => "hd720", "quality" => "hd720",
"volume" => 100, "volume" => 100,
"dark_mode" => false, "dark_mode" => false,
"thin_mode " => false,
"max_results" => 40, "max_results" => 40,
"sort" => "published", "sort" => "published",
"latest_only" => false, "latest_only" => false,
@ -145,14 +146,20 @@ class User
}) })
end end
# TODO: Migrate preferences so this will not be nilable
class Preferences class Preferences
JSON.mapping({ JSON.mapping({
video_loop: Bool, video_loop: Bool,
autoplay: Bool, autoplay: Bool,
speed: Float32, speed: Float32,
quality: String, quality: String,
volume: Int32, volume: Int32,
dark_mode: Bool, dark_mode: Bool,
thin_mode: {
type: Bool,
nilable: true,
default: false,
},
max_results: Int32, max_results: Int32,
sort: String, sort: String,
latest_only: Bool, latest_only: Bool,

View file

@ -1,7 +1,10 @@
<div class="pure-u-1 pure-u-md-1-4"> <div class="pure-u-1 pure-u-md-1-4">
<div class="h-box"> <div class="h-box">
<a style="width:100%;" href="/watch?v=<%= video.id %>"> <a style="width:100%;" href="/watch?v=<%= video.id %>">
<% if env.get?("user") && env.get("user").as(User).preferences.thin_mode %>
<% else %>
<img style="width:100%;" src="https://i.ytimg.com/vi/<%= video.id %>/mqdefault.jpg"/> <img style="width:100%;" src="https://i.ytimg.com/vi/<%= video.id %>/mqdefault.jpg"/>
<% end %>
<p><%= video.title %></p> <p><%= video.title %></p>
</a> </a>
<p> <p>

View file

@ -1,7 +1,10 @@
<div class="pure-u-1 pure-u-md-1-4"> <div class="pure-u-1 pure-u-md-1-4">
<div class="h-box"> <div class="h-box">
<a style="width:100%;" href="/watch?v=<%= video.id %>"> <a style="width:100%;" href="/watch?v=<%= video.id %>">
<% if env.get?("user") && env.get("user").as(User).preferences.thin_mode %>
<% else %>
<img style="width:100%;" src="https://i.ytimg.com/vi/<%= video.id %>/mqdefault.jpg"/> <img style="width:100%;" src="https://i.ytimg.com/vi/<%= video.id %>/mqdefault.jpg"/>
<% end %>
<p><%= video.title %></p> <p><%= video.title %></p>
</a> </a>
<p> <p>

View file

@ -53,6 +53,11 @@ function update_value(element) {
<input name="dark_mode" id="dark_mode" type="checkbox" <% if user.preferences.dark_mode %>checked<% end %>> <input name="dark_mode" id="dark_mode" type="checkbox" <% if user.preferences.dark_mode %>checked<% end %>>
</div> </div>
<div class="pure-control-group">
<label for="thin_mode">Thin mode: </label>
<input name="thin_mode" id="thin_mode" type="checkbox" <% if user.preferences.thin_mode %>checked<% end %>>
</div>
<legend>Subscription preferences</legend> <legend>Subscription preferences</legend>
<div class="pure-control-group"> <div class="pure-control-group">
<label for="max_results">Number of videos shown in feed: </label> <label for="max_results">Number of videos shown in feed: </label>

View file

@ -278,7 +278,10 @@ String.prototype.supplant = function (o) {
<% rvs.each do |rv| %> <% rvs.each do |rv| %>
<% if rv.has_key?("id") %> <% if rv.has_key?("id") %>
<a href="/watch?v=<%= rv["id"] %>"> <a href="/watch?v=<%= rv["id"] %>">
<img style="width:100%;" alt="thumbnail" src="<%= rv["iurlmq"] %>"> <% if preferences && preferences.thin_mode %>
<% else %>
<img style="width:100%;" src="<%= rv["iurlmq"] %>">
<% end %>
<p style="width:100%"><%= rv["title"] %></p> <p style="width:100%"><%= rv["title"] %></p>
<p> <p>
<b style="width: 100%"><%= rv["author"] %></b> <b style="width: 100%"><%= rv["author"] %></b>