Fix: Keep the previous filtering when navigating back from cards

https://fizzy.37signals.com/5986089/cards/1760/edit

This also adds a proper resource for filtered collections, instead of changing the URL to cards for filtering cards.
This commit is contained in:
Jorge Manrubia
2025-09-30 15:31:56 +02:00
parent d0003e6e94
commit 0347806ce1
9 changed files with 70 additions and 23 deletions
@@ -0,0 +1,25 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
rememberLocation() {
sessionStorage.setItem("referrerUrl", window.location.href)
}
backIfSamePath(event) {
const link = event.target.closest("a")
const targetUrl = new URL(link.href)
if (this.#referrerPath && targetUrl.pathname === this.#referrerPath) {
event.preventDefault()
Turbo.visit(this.#referrerUrl)
}
}
get #referrerPath() {
if (!this.#referrerUrl) return null
return new URL(this.#referrerUrl).pathname
}
get #referrerUrl() {
return sessionStorage.getItem("referrerUrl")
}
}