Enable page refreshes with morphing
Update Trix to a compatible version https://github.com/basecamp/house/tree/morphing-2
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
import { debounce } from "helpers/timing_helpers"
|
||||
import { debounce, nextFrame } from "helpers/timing_helpers"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ["input"]
|
||||
@@ -10,7 +10,7 @@ export default class extends Controller {
|
||||
}
|
||||
|
||||
connect() {
|
||||
this.#restoreContent()
|
||||
this.restoreContent()
|
||||
}
|
||||
|
||||
submit({ detail: { success } }) {
|
||||
@@ -28,20 +28,22 @@ export default class extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
#clear() {
|
||||
localStorage.removeItem(this.keyValue)
|
||||
}
|
||||
|
||||
#restoreContent() {
|
||||
async restoreContent() {
|
||||
await nextFrame()
|
||||
const savedContent = localStorage.getItem(this.keyValue)
|
||||
|
||||
if (savedContent) {
|
||||
this.inputTarget.value = savedContent
|
||||
this.#triggerChangeEvent(savedContent)
|
||||
}
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
#clear() {
|
||||
localStorage.removeItem(this.keyValue)
|
||||
}
|
||||
|
||||
#triggerChangeEvent(newValue) {
|
||||
if (this.inputTarget.tagName === "HOUSE-MD") {
|
||||
this.inputTarget.dispatchEvent(new CustomEvent('house-md:change', {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<% @page_title = @filter.summary %>
|
||||
|
||||
<% turbo_refreshes_with method: :morph, scroll: :preserve %>
|
||||
<%= render "filters/broadcasts", filter: @filter %>
|
||||
|
||||
<% content_for :header do %>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
local_save_key_value: "comment-#{bubble.id}",
|
||||
action: "turbo:submit-end->local-save#submit keydown.ctrl+enter->form#submit:prevent keydown.meta+enter->form#submit:prevent keydown.esc->form#cancel:stop paste->paste#pasteFiles" } do |form| %>
|
||||
<%= form.markdown_area :body, class: "input comment__input", required: true, placeholder: new_comment_placeholder(bubble),
|
||||
data: { local_save_target: "input", action: "house-md:change->local-save#save" } %>
|
||||
data: { local_save_target: "input", action: "house-md:change->local-save#save turbo:morph-element->local-save#restoreContent" } %>
|
||||
<%= form.button class: "comment__submit btn btn--reversed flex-item-justify-start" do %>
|
||||
<span>Post this comment</span>
|
||||
<% end %>
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
<%= csp_meta_tag %>
|
||||
<%= tag.meta name: "current-user-id", content: Current.user.id if Current.user %>
|
||||
|
||||
<% turbo_refreshes_with method: :morph, scroll: :preserve %>
|
||||
|
||||
<%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
|
||||
<%= javascript_importmap_tags %>
|
||||
|
||||
|
||||
Vendored
+43
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user