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:
@@ -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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user