Use a switch to toggle proposal selection

The button to select/deselect a proposal wasn't very intuitive; for
example, it wasn't obvious that pressing a button saying "selected"
would deselect the proposal.

So we're using a switch control, like we do to enable/disable features
since commit fabe97e50.
This commit is contained in:
Javi Martín
2021-08-20 02:58:10 +02:00
parent b127bd2f51
commit fec44c146c
7 changed files with 53 additions and 30 deletions

View File

@@ -1 +1 @@
<%= button_to text, path, options %>
<%= render Admin::ToggleSwitchComponent.new(action, proposal, pressed: selected?, **options) %>

View File

@@ -7,27 +7,21 @@ class Admin::Proposals::ToggleSelectionComponent < ApplicationComponent
private
def text
if proposal.selected?
t("admin.proposals.index.selected")
else
t("admin.proposals.index.select")
end
def action
:toggle_selection
end
def path
admin_polymorphic_path(proposal, action: :toggle_selection)
def selected?
proposal.selected?
end
def options
{ remote: true, method: :patch, class: html_class }
{
"aria-label": label
}
end
def html_class
if proposal.selected?
"button expanded"
else
"button hollow expanded"
end
def label
t("admin.actions.label", action: t("admin.actions.select"), name: proposal.title)
end
end