Merge pull request #43 from omarroth/thin-mode

Add thin mode
This commit is contained in:
Omar Roth 2018-07-26 18:00:13 -05:00 committed by GitHub
commit 20ddd3c025
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 7 deletions

View File

@ -1363,6 +1363,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
@ -1380,6 +1384,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,
@ -148,14 +149,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

@ -280,7 +280,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>