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:
@@ -8,8 +8,11 @@ class CollectionsController < ApplicationController
|
||||
end
|
||||
|
||||
def show
|
||||
set_page_and_extract_portion_from @collection.cards.awaiting_triage.reverse_chronologically.with_golden_first
|
||||
fresh_when etag: [ @collection, @page.records, @user_filtering ]
|
||||
if @filter.used?(ignore_collections: true)
|
||||
show_filtered_events
|
||||
else
|
||||
show_columns
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@@ -42,6 +45,16 @@ class CollectionsController < ApplicationController
|
||||
@collection = Current.user.collections.find params[:id]
|
||||
end
|
||||
|
||||
def show_filtered_events
|
||||
@filter.collection_ids = [ @collection.id ]
|
||||
set_page_and_extract_portion_from @filter.cards
|
||||
end
|
||||
|
||||
def show_columns
|
||||
set_page_and_extract_portion_from @collection.cards.awaiting_triage.reverse_chronologically.with_golden_first
|
||||
fresh_when etag: [ @collection, @page.records, @user_filtering ]
|
||||
end
|
||||
|
||||
def collection_params
|
||||
params.expect(collection: [ :name, :all_access, :auto_postpone_period, :public_description ])
|
||||
end
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= render "filters/settings", user_filtering: @user_filtering, no_filtering_url: cards_path %>
|
||||
<%= render "filters/settings", filter_url: cards_path, user_filtering: @user_filtering, no_filtering_url: cards_path %>
|
||||
|
||||
<%= turbo_frame_tag :cards_container do %>
|
||||
<section class="cards cards--grid">
|
||||
|
||||
@@ -12,7 +12,9 @@
|
||||
<% content_for :header do %>
|
||||
<%= render "filters/menu", user_filtering: @user_filtering %>
|
||||
|
||||
<%= link_to collection_path(@card.collection), class: "header__title btn borderless txt-large", style: "--btn-padding: 0.25ch 1ch 0.25ch 0.75ch; view-transistion-name: card-collection-title;", data: { controller: "hotkey", action: "keydown.esc@document->hotkey#click" } do %>
|
||||
<%= link_to collection_url(@card.collection), class: "header__title btn borderless txt-large",
|
||||
style: "--btn-padding: 0.25ch 1ch 0.25ch 0.75ch; view-transistion-name: card-collection-title;",
|
||||
data: { controller: "hotkey", action: "keydown.esc@document->hotkey#click click->turbo-navigation#backIfSamePath" } do %>
|
||||
<span class="overflow-ellipsis">
|
||||
←
|
||||
<strong class="font-black"><%= @card.collection.name %></strong>
|
||||
|
||||
@@ -19,24 +19,18 @@
|
||||
</h1>
|
||||
|
||||
<div class="header__actions header__actions--end">
|
||||
<%= render "cards/collection_settings", collection: @collection %>
|
||||
<%= render "cards/collection_settings", collection: @collection %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= render "filters/settings", user_filtering: @user_filtering, no_filtering_url: collection_path(@collection) do |form| %>
|
||||
<%= render "filters/settings", filter_url: collection_path(@collection), user_filtering: @user_filtering, no_filtering_url: collection_path(@collection) do |form| %>
|
||||
<%= hidden_field_tag "collection_ids[]", @collection.id %>
|
||||
<% end %>
|
||||
|
||||
<%= tag.div data: {
|
||||
controller: "drag-and-drop drag-and-strum",
|
||||
drag_and_drop_dragged_item_class: "drag-and-drop__dragged-item",
|
||||
drag_and_drop_hover_container_class: "drag-and-drop__hover-container",
|
||||
action: "
|
||||
dragstart->drag-and-drop#dragStart
|
||||
dragover->drag-and-drop#dragOver
|
||||
dragenter->drag-and-strum#dragEnter
|
||||
drop->drag-and-drop#drop
|
||||
dragend->drag-and-drop#dragEnd" } do %>
|
||||
|
||||
<%= render "collections/show/columns", page: @page, collection: @collection %>
|
||||
<%= turbo_frame_tag :cards_container do %>
|
||||
<% if @filter.used?(ignore_collections: true) %>
|
||||
<%= render "collections/show/filtered_cards", page: @page %>
|
||||
<% else %>
|
||||
<%= render "collections/show/columns", page: @page, collection: @collection %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
<%= turbo_frame_tag :cards_container do %>
|
||||
<div class="card-columns" data-controller="collapsible-columns" data-collapsible-columns-collapsed-class="is-collapsed">
|
||||
<%= tag.div data: {
|
||||
controller: "drag-and-drop drag-and-strum",
|
||||
drag_and_drop_dragged_item_class: "drag-and-drop__dragged-item",
|
||||
drag_and_drop_hover_container_class: "drag-and-drop__hover-container",
|
||||
action: "
|
||||
dragstart->drag-and-drop#dragStart
|
||||
dragover->drag-and-drop#dragOver
|
||||
dragenter->drag-and-strum#dragEnter
|
||||
drop->drag-and-drop#drop
|
||||
dragend->drag-and-drop#dragEnd" } do %>
|
||||
|
||||
<div class="card-columns" data-controller="collapsible-columns" data-collapsible-columns-collapsed-class="is-collapsed">
|
||||
<div class="card-columns__left">
|
||||
<%= render "collections/show/not_now", collection: collection %>
|
||||
</div>
|
||||
@@ -11,7 +20,8 @@
|
||||
<%= render partial: "collections/show/column", collection: collection.columns, cached: true %>
|
||||
<%= render "collections/show/closed", collection: collection %>
|
||||
|
||||
<%= render "collections/show/menu/columns", collection: collection %>
|
||||
<%= render "collections/show/menu/columns", collection: collection %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<section class="cards cards--grid">
|
||||
<%= render partial: "cards/display/preview", collection: page.records, as: :card, locals: { draggable: true }, cached: ->(card) { cacheable_preview_parts_for(card) } %>
|
||||
</section>
|
||||
@@ -7,7 +7,7 @@
|
||||
filter_settings_filters_set_class: "filters--has-filters-set",
|
||||
filter_settings_no_filtering_url_value: no_filtering_url,
|
||||
filter_settings_refresh_url_value: settings_refresh_path } do %>
|
||||
<%= form_with url: cards_path, method: :get, class: "", data: {
|
||||
<%= form_with url: filter_url, method: :get, class: "", data: {
|
||||
controller: "form",
|
||||
turbo_frame: "cards_container",
|
||||
filter_settings_target: "form",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<html lang="en">
|
||||
<%= render "layouts/shared/head" %>
|
||||
|
||||
<body data-controller="local-time timezone-cookie" data-action="turbo:morph@window->local-time#refreshAll">
|
||||
<body data-controller="local-time timezone-cookie turbo-navigation" data-action="turbo:morph@window->local-time#refreshAll turbo:before-visit@document->turbo-navigation#rememberLocation">
|
||||
<header class="header <%= @header_class %>" id="header">
|
||||
<a href="#main" class="header__skip-navigation btn" data-turbo="false">Skip to main content</a>
|
||||
<%= yield :header %>
|
||||
|
||||
Reference in New Issue
Block a user