-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic text search of conversations (#576)
Co-authored-by: Keith Schacht <krschacht@gmail.com>
- Loading branch information
1 parent
de9eafc
commit da4b146
Showing
8 changed files
with
147 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
export default class extends Controller { | ||
static targets = [ "input", "clear" ] | ||
|
||
inputTargetConnected() { | ||
this.setSearchClearIcon() | ||
} | ||
|
||
disconnect() { | ||
clearTimeout(this.timeout) | ||
} | ||
|
||
clear() { | ||
this.inputTarget.value = "" | ||
this.element.requestSubmit() | ||
} | ||
|
||
unfocus() { | ||
this.inputTarget.autofocus = false | ||
} | ||
|
||
search() { | ||
clearTimeout(this.timeout) | ||
this.setSearchClearIcon() | ||
this.timeout = setTimeout(() => { | ||
this.element.requestSubmit() | ||
}, 500) | ||
} | ||
|
||
setSearchClearIcon() { | ||
if (this.inputTarget.value.length > 0) | ||
this.clearTarget.classList.remove("hidden") | ||
else | ||
this.clearTarget.classList.add("hidden") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<turbo-frame data-turbo-permanent id="nav-conversations"> | ||
<section id="search" | ||
class="pt-6 text-gray-950 dark:text-gray-100 select-none" | ||
> | ||
<%= form_with(url: conversations_path, | ||
data: { turbo_frame: "nav_conversations", controller: "search" }, | ||
class: "contents", | ||
method: :get | ||
) do |form| %> | ||
<div class="relative ml-2 mr-5"> | ||
<%= form.text_field :query, | ||
value: @query, | ||
placeholder: "Search", | ||
id: "search-input", | ||
autofocus: @query.nil? ? false : true, | ||
class: %| | ||
w-full | ||
p-2 py-1 | ||
border border-gray-200 rounded-lg | ||
text-black dark:text-gray-800 | ||
|, | ||
data: { | ||
search_target: "input", | ||
turbo_permanent: true, | ||
action: %| | ||
blur->search#unfocus | ||
input->search#search | ||
%| | ||
} | ||
%> | ||
<%= icon "x-circle", | ||
variant: :mini, | ||
size: 18, | ||
class: "cursor-pointer text-gray-800 absolute right-1 top-1/2 transform -translate-y-1/2", | ||
data: { search_target: "clear", action: "click->search#clear" } | ||
%> | ||
</div> | ||
<% end %> | ||
</section> | ||
|
||
<section class="text-gray-950 dark:text-gray-100 select-none"> | ||
<turbo-frame id="conversations" | ||
target="conversation" | ||
data-controller="radio-behavior" | ||
data-radio-behavior-selected-class="relationship" | ||
class="block mb-24" <%# ensures the last conversation's menu has room to open %> | ||
> | ||
<% @nav_conversations.each do |named_time_span, conversations| %> | ||
<header class="mx-2 mt-6 mb-2 text-xs font-semibold text-gray-300 text-opacity-1 dark:text-gray-500"> | ||
<%= named_time_span %> | ||
</header> | ||
|
||
<%= render conversations %> | ||
<% end %> | ||
</turbo-frame> | ||
</section> | ||
</turbo-frame> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters