refactor(slint): promote multi-select bulk bar to a shared primitive
Extract PlaylistView's inline bulk action bar into a shared MultiSelectBar primitive driven by a [BulkAction] model (id / label / danger / needs-selection) emitting action(id). PlaylistView now declares its two actions (Select all, Remove) as data; the Favorites tracks tab will reuse the same bar with its larger action set instead of copying it. Same visual (count label + bordered/hover buttons, ADR-008). cc
This commit is contained in:
3 files changed
+97
-59
No files matched your search
@@ -12,6 +12,7 @@ import { TrackRow } from "../primitives/TrackRow.slint";
|
||||
import { ExpandableSearch } from "../primitives/ExpandableSearch.slint";
|
||||
import { ListScrollbar } from "../primitives/ListScrollbar.slint";
|
||||
import { LoadingSpinner } from "../primitives/LoadingSpinner.slint";
|
||||
import { MultiSelectBar } from "../primitives/MultiSelectBar.slint";
|
||||
import { NavButtons } from "../shell/NavButtons.slint";
|
||||
import { ListView } from "std-widgets.slint";
|
||||
|
||||
@@ -581,65 +582,14 @@ export component PlaylistView inherits Rectangle {
|
||||
Rectangle { height: 6px; }
|
||||
|
||||
// Bulk action bar — visible in edit mode.
|
||||
if PlaylistState.multi-select-mode: Rectangle {
|
||||
height: 44px;
|
||||
border-radius: 8px;
|
||||
background: Theme.surface-elevated;
|
||||
HorizontalLayout {
|
||||
padding-left: 14px;
|
||||
padding-right: 10px;
|
||||
spacing: 12px;
|
||||
Text {
|
||||
text: PlaylistState.selected-count + " " + @tr("selected");
|
||||
color: Theme.text-secondary;
|
||||
font-size: Typography.body;
|
||||
vertical-alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
}
|
||||
pill-all := Rectangle {
|
||||
width: all-label.preferred-width + 24px;
|
||||
height: 30px;
|
||||
border-radius: Radius.sm;
|
||||
background: all-ta.has-hover ? Theme.surface-hover : transparent;
|
||||
all-label := Text {
|
||||
text: @tr("Select all");
|
||||
color: Theme.text-secondary;
|
||||
font-size: Typography.legal;
|
||||
x: (parent.width - self.width) / 2;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
all-ta := TouchArea {
|
||||
mouse-cursor: pointer;
|
||||
clicked => {
|
||||
root.media-action("playlist", "", "select-all");
|
||||
}
|
||||
}
|
||||
}
|
||||
pill-remove := Rectangle {
|
||||
width: rm-label.preferred-width + 24px;
|
||||
height: 30px;
|
||||
border-radius: Radius.sm;
|
||||
opacity: PlaylistState.selected-count > 0 ? 1.0 : 0.5;
|
||||
background: rm-ta.has-hover ? #ef444433 : transparent;
|
||||
border-width: 1px;
|
||||
border-color: #ef4444;
|
||||
rm-label := Text {
|
||||
text: @tr("Remove");
|
||||
color: #ef4444;
|
||||
font-size: Typography.legal;
|
||||
font-weight: Typography.medium;
|
||||
x: (parent.width - self.width) / 2;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
rm-ta := TouchArea {
|
||||
mouse-cursor: PlaylistState.selected-count > 0 ? pointer : default;
|
||||
clicked => {
|
||||
if (PlaylistState.selected-count > 0) {
|
||||
root.media-action("playlist", "", "remove-selected");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if PlaylistState.multi-select-mode: MultiSelectBar {
|
||||
selected-count: PlaylistState.selected-count;
|
||||
actions: [
|
||||
{ id: "select-all", label: @tr("Select all"), danger: false, needs-selection: false },
|
||||
{ id: "remove-selected", label: @tr("Remove"), danger: true, needs-selection: true },
|
||||
];
|
||||
action(id) => {
|
||||
root.media-action("playlist", "", id);
|
||||
}
|
||||
}
|
||||
if PlaylistState.multi-select-mode: Rectangle { height: 8px; }
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
// Multi-select bulk action bar — a "N selected" count label plus a row
|
||||
// of action buttons driven by a [BulkAction] model, so the bar's chrome
|
||||
// lives in one place. Shared by PlaylistView and the Favorites tracks
|
||||
// tab. Emits the chosen action's id via `action(id)`; the surrounding
|
||||
// view maps that id to a command. ADR-008: these are bordered/hover
|
||||
// buttons, not pills.
|
||||
|
||||
import { Theme } from "../foundation/semantic-colors.slint";
|
||||
import { Typography } from "../foundation/typography.slint";
|
||||
import { Radius } from "../foundation/radius.slint";
|
||||
import { BulkAction } from "../state.slint";
|
||||
|
||||
// One action button — borderless hover for a normal action, red-bordered
|
||||
// for a danger action, dimmed + non-interactive when it needs a selection
|
||||
// and there is none.
|
||||
component BulkButton inherits Rectangle {
|
||||
in property <string> label;
|
||||
in property <bool> danger: false;
|
||||
in property <bool> enabled-when: true;
|
||||
callback clicked();
|
||||
|
||||
width: lbl.preferred-width + 24px;
|
||||
height: 30px;
|
||||
border-radius: Radius.sm;
|
||||
opacity: root.enabled-when ? 1.0 : 0.5;
|
||||
background: root.danger
|
||||
? (ta.has-hover ? #ef444433 : transparent)
|
||||
: (ta.has-hover ? Theme.surface-hover : transparent);
|
||||
border-width: root.danger ? 1px : 0px;
|
||||
border-color: #ef4444;
|
||||
|
||||
lbl := Text {
|
||||
text: root.label;
|
||||
color: root.danger ? #ef4444 : Theme.text-secondary;
|
||||
font-size: Typography.legal;
|
||||
font-weight: root.danger ? Typography.medium : Typography.regular;
|
||||
x: (parent.width - self.width) / 2;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
|
||||
ta := TouchArea {
|
||||
mouse-cursor: root.enabled-when ? pointer : default;
|
||||
clicked => {
|
||||
if (root.enabled-when) {
|
||||
root.clicked();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export component MultiSelectBar inherits Rectangle {
|
||||
in property <int> selected-count: 0;
|
||||
in property <[BulkAction]> actions;
|
||||
callback action(string);
|
||||
|
||||
height: 44px;
|
||||
border-radius: 8px;
|
||||
background: Theme.surface-elevated;
|
||||
|
||||
HorizontalLayout {
|
||||
padding-left: 14px;
|
||||
padding-right: 10px;
|
||||
spacing: 12px;
|
||||
Text {
|
||||
text: root.selected-count + " " + @tr("selected");
|
||||
color: Theme.text-secondary;
|
||||
font-size: Typography.body;
|
||||
vertical-alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
}
|
||||
for act in root.actions: BulkButton {
|
||||
label: act.label;
|
||||
danger: act.danger;
|
||||
enabled-when: !act.needs-selection || root.selected-count > 0;
|
||||
clicked => {
|
||||
root.action(act.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,14 @@ export struct AlbumCardItem {
|
||||
plain-year: string, // "1973" — bare year for the list-row YEAR column
|
||||
}
|
||||
|
||||
// One button in the shared multi-select bulk bar (MultiSelectBar).
|
||||
export struct BulkAction {
|
||||
id: string, // emitted verbatim via MultiSelectBar.action(id)
|
||||
label: string, // already-translated button label
|
||||
danger: bool, // red-bordered destructive button (e.g. Remove)
|
||||
needs-selection: bool, // dimmed + disabled while nothing is selected
|
||||
}
|
||||
|
||||
export struct DiscoverSection {
|
||||
title: string,
|
||||
// Discover endpoint path this section maps to (e.g. "/discover/newReleases").
|
||||
|
||||
Reference in new issue
Block a user