From 15e64279d241679b5f14f72f86a974bc74b2e44b Mon Sep 17 00:00:00 2001 From: Tom Tuddenham Date: Sat, 18 May 2024 19:46:46 +0930 Subject: [PATCH] 19 clean up, add theme toggle --- Gemfile.lock | 142 +++++++++--------- app/controllers/home_controller.rb | 2 +- .../workspace/checklists_controller.rb | 2 +- app/helpers/application_helper.rb | 6 + .../controllers/theme_controller.js | 40 +++++ .../contents/_content.html.erb | 3 - app/views/checklist_instances/index.html.erb | 7 + app/views/layouts/application.html.erb | 16 +- app/views/layouts/shared/_navbar.html.erb | 35 +++++ .../layouts/shared/_navbar_item.html.erb | 13 ++ .../layouts/shared/icons/_dark_mode.html.erb | 4 + .../layouts/shared/icons/_light_mode.html.erb | 3 + .../layouts/shared/icons/_sign_out.html.erb | 3 + .../library/checklists/_table.html.erb.old | 29 ---- .../workspace/checklists/_table.html.erb | 4 +- app/views/workspace/checklists/index.html.erb | 9 +- app/views/workspace/shared/_header.html.erb | 2 +- config/tailwind.config.js | 1 + 18 files changed, 197 insertions(+), 124 deletions(-) create mode 100644 app/javascript/controllers/theme_controller.js delete mode 100644 app/views/action_markdown/contents/_content.html.erb create mode 100644 app/views/layouts/shared/_navbar.html.erb create mode 100644 app/views/layouts/shared/_navbar_item.html.erb create mode 100644 app/views/layouts/shared/icons/_dark_mode.html.erb create mode 100644 app/views/layouts/shared/icons/_light_mode.html.erb create mode 100644 app/views/layouts/shared/icons/_sign_out.html.erb delete mode 100644 app/views/library/checklists/_table.html.erb.old diff --git a/Gemfile.lock b/Gemfile.lock index 9316fdc..0d9ac81 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,35 +1,35 @@ GEM remote: https://rubygems.org/ specs: - actioncable (7.1.3.2) - actionpack (= 7.1.3.2) - activesupport (= 7.1.3.2) + actioncable (7.1.3.3) + actionpack (= 7.1.3.3) + activesupport (= 7.1.3.3) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.1.3.2) - actionpack (= 7.1.3.2) - activejob (= 7.1.3.2) - activerecord (= 7.1.3.2) - activestorage (= 7.1.3.2) - activesupport (= 7.1.3.2) + actionmailbox (7.1.3.3) + actionpack (= 7.1.3.3) + activejob (= 7.1.3.3) + activerecord (= 7.1.3.3) + activestorage (= 7.1.3.3) + activesupport (= 7.1.3.3) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.1.3.2) - actionpack (= 7.1.3.2) - actionview (= 7.1.3.2) - activejob (= 7.1.3.2) - activesupport (= 7.1.3.2) + actionmailer (7.1.3.3) + actionpack (= 7.1.3.3) + actionview (= 7.1.3.3) + activejob (= 7.1.3.3) + activesupport (= 7.1.3.3) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.2) - actionpack (7.1.3.2) - actionview (= 7.1.3.2) - activesupport (= 7.1.3.2) + actionpack (7.1.3.3) + actionview (= 7.1.3.3) + activesupport (= 7.1.3.3) nokogiri (>= 1.8.5) racc rack (>= 2.2.4) @@ -37,35 +37,35 @@ GEM rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - actiontext (7.1.3.2) - actionpack (= 7.1.3.2) - activerecord (= 7.1.3.2) - activestorage (= 7.1.3.2) - activesupport (= 7.1.3.2) + actiontext (7.1.3.3) + actionpack (= 7.1.3.3) + activerecord (= 7.1.3.3) + activestorage (= 7.1.3.3) + activesupport (= 7.1.3.3) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.1.3.2) - activesupport (= 7.1.3.2) + actionview (7.1.3.3) + activesupport (= 7.1.3.3) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activejob (7.1.3.2) - activesupport (= 7.1.3.2) + activejob (7.1.3.3) + activesupport (= 7.1.3.3) globalid (>= 0.3.6) - activemodel (7.1.3.2) - activesupport (= 7.1.3.2) - activerecord (7.1.3.2) - activemodel (= 7.1.3.2) - activesupport (= 7.1.3.2) + activemodel (7.1.3.3) + activesupport (= 7.1.3.3) + activerecord (7.1.3.3) + activemodel (= 7.1.3.3) + activesupport (= 7.1.3.3) timeout (>= 0.4.0) - activestorage (7.1.3.2) - actionpack (= 7.1.3.2) - activejob (= 7.1.3.2) - activerecord (= 7.1.3.2) - activesupport (= 7.1.3.2) + activestorage (7.1.3.3) + actionpack (= 7.1.3.3) + activejob (= 7.1.3.3) + activerecord (= 7.1.3.3) + activesupport (= 7.1.3.3) marcel (~> 1.0) - activesupport (7.1.3.2) + activesupport (7.1.3.3) base64 bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) @@ -99,12 +99,12 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - commonmarker (1.1.2) + commonmarker (1.1.3) rb_sys (~> 0.9) - commonmarker (1.1.2-aarch64-linux) - commonmarker (1.1.2-arm64-darwin) - commonmarker (1.1.2-x86_64-darwin) - commonmarker (1.1.2-x86_64-linux) + commonmarker (1.1.3-aarch64-linux) + commonmarker (1.1.3-arm64-darwin) + commonmarker (1.1.3-x86_64-darwin) + commonmarker (1.1.3-x86_64-linux) concurrent-ruby (1.2.3) connection_pool (2.4.1) crass (1.0.6) @@ -219,11 +219,11 @@ GEM matrix (0.4.2) method_source (1.1.0) mini_mime (1.1.5) - minitest (5.22.3) + minitest (5.23.0) msgpack (1.7.2) multi_test (1.1.0) mutex_m (0.2.0) - net-imap (0.4.10) + net-imap (0.4.11) date net-protocol net-pop (0.1.2) @@ -258,10 +258,10 @@ GEM public_suffix (5.0.5) puma (6.4.2) nio4r (~> 2.0) - pundit (2.3.1) + pundit (2.3.2) activesupport (>= 3.0.0) racc (1.7.3) - rack (3.0.10) + rack (3.0.11) rack-session (2.0.0) rack (>= 3.0.0) rack-test (2.1.0) @@ -269,20 +269,20 @@ GEM rackup (2.1.0) rack (>= 3) webrick (~> 1.8) - rails (7.1.3.2) - actioncable (= 7.1.3.2) - actionmailbox (= 7.1.3.2) - actionmailer (= 7.1.3.2) - actionpack (= 7.1.3.2) - actiontext (= 7.1.3.2) - actionview (= 7.1.3.2) - activejob (= 7.1.3.2) - activemodel (= 7.1.3.2) - activerecord (= 7.1.3.2) - activestorage (= 7.1.3.2) - activesupport (= 7.1.3.2) + rails (7.1.3.3) + actioncable (= 7.1.3.3) + actionmailbox (= 7.1.3.3) + actionmailer (= 7.1.3.3) + actionpack (= 7.1.3.3) + actiontext (= 7.1.3.3) + actionview (= 7.1.3.3) + activejob (= 7.1.3.3) + activemodel (= 7.1.3.3) + activerecord (= 7.1.3.3) + activestorage (= 7.1.3.3) + activesupport (= 7.1.3.3) bundler (>= 1.15.0) - railties (= 7.1.3.2) + railties (= 7.1.3.3) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -290,9 +290,9 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.1.3.2) - actionpack (= 7.1.3.2) - activesupport (= 7.1.3.2) + railties (7.1.3.3) + actionpack (= 7.1.3.3) + activesupport (= 7.1.3.3) irb rackup (>= 1.0.0) rake (>= 12.2) @@ -309,20 +309,21 @@ GEM redis-client (>= 0.22.0) redis-client (0.22.1) connection_pool - regexp_parser (2.9.0) - reline (0.5.5) + regexp_parser (2.9.2) + reline (0.5.7) io-console (~> 0.5) responders (3.1.1) actionpack (>= 5.2) railties (>= 5.2) - rexml (3.2.6) + rexml (3.2.8) + strscan (>= 3.0.9) rouge (4.2.1) rspec-core (3.13.0) rspec-support (~> 3.13.0) rspec-expectations (3.13.0) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) - rspec-mocks (3.13.0) + rspec-mocks (3.13.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) rspec-rails (6.1.2) @@ -334,7 +335,7 @@ GEM rspec-mocks (~> 3.13) rspec-support (~> 3.13) rspec-support (3.13.1) - rubocop (1.63.4) + rubocop (1.63.5) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -354,7 +355,7 @@ GEM rubocop-performance (1.21.0) rubocop (>= 1.48.1, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rails (2.24.1) + rubocop-rails (2.25.0) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) @@ -371,7 +372,7 @@ GEM scenic (1.8.0) activerecord (>= 4.0.0) railties (>= 4.0.0) - selenium-webdriver (4.20.1) + selenium-webdriver (4.21.1) base64 (~> 0.2) rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) @@ -392,6 +393,7 @@ GEM stimulus-rails (1.3.3) railties (>= 6.0.0) stringio (3.1.0) + strscan (3.1.0) sys-uname (1.2.3) ffi (~> 1.1) tailwindcss-rails (2.6.0) @@ -434,7 +436,7 @@ GEM xpath (3.2.0) nokogiri (~> 1.8) yard (0.9.36) - zeitwerk (2.6.13) + zeitwerk (2.6.14) PLATFORMS aarch64-linux diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 7ae189a..f3c92b9 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -6,7 +6,7 @@ class HomeController < ApplicationController skip_before_action :authenticate_user!, raise: false before_action :load_workspace, only: :index - group :home + group :workspace def index = render(template, layout:) diff --git a/app/controllers/workspace/checklists_controller.rb b/app/controllers/workspace/checklists_controller.rb index f4e26bc..d96bb5e 100644 --- a/app/controllers/workspace/checklists_controller.rb +++ b/app/controllers/workspace/checklists_controller.rb @@ -3,7 +3,7 @@ module Workspace # Controller for Workspace checklists class ChecklistsController < ApplicationController - group :root + group :workspace def index @checklists = Checklist.all diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 77881c0..fc64af8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -21,6 +21,12 @@ def render_sidebar_item(title:, path:, icon:, active_group:, classes: '') render 'layouts/shared/sidebar_item', title:, path:, icon:, active:, classes: end + def render_navbar_item(title:, path:, icon:, active_group:, classes: '') + active = active_group == controller.active_group + + render 'layouts/shared/navbar_item', title:, path:, icon:, active:, classes: + end + def link_to_tab_item(title, path, active_action_name) klass = controller.action_name == active_action_name.to_s ? 'text-indigo-400' : '' diff --git a/app/javascript/controllers/theme_controller.js b/app/javascript/controllers/theme_controller.js new file mode 100644 index 0000000..3d6039c --- /dev/null +++ b/app/javascript/controllers/theme_controller.js @@ -0,0 +1,40 @@ +import { Controller } from "@hotwired/stimulus" + +export default class extends Controller { + static targets = [ "lightMode", "darkMode", "toggle" ] + + connect() { + if (localStorage.getItem('color-theme') === 'dark' || (!('color-theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) { + this.darkModeTarget.classList.remove('hidden'); + document.documentElement.classList.add('dark'); + } else { + this.lightModeTarget.classList.remove('hidden'); + document.documentElement.classList.remove('dark'); + } + } + + toggle() { + this.lightModeTarget.classList.toggle('hidden'); + this.darkModeTarget.classList.toggle('hidden'); + + if (localStorage.getItem('color-theme')) { + if (localStorage.getItem('color-theme') === 'light') { + document.documentElement.classList.add('dark'); + localStorage.setItem('color-theme', 'dark'); + } else { + document.documentElement.classList.remove('dark'); + localStorage.setItem('color-theme', 'light'); + } + + // if NOT set via local storage previously + } else { + if (document.documentElement.classList.contains('dark')) { + document.documentElement.classList.remove('dark'); + localStorage.setItem('color-theme', 'light'); + } else { + document.documentElement.classList.add('dark'); + localStorage.setItem('color-theme', 'dark'); + } + } + } +} diff --git a/app/views/action_markdown/contents/_content.html.erb b/app/views/action_markdown/contents/_content.html.erb deleted file mode 100644 index 6b6bb75..0000000 --- a/app/views/action_markdown/contents/_content.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -
- <%= sanitize content.to_html %> -
diff --git a/app/views/checklist_instances/index.html.erb b/app/views/checklist_instances/index.html.erb index a2406bb..7cf537d 100644 --- a/app/views/checklist_instances/index.html.erb +++ b/app/views/checklist_instances/index.html.erb @@ -1,3 +1,10 @@ +<% content_for :header do %> +
+

