Merge pull request #1452 from basecamp/keep-search
Keep the last search in place
This commit is contained in:
@@ -29,4 +29,3 @@ class Users::JoinsController < ApplicationController
|
||||
params.expect(user: [ :name, :avatar ])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Controller } from "@hotwired/stimulus"
|
||||
import { post } from "@rails/request.js"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = [ "turboFrame", "searchInput", "buttonsContainer" ]
|
||||
static targets = [ "turboFrame", "search", "searchInput", "form", "buttonsContainer" ]
|
||||
static outlets = [ "dialog" ]
|
||||
static values = {
|
||||
searchUrl: String,
|
||||
@@ -17,18 +17,13 @@ export default class extends Controller {
|
||||
this.dialogOutlet.close()
|
||||
this.#clearTurboFrame()
|
||||
|
||||
this.searchInputTarget.querySelector("input").value = ""
|
||||
this.#showItem(this.buttonsContainerTarget)
|
||||
this.#hideItem(this.searchInputTarget)
|
||||
this.#hideItem(this.searchTarget)
|
||||
}
|
||||
|
||||
showModalAndSubmit(event) {
|
||||
event.preventDefault()
|
||||
|
||||
const form = event.target.closest("form")
|
||||
|
||||
this.showModal()
|
||||
form.requestSubmit()
|
||||
this.formTarget.requestSubmit()
|
||||
}
|
||||
|
||||
showModal() {
|
||||
@@ -36,10 +31,18 @@ export default class extends Controller {
|
||||
}
|
||||
|
||||
search(event) {
|
||||
this.#openInTurboFrame(this.searchUrlValue)
|
||||
|
||||
this.#showItem(this.searchInputTarget)
|
||||
this.#showItem(this.searchTarget)
|
||||
this.#hideItem(this.buttonsContainerTarget)
|
||||
|
||||
if (this.searchInputTarget.value.trim()) {
|
||||
this.showModalAndSubmit()
|
||||
} else {
|
||||
this.#loadTurboFrame()
|
||||
}
|
||||
}
|
||||
|
||||
#loadTurboFrame() {
|
||||
this.turboFrameTarget.src = this.searchUrlValue
|
||||
}
|
||||
|
||||
#clearTurboFrame() {
|
||||
@@ -47,10 +50,6 @@ export default class extends Controller {
|
||||
this.turboFrameTarget.innerHtml = ""
|
||||
}
|
||||
|
||||
#openInTurboFrame(url) {
|
||||
this.turboFrameTarget.src = url
|
||||
}
|
||||
|
||||
#showItem(element) {
|
||||
element.removeAttribute("hidden")
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="bar__input" data-bar-target="searchInput" hidden>
|
||||
<div class="bar__input" data-bar-target="search" hidden>
|
||||
<%= render "searches/form", query_terms: "" %>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= form_with url: search_path, method: :get, class: "search__form flex align-center justify-center gap-half", data: { turbo_frame: "bar_content" } do |form| %>
|
||||
<%= form_with url: search_path, method: :get, class: "search__form flex align-center justify-center gap-half", data: { bar_target: "form", turbo_frame: "bar_content" } do |form| %>
|
||||
<%= form.label :q, "Search BOXCAR", class: "font-weight-black txt-nowrap" %>
|
||||
<%= text_field_tag :q, query_terms,
|
||||
class: "search__input input",
|
||||
@@ -7,7 +7,8 @@
|
||||
autocomplete: "off",
|
||||
autofocus: true,
|
||||
data: {
|
||||
action: "keydown.enter->bar#showModalAndSubmit keydown.esc->bar#reset" } %>
|
||||
bar_target: "searchInput",
|
||||
action: "keydown.enter->bar#showModalAndSubmit:prevent keydown.esc->bar#reset" } %>
|
||||
<button class="search__reset btn btn--circle borderless" data-action="bar#reset">
|
||||
<%= icon_tag "close" %>
|
||||
<span class="for-screen-reader">Close search</span>
|
||||
|
||||
@@ -11,7 +11,7 @@ class Account::SettingsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "update" do
|
||||
put account_settings_path, params: { account: { name: "New Account Name" }}
|
||||
put account_settings_path, params: { account: { name: "New Account Name" } }
|
||||
assert_equal "New Account Name", Account.sole.name
|
||||
assert_redirected_to account_settings_path
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user