Add option to toggle light and dark to navbar
This commit is contained in:
parent
cfa76d21db
commit
cccf28aaf7
2 changed files with 58 additions and 26 deletions
|
@ -806,6 +806,28 @@ post "/preferences" do |env|
|
|||
env.redirect referer
|
||||
end
|
||||
|
||||
get "/toggle_theme" do |env|
|
||||
user = env.get? "user"
|
||||
|
||||
referer = env.params.query["referer"]?
|
||||
referer ||= "/feed/subscriptions"
|
||||
|
||||
if user
|
||||
user = user.as(User)
|
||||
preferences = user.preferences
|
||||
|
||||
if preferences.dark_mode
|
||||
preferences.dark_mode = false
|
||||
else
|
||||
preferences.dark_mode = true
|
||||
end
|
||||
|
||||
PG_DB.exec("UPDATE users SET preferences = $1 WHERE email = $2", preferences.to_json, user.email)
|
||||
end
|
||||
|
||||
env.redirect referer
|
||||
end
|
||||
|
||||
# /modify_notifications
|
||||
# will "ding" all subscriptions.
|
||||
# /modify_notifications?receive_all_updates=false&receive_no_updates=false
|
||||
|
|
|
@ -33,7 +33,17 @@
|
|||
</div>
|
||||
<div class="pure-u-1 pure-u-md-8-24 user-field">
|
||||
<% if env.get? "user" %>
|
||||
<div class="pure-u-1-3">
|
||||
<div class="pure-u-1-4">
|
||||
<a href="/toggle_theme" class="pure-menu-heading">
|
||||
<% preferences = env.get("user").as(User).preferences %>
|
||||
<% if preferences.dark_mode %>
|
||||
<i class="icon ion-ios-sunny"></i>
|
||||
<% else %>
|
||||
<i class="icon ion-ios-moon"></i>
|
||||
<% end %>
|
||||
</a>
|
||||
</div>
|
||||
<div class="pure-u-1-4">
|
||||
<a href="/feed/subscriptions" class="pure-menu-heading">
|
||||
<% notification_count = env.get("user").as(User).notifications.size %>
|
||||
<% if notification_count > 0 %>
|
||||
|
@ -43,12 +53,12 @@
|
|||
<% end %>
|
||||
</a>
|
||||
</div>
|
||||
<div class="pure-u-1-3">
|
||||
<div class="pure-u-1-4">
|
||||
<a href="/preferences" class="pure-menu-heading">
|
||||
<i class="icon ion-ios-cog"></i>
|
||||
</a>
|
||||
</div>
|
||||
<div class="pure-u-1-3">
|
||||
<div class="pure-u-1-4">
|
||||
<a href="/signout" class="pure-menu-heading">Sign out</a>
|
||||
</div>
|
||||
<% else %>
|
||||
|
|
Loading…
Reference in a new issue