Checklist instances

+ <%= link_to "New checklist instance", new_checklist_instance_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %> +
+<% end %> +
<% if notice.present? %>

<%= notice %>

diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index bbdec58..ce11d1f 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -16,17 +16,11 @@ <%= render 'layouts/shared/flash_messages' %> -
- <%= render partial: 'layouts/shared/sidebar_mobile' %> - <%= render partial: 'layouts/shared/sidebar_desktop' %> - -
- <%= render partial: 'layouts/shared/search_header' %> -
- <%= yield %> -
+ <%= render 'layouts/shared/navbar' %> +
+
+ <%= yield %>
-
- + diff --git a/app/views/layouts/shared/_navbar.html.erb b/app/views/layouts/shared/_navbar.html.erb new file mode 100644 index 0000000..30e56aa --- /dev/null +++ b/app/views/layouts/shared/_navbar.html.erb @@ -0,0 +1,35 @@ + diff --git a/app/views/layouts/shared/_navbar_item.html.erb b/app/views/layouts/shared/_navbar_item.html.erb new file mode 100644 index 0000000..dc69ac6 --- /dev/null +++ b/app/views/layouts/shared/_navbar_item.html.erb @@ -0,0 +1,13 @@ +<% + if active + options = { + class: "bg-gray-900 text-white rounded-md px-3 py-2 text-sm font-medium", + aria: { current: "page" } + } + else + options = { class: "text-gray-300 hover:bg-gray-700 hover:text-white rounded-md px-3 py-2 text-sm font-medium" } + + end +%> +<%= link_to title, path, options %> + diff --git a/app/views/layouts/shared/icons/_dark_mode.html.erb b/app/views/layouts/shared/icons/_dark_mode.html.erb new file mode 100644 index 0000000..e2a9717 --- /dev/null +++ b/app/views/layouts/shared/icons/_dark_mode.html.erb @@ -0,0 +1,4 @@ + + + + diff --git a/app/views/layouts/shared/icons/_light_mode.html.erb b/app/views/layouts/shared/icons/_light_mode.html.erb new file mode 100644 index 0000000..1039c35 --- /dev/null +++ b/app/views/layouts/shared/icons/_light_mode.html.erb @@ -0,0 +1,3 @@ + + + diff --git a/app/views/layouts/shared/icons/_sign_out.html.erb b/app/views/layouts/shared/icons/_sign_out.html.erb new file mode 100644 index 0000000..e083e3e --- /dev/null +++ b/app/views/layouts/shared/icons/_sign_out.html.erb @@ -0,0 +1,3 @@ + + + diff --git a/app/views/library/checklists/_table.html.erb.old b/app/views/library/checklists/_table.html.erb.old deleted file mode 100644 index c5fde4d..0000000 --- a/app/views/library/checklists/_table.html.erb.old +++ /dev/null @@ -1,29 +0,0 @@ -
- -
    - <% checklists.each do |checklist| %> -
  • -
    -
    - <%= render_checklist_status_dot(checklist) %> - -

    - <%= link_to templates_checklist_path(checklist), class: "flex gap-x-2" do %> - <%= checklist.title %> - <% end %> -

    -
    -
    -

    Created <%= distance_of_time_in_words(checklist.created_at, DateTime.now) %> ago

    -
    -
    -
    <%= checklist.status.humanize %>
    - -
  • - <% end %> -
