Skip to content

Commit ae20d25

Browse files
committed
Saved search improvements:
* Deleting the currently active saved search redirects to the main index * Re-added the easy unset button
1 parent bba2a55 commit ae20d25

4 files changed

Lines changed: 28 additions & 2 deletions

File tree

app/assets/stylesheets/components/topics.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,20 @@ a.topic-icon {
947947
font-weight: var(--font-weight-medium);
948948
}
949949

950+
.saved-search-clear {
951+
display: inline-flex;
952+
align-items: center;
953+
justify-content: center;
954+
margin-left: var(--spacing-1);
955+
color: var(--color-primary-400);
956+
text-decoration: none;
957+
transition: color var(--transition-fast);
958+
}
959+
960+
.saved-search-clear:hover {
961+
color: var(--color-primary-700);
962+
}
963+
950964
.save-search-prompt {
951965
padding: var(--spacing-3) var(--spacing-4);
952966
margin-bottom: var(--spacing-4);

app/controllers/settings/saved_searches_controller.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ def update
4747

4848
def destroy
4949
@saved_search.destroy
50-
redirect_back fallback_location: settings_saved_searches_path, notice: "Saved search deleted"
50+
51+
referrer = request.referer.to_s
52+
if referrer.include?("saved_search_id=#{@saved_search.id}")
53+
render turbo_stream: %(<turbo-stream action="visit" url="#{root_path}"></turbo-stream>)
54+
else
55+
redirect_back fallback_location: settings_saved_searches_path, notice: "Saved search deleted"
56+
end
5157
end
5258

5359
private

app/javascript/application.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
2-
import "@hotwired/turbo-rails"
2+
import { Turbo } from "@hotwired/turbo-rails"
33
import "controllers"
4+
5+
Turbo.StreamActions.visit = function () {
6+
Turbo.visit(this.getAttribute("url"))
7+
}

app/views/topics/search.html.slim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
span
1111
| Saved search:
1212
strong<> #{@saved_search.name}
13+
= link_to root_path, class: "saved-search-clear", title: "Clear filter"
14+
i.fa-solid.fa-xmark
1315
- elsif @search_query.present? && user_signed_in?
1416
.save-search-prompt data-controller="save-search" data-save-search-url-value=settings_saved_searches_path
1517
.save-search-toggle data-action="click->save-search#toggle"

0 commit comments

Comments
 (0)