Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dark mode: allow user to set it #296

Merged
merged 55 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
4df5629
Adding apple-touch-icons and related code to head. Fix bug causing HT…
Apr 15, 2024
66eb852
minor var name change
Apr 16, 2024
31e5791
removing ineffective tests
Apr 16, 2024
aeba49b
Adding apple-touch-icons and related code to head. Fix bug causing HT…
Apr 15, 2024
05e1628
moving code rendering logic to inherited classes
Apr 17, 2024
949dfad
* fix(messages_helper.rb): revert formatted_block_code method name to…
Apr 18, 2024
08da8be
* fix(messages_helper.rb): revert formatted_block_code method name to…
Apr 18, 2024
9f2a913
moving code rendering logic to inherited classes
Apr 17, 2024
b87d663
* fix(messages_helper.rb): revert formatted_block_code method name to…
Apr 18, 2024
aa357b1
fixing rebase issue, again
Apr 19, 2024
0a82270
wip: todo: initial state of theme, etc
Apr 19, 2024
9b62207
* feat(app/views/settings/people/_form.html.erb): add radio button in…
Apr 19, 2024
000ebda
cleaning up
Apr 19, 2024
33a92de
still trying to fix a merge issue
Apr 19, 2024
e694f49
* style(markdown_renderer.rb): remove extra blank line
Apr 19, 2024
91a2c7c
Merge branch 'main' into #169
Apr 22, 2024
4031c42
adding line break to test column wrapping
Apr 22, 2024
1afd091
chore: another formatting modification
Apr 22, 2024
ad683dc
Fix logo for dark mode
krschacht Apr 22, 2024
71a8f71
Hotfix: Another attempt on flappy tests
krschacht Apr 22, 2024
b057928
Use positive? and negative? for code readability
krschacht Apr 22, 2024
61e09bd
PR comment resolution completes Allow user to toggle dark/light mode …
Apr 22, 2024
7e68085
Merge branch 'allyourbot:main' into dark-mode
jasonpaulso Apr 22, 2024
b60185d
syncing with upstream main
Apr 22, 2024
0ddbec7
syncing with upstream main
Apr 22, 2024
ce5f0a0
reverting method name change
Apr 22, 2024
945b7f2
Update app/views/settings/people/_form.html.erb
jasonpaulso Apr 23, 2024
b1a488a
* fix(dark_mode_controller.js): remove semicolons and fix toggleDarkM…
Apr 23, 2024
a7a3ef7
* chore(_head.html.erb): remove unused JavaScript code for dark mode …
Apr 23, 2024
ec01cde
* style(conversation.html.erb): update class attribute for the conver…
Apr 23, 2024
c44b123
* fix(dark_mode_controller.js): remove unnecessary conditional check …
Apr 23, 2024
af5689c
* feat(dark_mode_controller.js): add toggle for 'system' class in tog…
Apr 23, 2024
816704f
* style(conversation.html.erb): reverting class names for hover and d…
Apr 23, 2024
62c7247
* chore(styles): remove unused dark mode styles in application.tailwi…
Apr 23, 2024
2b9ff6f
* chore(styles): update tailwind CSS classes in application.tailwind.css
Apr 23, 2024
ec1f259
* chore(daisyui_tooltip.css): add media query to hide tooltip on touc…
Apr 25, 2024
162217e
* chore(daisyui_): modifying daisyui css to eliminate dark mode confl…
Apr 25, 2024
4a376fc
Merge branch 'main' into dark-mode
jasonpaulso Apr 25, 2024
f52c213
selecting daisy styles
Apr 25, 2024
e419748
removing unused css files
Apr 25, 2024
53ba2bc
* chore(daisyui_tooltip.css): apply daisy light theme colors when pre…
Apr 26, 2024
e7c0209
* chore(daisyui_selected.css): remove file
Apr 26, 2024
aff068e
Update README.md
krschacht Apr 26, 2024
4bf6af4
README for v0.6
krschacht Apr 26, 2024
fbb8386
Update video
krschacht Apr 26, 2024
80b99f8
Fix a race that sometimes hides stop streaming (#307)
krschacht Apr 26, 2024
2e728c4
Add a submit state to buttons, like Saving... (#306)
krschacht Apr 26, 2024
ebdaa02
PWA Layout Fixes (#304)
jasonpaulso Apr 27, 2024
22a9306
* fix(user.rb): set default preferences before creating a user
Apr 29, 2024
10aaca0
* chore(styles): update tailwind CSS classes for relationship backgro…
Apr 29, 2024
39aa383
* chore(daisyui_tooltip.css): update dark mode styles for menu hover
Apr 29, 2024
803a4f3
Merge branch 'main' into dark-mode
jasonpaulso Apr 29, 2024
2b16d74
Merge branch 'allyourbot:main' into dark-mode
jasonpaulso Apr 30, 2024
0d47340
Merge branch 'main' into pr/jasonpaulso/296
krschacht Apr 30, 2024
53961fd
fix convo highlight
krschacht Apr 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions app/assets/stylesheets/application.tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,24 @@
@apply !text-white;
}

.relationship .relationship\:bg-gray-700,
.relationship.relationship\:bg-gray-700 {
@apply bg-gray-700;
}

.relationship .relationship\:bg-gray-200,
.relationship.relationship\:bg-gray-200 {
@apply bg-gray-200;
}

@media (prefers-color-scheme: dark) {
.relationship .dark\:relationship\:bg-gray-700,
.relationship.dark\:relationship\:bg-gray-700 {
:root:not(.dark) {
.relationship .relationship\:bg-gray-700,
.relationship.relationship\:bg-gray-700 {
@apply bg-gray-700;
}
.relationship .relationship\:bg-gray-200,
.relationship.relationship\:bg-gray-200 {
@apply bg-gray-200;
}
}

.relationship .relationship\:hidden,
.relationship.relationship\:hidden {
@apply !hidden;
@media (prefers-color-scheme: dark), (root: dark) {
.dark\:relationship\:bg-gray-700.relationship {
@apply bg-gray-700 !important;
}
.dark\:relationship\:bg-gray-900.relationship {
@apply bg-gray-900;
}
}

.relationship .relationship\:pl-4,
Expand Down
31 changes: 30 additions & 1 deletion app/assets/stylesheets/includes/daisyui_tooltip.css
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,42 @@ dialog button:focus-visible {
--tw-prose-pre-code: #ffffff !important;
}

/* dark_mode overrides */
@media (prefers-color-scheme: dark) {
:root.light {
color-scheme: light;
}
:root .prose {
--tw-prose-body: rgb(236, 236, 236);
}
}
:root.dark {
:root .prose {
--tw-prose-body: rgb(236, 236, 236);
}
}
:root.dark {
:root .prose {
--tw-prose-body: rgb(236, 236, 236);
}
}

/* show only on touch devices */
:root.dark {
:where(.menu li:not(.menu-title):not(.disabled) > :not(ul):not(details):not(.menu-title)):not(.active):hover,
:where(.menu li:not(.menu-title):not(.disabled) > details > summary:not(.menu-title)):not(.active):hover {
background-color: rgb(59 59 61);
}
}

:root.dark {
:where(.menu li:not(.menu-title):not(.disabled) > :not(ul):not(details):not(.menu-title)):not(.active):hover,
:where(.menu li:not(.menu-title):not(.disabled) > details > summary:not(.menu-title)):not(.active):hover {
background-color: rgb(59 59 61);
}
}

/* hide tooltip on touch devices */

@media (hover: none), (hover: on-demand), (-moz-touch-enabled: 1), (pointer: coarse) {
.tooltip:hover:after,
.tooltip:hover:active:before,
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/settings/people_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def update

def person_params
params.require(:person).permit(:email, personable_attributes: [
:id, :first_name, :last_name, :password, :openai_key, :anthropic_key
:id, :first_name, :last_name, :password, :openai_key, :anthropic_key, preferences: [:dark_mode]
])
end

Expand All @@ -27,4 +27,4 @@ def check_personable_id
return render :edit, status: :unauthorized
end
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def person_params
end

def user_params
params.require(:user).permit(preferences: [:nav_closed])
params.require(:user).permit(preferences: [:nav_closed, :dark_mode])
end

def ensure_registration
Expand Down
9 changes: 9 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@ class User < ApplicationRecord
has_many :conversations, dependent: :destroy

serialize :preferences, coder: JsonSerializer

before_create :set_default_preferences

private

def set_default_preferences
self.preferences ||= {}
self.preferences[:dark_mode] ||= 'system'
end
end
5 changes: 3 additions & 2 deletions app/views/assistants/_assistant.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
<div class="
flex justify-between items-center
mb-1 p-1 pl-2 pr-2 mr-5
hover:bg-gray-100 dark:hover:bg-gray-700
bg-gray-50 dark:bg-gray-900
hover:bg-gray-100 dark:hover:bg-gray-700
bg-gray-50 dark:bg-transparent
dark:bg-gray-700
group cursor-pointer
text-sm rounded-lg
<%= selected && 'relationship' %>
Expand Down
4 changes: 3 additions & 1 deletion app/views/conversations/_conversation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
class="
rounded-lg mr-5 cursor-pointer group
hover:bg-gray-100 dark:hover:bg-gray-700
relationship:bg-gray-200 dark:relationship:bg-gray-700 <%= selected && 'relationship' %>
relationship:bg-gray-200 dark:relationship:bg-gray-700
mb-px
<%= selected && 'relationship' %>
"
data-role="conversation"
data-radio-behavior-target="radio"
Expand Down
6 changes: 5 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<% content_for :title, "HostedGPT" %>
<!DOCTYPE html>
<html>
<html
class=<%= Current.user.preferences[:dark_mode] %>
>

<%= render "head" %>

<body
class="
nav-closed
Expand Down
2 changes: 1 addition & 1 deletion app/views/messages/_message.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ end
<div class="hidden" data-clipboard-target="text"><%= message.content_text %></div>
<div
data-role="content-text"
class="prose break-words leading-normal"
class="prose break-words leading-normal dark:[&_*]:text-gray-100 dark:marker:text-gray-100"
>
<% if message.has_document_image? %>
<%= button_tag type: "button",
Expand Down
13 changes: 13 additions & 0 deletions app/views/settings/people/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@
placeholder: "Anthropic Key"
%>
</div>
<div class="my-5" data-controller="transition" data-transition-toggle-class="hidden">
<%= user_fields.label :dark_mode, "Color Theme" %>
<div class="flex items-center justify-between shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full dark:text-black gap-1">
<%= user_fields.fields_for :preferences do |preferences_fields| %>
<% %w(dark light system).each do |value| %>
<div class="flex items-center gap-2">
<%= preferences_fields.radio_button :dark_mode, value, checked: Current.user.preferences[:dark_mode] == value %>
<%= user_fields.label :dark_mode, value.capitalize, class: "dark:text-gray-100", for: "person_personable_attributes_preferences_dark_mode_#{value}"%>
</div>
<% end %>
<% end %>
</div>
</div>
<% end %>

<div class="inline">
Expand Down
36 changes: 23 additions & 13 deletions config/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ module.exports = {
'./public/*.html',
'./app/helpers/**/*.rb',
'./app/javascript/**/*.js',
'./app/views/**/*.{erb,haml,html,slim}'
'./app/views/**/*.{erb,haml,html,slim}',
],
theme: {
extend: {
fontFamily: {
sans: ['Figtree', ...defaultTheme.fontFamily.sans],
},
colors: {
'gray': {
gray: {
50: '#f9f9f9',
100: '#ececec',
200: '#cdcdcd',
Expand All @@ -26,27 +26,37 @@ module.exports = {
900: '#171717',
950: '#0d0d0d',
},
'brand': {
'blue': '#2f5ff2',
}
brand: {
blue: '#2f5ff2',
},
'base-100': '#ffffff', //this can be avodied by installing, requiring and configuring the daisyui plugin
},
scale: {
'96': '0.96',
'97': '0.97',
'98': '0.98',
'99': '0.99',
96: '0.96',
97: '0.97',
98: '0.98',
99: '0.99',
},
strokeWidth: {
'3': '3px',
'4': '4px',
3: '3px',
4: '4px',
},
},
},

darkMode: [
'variant',
[
'@media (prefers-color-scheme: dark) { &:is(.system *) }',
'&:is(.dark *)',
],
],
plugins: [
require('@tailwindcss/forms'),
require('@tailwindcss/aspect-ratio'),
require('@tailwindcss/typography'),
require('@tailwindcss/container-queries'),
]
],
}



27 changes: 22 additions & 5 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,27 +105,44 @@ class UserTest < ActiveSupport::TestCase

test "boolean values within preferences get converted back and forth properly" do
assert_nil users(:keith).preferences[:nav_closed]
assert_nil users(:keith).preferences[:dark_mode]
assert_nil users(:keith).preferences[:kids]
assert_nil users(:keith).preferences[:city]

users(:keith).update!(preferences: {
nav_closed: true,
dark_mode: false,
kids: 2,
city: "Austin"
})
users(:keith).reload

assert users(:keith).preferences[:nav_closed]
refute users(:keith).preferences[:dark_mode]
assert_equal 2, users(:keith).preferences[:kids]
assert_equal "Austin", users(:keith).preferences[:city]

users(:keith).update!(preferences: {
nav_closed: "false",
dark_mode: "true",

})

refute users(:keith).preferences[:nav_closed]
assert users(:keith).preferences[:dark_mode]

end

test "dark_mode preference defaults to system and it can update user dark_mode preference" do
new_user = User.create!(password: 'password', first_name: 'First', last_name: 'Last')
assert_equal "system", new_user.preferences[:dark_mode]

new_user.update!(preferences: { dark_mode: "light" })
assert_equal "light", new_user.preferences[:dark_mode]

new_user.update!(preferences: { dark_mode: "dark" })

assert_equal "dark", new_user.preferences[:dark_mode]

new_user.update!(preferences: { dark_mode: "system" })

assert_equal "system", new_user.preferences[:dark_mode]

end

end
Loading