diff --git a/app/controllers/conversations_controller.rb b/app/controllers/conversations_controller.rb index f4365024..a11402fe 100644 --- a/app/controllers/conversations_controller.rb +++ b/app/controllers/conversations_controller.rb @@ -1,10 +1,10 @@ class ConversationsController < ApplicationController before_action :set_conversation, only: [:show, :edit, :update, :destroy] - before_action :set_query, only: [:index] - before_action :set_nav_conversations before_action :set_nav_assistants def index + @query = params[:query] + @nav_conversations = Conversation.grouped_by_increasing_time_interval_for_user(Current.user, @query) end def show @@ -32,18 +32,10 @@ def destroy private - def set_nav_conversations - @nav_conversations = Conversation.grouped_by_increasing_time_interval_for_user(Current.user, @query) - end - def set_nav_assistants @nav_assistants = Current.user.assistants.ordered end - def set_query - @query = params[:query] - end - def set_conversation @conversation = Current.user.conversations.find(params[:id]) end diff --git a/app/javascript/stimulus/search_controller.js b/app/javascript/stimulus/search_controller.js index bbdb4d31..0252f298 100644 --- a/app/javascript/stimulus/search_controller.js +++ b/app/javascript/stimulus/search_controller.js @@ -4,14 +4,11 @@ export default class extends Controller { static targets = [ "input", "clear" ] connect() { - this.cursorToEnd() this.setSearchClearIcon() } - cursorToEnd() { - this.inputTarget.selectionStart = - this.inputTarget.selectionEnd = - this.inputTarget.value.length + disconnect() { + clearTimeout(this.timeout) } clear() { @@ -19,6 +16,10 @@ export default class extends Controller { this.element.requestSubmit() } + unfocus() { + this.inputTarget.autofocus = false + } + search() { clearTimeout(this.timeout) this.timeout = setTimeout(() => { @@ -29,10 +30,8 @@ export default class extends Controller { setSearchClearIcon() { if (this.inputTarget.value.length > 0) { this.clearTarget.classList.remove("hidden") - this.clearTarget.classList.add("text-gray-800") } else { this.clearTarget.classList.add("hidden") - this.clearTarget.classList.remove("text-gray-800") } } } \ No newline at end of file diff --git a/app/views/conversations/_nav_conversations.html.erb b/app/views/conversations/_nav_conversations.html.erb deleted file mode 100644 index 628a85ce..00000000 --- a/app/views/conversations/_nav_conversations.html.erb +++ /dev/null @@ -1,53 +0,0 @@ - - - -
- - > - <% @nav_conversations.each do |named_time_span, conversations| %> -
- <%= named_time_span %> -
- - <%= render conversations %> - <% end %> -
-
-
\ No newline at end of file diff --git a/app/views/conversations/index.html.erb b/app/views/conversations/index.html.erb index 46243332..3a2ecec0 100644 --- a/app/views/conversations/index.html.erb +++ b/app/views/conversations/index.html.erb @@ -1 +1,58 @@ -<%= render "nav_conversations" %> + + + +
+ + > + <% @nav_conversations.each do |named_time_span, conversations| %> +
+ <%= named_time_span %> +
+ + <%= render conversations %> + <% end %> +
+
+
diff --git a/app/views/messages/_nav_column.html.erb b/app/views/messages/_nav_column.html.erb index b9de73c2..0d3cd6d1 100644 --- a/app/views/messages/_nav_column.html.erb +++ b/app/views/messages/_nav_column.html.erb @@ -25,6 +25,4 @@ <% end %> - - Placeholder content - + diff --git a/test/models/conversation_test.rb b/test/models/conversation_test.rb index f382e7c7..d2000b9b 100644 --- a/test/models/conversation_test.rb +++ b/test/models/conversation_test.rb @@ -125,4 +125,34 @@ class ConversationTest < ActiveSupport::TestCase assert_equal 3, grouped_conversations["Older"].count end end + + test "#grouped_by_increasing_time_interval_for_user with a query returning a single conversation title" do + user = users(:keith) + query = "Ruby" + + grouped_conversations = Conversation.grouped_by_increasing_time_interval_for_user(user, query) + + # From prior tests. 1 with matching title. + assert_equal 1, grouped_conversations.values.flatten.count + end + + test "#grouped_by_increasing_time_interval_for_user with a query returning a single conversation message" do + user = users(:keith) + query = "alive" + + grouped_conversations = Conversation.grouped_by_increasing_time_interval_for_user(user, query) + + # From prior tests. 1 with a matching message. + assert_equal 1, grouped_conversations.values.flatten.count + end + + test "#grouped_by_increasing_time_interval_for_user with a query returning matching conversation titles and a message" do + user = users(:keith) + query = "test" + + grouped_conversations = Conversation.grouped_by_increasing_time_interval_for_user(user, query) + + # Total conversations from all prior tests. 2 with matching titles plus 1 other with a matching message. + assert_equal 3, grouped_conversations.values.flatten.count + end end