-
- - diff --git a/app/views/workspace/checklists/_table.html.erb b/app/views/workspace/checklists/_table.html.erb index 007cf6d..9f67e51 100644 --- a/app/views/workspace/checklists/_table.html.erb +++ b/app/views/workspace/checklists/_table.html.erb @@ -1,4 +1,4 @@ -
+
    <% checklists.each do |checklist| %> @@ -28,6 +28,6 @@ <% end %>
-
+ diff --git a/app/views/workspace/checklists/index.html.erb b/app/views/workspace/checklists/index.html.erb index e24dcbc..8ab84b1 100644 --- a/app/views/workspace/checklists/index.html.erb +++ b/app/views/workspace/checklists/index.html.erb @@ -1,13 +1,10 @@ -<% content_for :header do %> -
- <%= link_to '+', new_library_checklist_path, class: "block rounded-md bg-indigo-500 px-3 py-2 text-center text-sm font-semibold text-white hover:bg-indigo-400 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-500" %> -
-<% end %> -

Checklists

<%= render partial: 'workspace/shared/header' %> + +

Checklists

<% if @checklists.empty? %> <%= render partial: 'workspace/checklists/empty_page' %> <% else %> <%= render partial: 'workspace/checklists/table', locals: { checklists: @checklists } %> <% end %> + diff --git a/app/views/workspace/shared/_header.html.erb b/app/views/workspace/shared/_header.html.erb index 05d91ab..98f0903 100644 --- a/app/views/workspace/shared/_header.html.erb +++ b/app/views/workspace/shared/_header.html.erb @@ -3,7 +3,7 @@