From acac683b3e462fd7146e5f864b016c09cac8df08 Mon Sep 17 00:00:00 2001 From: Jose Farias Date: Mon, 25 Nov 2024 16:25:42 -0600 Subject: [PATCH] Do combobox filtering client-side --- app/controllers/bubbles/tags_controller.rb | 7 --- app/controllers/bubbles/users_controller.rb | 7 --- app/models/tag.rb | 2 - app/models/user.rb | 1 - app/views/bubbles/show.html.erb | 43 +------------------ .../bubbles/sidebar/_assignment.html.erb | 3 +- app/views/bubbles/sidebar/_tag.html.erb | 4 +- ...rbo_stream.erb => _select_option.html.erb} | 0 app/views/bubbles/tags/index.turbo_stream.erb | 1 - ...rbo_stream.erb => _select_option.html.erb} | 0 .../bubbles/users/index.turbo_stream.erb | 1 - config/routes.rb | 2 - 12 files changed, 6 insertions(+), 65 deletions(-) delete mode 100644 app/controllers/bubbles/tags_controller.rb delete mode 100644 app/controllers/bubbles/users_controller.rb rename app/views/bubbles/tags/{_select_option.turbo_stream.erb => _select_option.html.erb} (100%) delete mode 100644 app/views/bubbles/tags/index.turbo_stream.erb rename app/views/bubbles/users/{_select_option.turbo_stream.erb => _select_option.html.erb} (100%) delete mode 100644 app/views/bubbles/users/index.turbo_stream.erb diff --git a/app/controllers/bubbles/tags_controller.rb b/app/controllers/bubbles/tags_controller.rb deleted file mode 100644 index 4ac791ae0..000000000 --- a/app/controllers/bubbles/tags_controller.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Bubbles::TagsController < ApplicationController - include BubbleScoped, BucketScoped - - def index - @tags = Current.account.tags.search params[:q] - end -end diff --git a/app/controllers/bubbles/users_controller.rb b/app/controllers/bubbles/users_controller.rb deleted file mode 100644 index 23b8b9009..000000000 --- a/app/controllers/bubbles/users_controller.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Bubbles::UsersController < ApplicationController - include BubbleScoped, BucketScoped - - def index - @users = @bucket.users.active.search params[:q] - end -end diff --git a/app/models/tag.rb b/app/models/tag.rb index 5937ea8cd..e11391e0b 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -6,8 +6,6 @@ class Tag < ApplicationRecord has_many :taggings, dependent: :destroy has_many :bubbles, through: :taggings - scope :search, ->(query) { where "title LIKE ?", "%#{query}%" } - def hashtag "#" + title end diff --git a/app/models/user.rb b/app/models/user.rb index ccd198dd9..2baa83876 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -23,7 +23,6 @@ class User < ApplicationRecord scope :active, -> { where(active: true) } scope :alphabetically, -> { order("LOWER(name)") } - scope :search, ->(query) { where "name LIKE ?", "%#{query}%" } def initials name.to_s.scan(/\b\p{L}/).join.upcase diff --git a/app/views/bubbles/show.html.erb b/app/views/bubbles/show.html.erb index f6475cdcc..959f5093b 100644 --- a/app/views/bubbles/show.html.erb +++ b/app/views/bubbles/show.html.erb @@ -23,47 +23,8 @@ <% end %> - <%= render "bubbles/sidebar/assignment", bubble: @bubble %> - <%= render "bubbles/sidebar/tag", bubble: @bubble %> - - <%= form_with url: "/", data: { controller: "form" } do |form| %> - - <% end %> - -
- - - - <%= image_tag "tag.svg", aria: { hidden: true }, size: 24 %> - - <%= form_with model: Tag.new, url: bucket_bubble_tags_path(@bubble.bucket, @bubble), class: "min-width flex-item-grow", data: { turbo_frame: "_top" } do |form| %> - <%= form.text_field :title, class: "input", autofocus: "on", list: "tags-list" %> - <%= form.submit "Create Tag", hidden: true %> - - - <%= Current.account.tags.each do |tag| %> - - <% end %> - - <% end %> - -
- -
-
-
+ <%= render "bubbles/sidebar/assignment", bubble: @bubble, users: @bucket.users.active %> + <%= render "bubbles/sidebar/tag", bubble: @bubble, tags: Current.account.tags %> <% if @bubble.image.attached? %> <%= button_to bucket_bubble_image_path(@bubble.bucket, @bubble), method: :delete, class: "btn full-width justify-start borderless" do %> diff --git a/app/views/bubbles/sidebar/_assignment.html.erb b/app/views/bubbles/sidebar/_assignment.html.erb index b7a43e164..29fad3aa6 100644 --- a/app/views/bubbles/sidebar/_assignment.html.erb +++ b/app/views/bubbles/sidebar/_assignment.html.erb @@ -5,7 +5,8 @@ <%= form_with url: bucket_bubble_assignment_toggles_path(bubble.bucket, bubble), data: { controller: "form" } do |form| %> - <%= form.combobox :assignee_id, bucket_bubble_users_path(bubble.bucket, bubble), required: true, preload: true, + <%= form.combobox :assignee_id, users, required: true, preload: true, + render_in: { partial: "bubbles/users/select_option", as: :user, locals: { bubble: bubble } }, data: { controller: "autofocus", action: "hw-combobox:selection->form#submit" } %> <% end %> diff --git a/app/views/bubbles/sidebar/_tag.html.erb b/app/views/bubbles/sidebar/_tag.html.erb index c8ae622b6..a203790ab 100644 --- a/app/views/bubbles/sidebar/_tag.html.erb +++ b/app/views/bubbles/sidebar/_tag.html.erb @@ -5,8 +5,8 @@ <%= form_with url: bucket_bubble_tagging_toggles_path(bubble.bucket, bubble), data: { controller: "form" } do |form| %> - <%= form.combobox :tag_id, bucket_bubble_tags_path(bubble.bucket, bubble), - required: true, preload: true, name_when_new: "tag_title", + <%= form.combobox :tag_id, tags, required: true, preload: true, name_when_new: "tag_title", + render_in: { partial: "bubbles/tags/select_option", as: :tag, locals: { bubble: bubble } }, data: { controller: "autofocus", action: "hw-combobox:selection->form#submit" } %> <% end %> diff --git a/app/views/bubbles/tags/_select_option.turbo_stream.erb b/app/views/bubbles/tags/_select_option.html.erb similarity index 100% rename from app/views/bubbles/tags/_select_option.turbo_stream.erb rename to app/views/bubbles/tags/_select_option.html.erb diff --git a/app/views/bubbles/tags/index.turbo_stream.erb b/app/views/bubbles/tags/index.turbo_stream.erb deleted file mode 100644 index ea4cce4a5..000000000 --- a/app/views/bubbles/tags/index.turbo_stream.erb +++ /dev/null @@ -1 +0,0 @@ -<%= async_combobox_options @tags, render_in: { partial: "bubbles/tags/select_option", as: :tag, locals: { bubble: @bubble } } %> diff --git a/app/views/bubbles/users/_select_option.turbo_stream.erb b/app/views/bubbles/users/_select_option.html.erb similarity index 100% rename from app/views/bubbles/users/_select_option.turbo_stream.erb rename to app/views/bubbles/users/_select_option.html.erb diff --git a/app/views/bubbles/users/index.turbo_stream.erb b/app/views/bubbles/users/index.turbo_stream.erb deleted file mode 100644 index cf39ad084..000000000 --- a/app/views/bubbles/users/index.turbo_stream.erb +++ /dev/null @@ -1 +0,0 @@ -<%= async_combobox_options @users, render_in: { partial: "bubbles/users/select_option", as: :user, locals: { bubble: @bubble } } %> diff --git a/config/routes.rb b/config/routes.rb index ebddd9256..c11aff6ee 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,8 +24,6 @@ Rails.application.routes.draw do resource :pop resource :stage_picker resources :stagings - resources :tags - resources :users end namespace :assignments, as: :assignment do