Files
qbz/crates/qbz-slint/ui/search/SearchResultsView.slint
T
vicrodh 61232c05ce fix(slint): rebuild search results view to match Tauri
The results view was bare text rows — nothing like the Tauri search.
Rebuilt it from the components the successful views already use:

- Albums: a Carousel of AlbumCard cover cards (All tab) and an AlbumCard
  grid (Albums tab).
- Artists: new ArtistCard (circular portrait) + ArtistCarousel; an
  ArtistCard grid on the Artists tab.
- Tracks: SearchTrackRow with a position number.
- The history nav pair (NavButtons) added to the view toolbar.

cc
2026-05-19 12:53:46 -06:00

471 lines
17 KiB
Plaintext

// Search results view — a tabbed results page, ported faithfully from
// the Tauri SearchView.
//
// Toolbar with the history nav pair, a five-tab strip, and a scrollable
// body. The All tab is a dashboard (a top-result hero, an albums
// carousel, an artists carousel, and capped track/playlist previews);
// the per-type tabs show the full loaded set as a card grid or row list
// with a load-more button. Data comes from the SearchState global.
import { SearchState, SearchActions, SearchTrackItem, SearchPlaylistItem, AlbumCardItem, SlimItem } from "../state.slint";
import { Theme } from "../foundation/semantic-colors.slint";
import { Typography } from "../foundation/typography.slint";
import { Radius } from "../foundation/radius.slint";
import { Carousel } from "../discover/Carousel.slint";
import { ArtistCarousel } from "../discover/ArtistCarousel.slint";
import { AlbumCard } from "../discover/AlbumCard.slint";
import { ArtistCard } from "../discover/ArtistCard.slint";
import { SearchTrackRow } from "SearchTrackRow.slint";
import { NavButtons } from "../shell/NavButtons.slint";
import { QbzIcon } from "../primitives/QbzIcon.slint";
import { QbzSelect } from "../primitives/QbzSelect.slint";
// One tab in the results tab strip.
component SearchTab inherits Rectangle {
in property <string> label;
in property <bool> active;
callback clicked();
VerticalLayout {
spacing: 5px;
Text {
text: root.label;
color: root.active
? Theme.text-primary
: (ta.has-hover ? Theme.text-secondary : Theme.text-muted);
font-size: 14px;
font-weight: root.active ? 700 : 500;
}
Rectangle {
height: 2px;
border-radius: 1px;
background: root.active ? Theme.accent : transparent;
}
}
ta := TouchArea {
mouse-cursor: pointer;
clicked => {
root.clicked();
}
}
}
// "Title (count)" with an optional "View more" affordance.
component SectionHeader inherits Rectangle {
in property <string> title;
in property <int> count;
in property <bool> show-more;
callback more-clicked();
height: 28px;
HorizontalLayout {
Text {
text: root.title + " (\{root.count})";
color: Theme.text-primary;
font-size: 18px;
font-weight: Typography.semibold;
vertical-alignment: center;
horizontal-stretch: 1;
}
if root.show-more: Rectangle {
width: more-text.preferred-width + 8px;
more-text := Text {
text: @tr("View more");
color: more-ta.has-hover ? Theme.text-primary : Theme.accent;
font-size: 13px;
vertical-alignment: center;
}
more-ta := TouchArea {
mouse-cursor: pointer;
clicked => {
root.more-clicked();
}
}
}
}
}
// A "Load more (loaded / total)" button shown under a per-type list.
component LoadMoreButton inherits Rectangle {
in property <int> loaded;
in property <int> total;
callback clicked();
visible: root.loaded < root.total;
height: self.visible ? 44px : 0px;
horizontal-stretch: 1;
Rectangle {
width: btn-text.preferred-width + 36px;
height: 32px;
border-radius: Radius.sm;
background: btn-ta.has-hover ? Theme.surface-elevated : Theme.surface-card;
border-width: 1px;
border-color: Theme.border-subtle;
btn-text := Text {
text: @tr("Load more") + " (\{root.loaded} / \{root.total})";
color: Theme.text-secondary;
font-size: 13px;
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
}
btn-ta := TouchArea {
mouse-cursor: pointer;
clicked => {
root.clicked();
}
}
}
}
// A playlist result row — cover thumbnail, title / subtitle.
component SearchPlaylistRow inherits Rectangle {
in property <SearchPlaylistItem> playlist;
in property <int> index;
height: 56px;
border-radius: 8px;
background: Math.mod(root.index, 2) == 1 ? #ffffff07 : transparent;
HorizontalLayout {
padding-left: 12px;
padding-right: 12px;
spacing: 14px;
VerticalLayout {
alignment: center;
Rectangle {
width: 40px;
height: 40px;
border-radius: Radius.sm;
clip: true;
background: Theme.surface-elevated;
QbzIcon {
source: @image-url("../assets/icons/list-music.svg");
width: 18px;
height: 18px;
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
tint: Theme.text-muted;
}
Image {
width: 100%;
height: 100%;
source: root.playlist.artwork;
image-fit: cover;
}
}
}
VerticalLayout {
alignment: center;
horizontal-stretch: 1;
spacing: 2px;
Text {
text: root.playlist.title;
color: Theme.text-primary;
font-size: Typography.body;
font-weight: Typography.medium;
overflow: elide;
}
Text {
text: root.playlist.subtitle;
visible: root.playlist.subtitle != "";
color: Theme.text-muted;
font-size: Typography.link;
overflow: elide;
}
}
}
}
// A wrapping grid of album cards (per-type Albums tab).
component AlbumGrid inherits Rectangle {
in property <[AlbumCardItem]> albums;
callback open(string);
callback media-action(string, string, string);
property <length> card-w: 220px;
property <length> card-h: 266px;
property <length> gap: 24px;
property <int> columns:
Math.max(1, Math.floor((self.width + root.gap) / (root.card-w + root.gap)));
property <int> row-count: Math.ceil(root.albums.length / root.columns);
height: root.row-count > 0
? root.row-count * root.card-h + (root.row-count - 1) * root.gap
: 0px;
for album[i] in root.albums: AlbumCard {
x: Math.mod(i, root.columns) * (root.card-w + root.gap);
y: Math.floor(i / root.columns) * (root.card-h + root.gap);
album: album;
clicked(id) => {
root.open(id);
}
media-action(k, ii, a) => {
root.media-action(k, ii, a);
}
}
}
// A wrapping grid of artist cards (per-type Artists tab).
component ArtistGrid inherits Rectangle {
in property <[SlimItem]> artists;
callback open(string);
property <length> card-w: 160px;
property <length> card-h: 200px;
property <length> gap: 24px;
property <int> columns:
Math.max(1, Math.floor((self.width + root.gap) / (root.card-w + root.gap)));
property <int> row-count: Math.ceil(root.artists.length / root.columns);
height: root.row-count > 0
? root.row-count * root.card-h + (root.row-count - 1) * root.gap
: 0px;
for artist[i] in root.artists: ArtistCard {
x: Math.mod(i, root.columns) * (root.card-w + root.gap);
y: Math.floor(i / root.columns) * (root.card-h + root.gap);
artist: artist;
clicked(id) => {
root.open(id);
}
}
}
export component SearchResultsView inherits Rectangle {
callback open-album(string);
callback open-artist(string);
callback media-action(string, string, string);
// How many tracks/playlists each category previews on the All tab.
property <int> preview-cap: 5;
background: Theme.surface-main;
VerticalLayout {
spacing: 0px;
// --- Toolbar: history nav pair ----------------------------------
Rectangle {
height: 56px;
background: Theme.surface-main;
HorizontalLayout {
x: 32px;
y: 25px - self.height / 2;
width: self.preferred-width;
height: self.preferred-height;
VerticalLayout {
alignment: center;
NavButtons { }
}
}
}
// --- Fixed header: title, tabs, filter --------------------------
VerticalLayout {
padding-left: 32px;
padding-right: 32px;
padding-bottom: 10px;
spacing: 14px;
Text {
text: SearchState.loading
? @tr("Searching…")
: @tr("Results for ") + SearchState.query;
color: Theme.text-primary;
font-size: 24px;
font-weight: 700;
}
HorizontalLayout {
spacing: 22px;
alignment: start;
SearchTab {
label: @tr("All");
active: SearchState.tab == 0;
clicked => { SearchActions.tab-changed(0); }
}
SearchTab {
label: @tr("Albums");
active: SearchState.tab == 1;
clicked => { SearchActions.tab-changed(1); }
}
SearchTab {
label: @tr("Tracks");
active: SearchState.tab == 2;
clicked => { SearchActions.tab-changed(2); }
}
SearchTab {
label: @tr("Artists");
active: SearchState.tab == 3;
clicked => { SearchActions.tab-changed(3); }
}
SearchTab {
label: @tr("Playlists");
active: SearchState.tab == 4;
clicked => { SearchActions.tab-changed(4); }
}
}
if SearchState.tab >= 1 && SearchState.tab <= 3: HorizontalLayout {
alignment: start;
QbzSelect {
menu-width: 180px;
options: [
@tr("No filter"),
@tr("Main artist"),
@tr("Performer"),
@tr("Composer"),
@tr("Label"),
@tr("Release name"),
];
current-index: SearchState.filter-index;
selected(i) => {
SearchActions.filter-changed(i);
}
}
}
}
// --- Scrollable results body ------------------------------------
Flickable {
vertical-stretch: 1;
viewport-width: self.width;
viewport-height: body.preferred-height;
body := VerticalLayout {
padding-left: 32px;
padding-right: 32px;
padding-bottom: 32px;
spacing: 24px;
alignment: start;
// ---- Top result (All tab) ---------------------------------
if SearchState.tab == 0 && SearchState.most-popular-kind != "": VerticalLayout {
spacing: 12px;
Text {
text: @tr("Top result");
color: Theme.text-primary;
font-size: 18px;
font-weight: Typography.semibold;
}
HorizontalLayout {
alignment: start;
if SearchState.most-popular-kind == "artist": ArtistCard {
artist: SearchState.most-popular-artist;
clicked(id) => { root.open-artist(id); }
}
if SearchState.most-popular-kind == "album": AlbumCard {
album: SearchState.most-popular-album;
clicked(id) => { root.open-album(id); }
media-action(k, i, a) => { root.media-action(k, i, a); }
}
}
if SearchState.most-popular-kind == "track": SearchTrackRow {
track: SearchState.most-popular-track;
index: 0;
media-action(k, i, a) => { root.media-action(k, i, a); }
}
}
// ---- Albums -----------------------------------------------
if SearchState.tab == 0 && SearchState.albums.length > 0: Carousel {
section: {
title: @tr("Albums") + " (\{SearchState.albums-total})",
albums: SearchState.albums,
};
album-clicked(id) => { root.open-album(id); }
media-action(k, i, a) => { root.media-action(k, i, a); }
}
if SearchState.tab == 1: AlbumGrid {
albums: SearchState.albums;
open(id) => { root.open-album(id); }
media-action(k, i, a) => { root.media-action(k, i, a); }
}
if SearchState.tab == 1: LoadMoreButton {
loaded: SearchState.albums.length;
total: SearchState.albums-total;
clicked => { SearchActions.load-more(1); }
}
// ---- Artists ----------------------------------------------
if SearchState.tab == 0 && SearchState.artists.length > 0: ArtistCarousel {
title: @tr("Artists") + " (\{SearchState.artists-total})";
artists: SearchState.artists;
artist-clicked(id) => { root.open-artist(id); }
}
if SearchState.tab == 3: ArtistGrid {
artists: SearchState.artists;
open(id) => { root.open-artist(id); }
}
if SearchState.tab == 3: LoadMoreButton {
loaded: SearchState.artists.length;
total: SearchState.artists-total;
clicked => { SearchActions.load-more(3); }
}
// ---- Tracks -----------------------------------------------
if (SearchState.tab == 0 || SearchState.tab == 2) && SearchState.tracks.length > 0: VerticalLayout {
spacing: 4px;
SectionHeader {
title: @tr("Tracks");
count: SearchState.tracks-total;
show-more: SearchState.tab == 0 && SearchState.tracks-total > root.preview-cap;
more-clicked => { SearchActions.tab-changed(2); }
}
for track[idx] in SearchState.tracks: SearchTrackRow {
visible: SearchState.tab == 2 || idx < root.preview-cap;
height: self.visible ? 56px : 0px;
track: track;
index: idx;
media-action(k, i, a) => { root.media-action(k, i, a); }
}
if SearchState.tab == 2: LoadMoreButton {
loaded: SearchState.tracks.length;
total: SearchState.tracks-total;
clicked => { SearchActions.load-more(2); }
}
}
// ---- Playlists --------------------------------------------
if (SearchState.tab == 0 || SearchState.tab == 4) && SearchState.playlists.length > 0: VerticalLayout {
spacing: 4px;
SectionHeader {
title: @tr("Playlists");
count: SearchState.playlists-total;
show-more: SearchState.tab == 0 && SearchState.playlists-total > root.preview-cap;
more-clicked => { SearchActions.tab-changed(4); }
}
for playlist[idx] in SearchState.playlists: SearchPlaylistRow {
visible: SearchState.tab == 4 || idx < root.preview-cap;
height: self.visible ? 56px : 0px;
playlist: playlist;
index: idx;
}
if SearchState.tab == 4: LoadMoreButton {
loaded: SearchState.playlists.length;
total: SearchState.playlists-total;
clicked => { SearchActions.load-more(4); }
}
}
// ---- Empty state ------------------------------------------
if !SearchState.loading
&& SearchState.albums.length == 0
&& SearchState.tracks.length == 0
&& SearchState.artists.length == 0
&& SearchState.playlists.length == 0: Text {
text: @tr("No results.");
color: Theme.text-muted;
font-size: 14px;
}
}
}
}
}