// My QBZ > Collections — the index grid of the user's Collections + Artist // Collections (Tauri's CollectionsView.svelte). Same vocabulary as Mixtapes // plus the kind-filter (a second QbzSelect). The 3x3 mosaic appears only for a // `collection` with >= 9 items (handled inside CollectionMosaic). // // HOMOLOGATED to the app's index views: NO per-view back button, 32px L/R // content padding, Typography tokens, ExpandableSearch + QbzSelect + the shared // ViewToggle, surface-elevated NewActionBtn (no blue pill). import { Theme } from "../foundation/semantic-colors.slint"; import { Typography } from "../foundation/typography.slint"; import { MyQbzState, MyQbzActions, MixtapeCardItem, NavState } from "../state.slint"; import { ExpandableSearch } from "../primitives/ExpandableSearch.slint"; import { QbzSelect } from "../primitives/QbzSelect.slint"; import { ListScrollbar } from "../primitives/ListScrollbar.slint"; import { CollectionMosaic } from "CollectionMosaic.slint"; import { NewActionBtn, ViewToggle, MyQbzCard, MyQbzListRow } from "MyQbzShared.slint"; export component CollectionsView inherits Rectangle { property card-w: 208px; property grid-gap: 20px; property card-h: 184px + 12px + 12px + 18px + 2 * 20px + 18px + 12px; property sort-index: MyQbzState.col-sort == "name" ? 1 : MyQbzState.col-sort == "items" ? 2 : MyQbzState.col-sort == "updated" ? 3 : 0; property kind-index: MyQbzState.col-kind-filter == "collection" ? 1 : MyQbzState.col-kind-filter == "artist_collection" ? 2 : 0; background: Theme.surface-main; flick := Flickable { viewport-width: self.width; viewport-height: page.preferred-height; property sr-armed: NavState.restore-scope; function sr-restore() { if (NavState.restore-scope == "collections" && self.viewport-height > self.height) { self.viewport-y = NavState.scroll-restore; NavState.restore-scope = ""; } } init => { self.sr-restore(); } changed sr-armed => { self.sr-restore(); } changed viewport-height => { self.sr-restore(); } changed viewport-y => { NavState.report-scroll(self.viewport-y); } page := VerticalLayout { width: parent.width; padding-top: 16px; padding-right: 32px; padding-bottom: 100px; padding-left: 32px; spacing: 0px; alignment: start; // --- Header — no per-view back button ---------------------- HorizontalLayout { height: 40px; spacing: 16px; VerticalLayout { alignment: center; horizontal-stretch: 1; Text { text: @tr("Collections"); color: Theme.text-primary; font-size: Typography.section; font-weight: Typography.bold; vertical-alignment: center; } } // Header "+ New" shows only when populated; when empty the // empty-state CTA is the single call-to-action (no duplicate). if MyQbzState.collections.length > 0 || MyQbzState.col-search != "" || MyQbzState.col-kind-filter != "all": VerticalLayout { alignment: center; NewActionBtn { clicked => { MyQbzActions.create-collection(); } } } } Rectangle { height: 16px; } // ====================== EMPTY STATE ======================== if MyQbzState.collections.length == 0 && MyQbzState.col-search == "" && MyQbzState.col-kind-filter == "all": VerticalLayout { padding-top: 80px; padding-bottom: 80px; spacing: 16px; alignment: start; HorizontalLayout { alignment: center; CollectionMosaic { size: 160px; empty-kind: "collection"; } } HorizontalLayout { alignment: center; Text { text: @tr("No collections yet"); color: Theme.text-secondary; font-size: Typography.section; font-weight: Typography.semibold; } } HorizontalLayout { alignment: center; NewActionBtn { clicked => { MyQbzActions.create-collection(); } } } } // ====================== POPULATED ========================== if MyQbzState.collections.length > 0 || MyQbzState.col-search != "" || MyQbzState.col-kind-filter != "all": VerticalLayout { spacing: 0px; alignment: start; // --- Toolbar ------------------------------------------- HorizontalLayout { height: 30px; spacing: 8px; Rectangle { horizontal-stretch: 1; } VerticalLayout { alignment: center; ExpandableSearch { placeholder: @tr("Search"); sm: true; query <=> MyQbzState.col-search; edited(q) => { MyQbzActions.col-search-changed(q); } } } VerticalLayout { alignment: center; QbzSelect { menu-width: 180px; sm: true; options: [ @tr("Position"), @tr("Name"), @tr("Items"), @tr("Recently updated"), ]; current-index: root.sort-index; selected(i) => { MyQbzActions.col-set-sort( i == 1 ? "name" : i == 2 ? "items" : i == 3 ? "updated" : "position"); } } } // Kind filter (group-by idiom, second QbzSelect). VerticalLayout { alignment: center; QbzSelect { menu-width: 200px; sm: true; options: [ @tr("All kinds"), @tr("Collections"), @tr("Artist Collections"), ]; current-index: root.kind-index; selected(i) => { MyQbzActions.col-set-kind-filter( i == 1 ? "collection" : i == 2 ? "artist_collection" : "all"); } } } VerticalLayout { alignment: center; ViewToggle { view: MyQbzState.col-view; set-view(v) => { MyQbzActions.col-set-view(v); } } } } Rectangle { height: 16px; } // --- Body: search/filter-empty ------------------------- if MyQbzState.collections.length == 0: Rectangle { height: 80px; Text { text: @tr("No results found"); color: Theme.text-muted; font-size: Typography.legal; horizontal-alignment: center; vertical-alignment: center; x: Math.round((parent.width - self.width) / 2 / 1px) * 1px; y: Math.round((parent.height - self.height) / 2 / 1px) * 1px; } } // --- Body: GRID --------------------------------------- if MyQbzState.collections.length > 0 && MyQbzState.col-view == "grid": grid := Rectangle { property columns: Math.max(1, Math.floor((self.width + root.grid-gap) / (root.card-w + root.grid-gap))); property rows: Math.ceil(MyQbzState.collections.length / self.columns); height: self.rows > 0 ? self.rows * root.card-h + Math.max(0, self.rows - 1) * root.grid-gap : 0px; for item[i] in MyQbzState.collections: MyQbzCard { x: Math.mod(i, grid.columns) * (root.card-w + root.grid-gap); y: Math.floor(i / grid.columns) * (root.card-h + root.grid-gap); item: item; clicked => { MyQbzActions.open-card(item.id); } } } // --- Body: LIST --------------------------------------- if MyQbzState.collections.length > 0 && MyQbzState.col-view == "list": VerticalLayout { spacing: 4px; for item in MyQbzState.collections: MyQbzListRow { item: item; clicked => { MyQbzActions.open-card(item.id); } } } } } } ListScrollbar { x: parent.width - self.width - 4px; y: 0px; width: 14px; height: parent.height; viewport-height: flick.viewport-height; visible-height: flick.height; viewport-y <=> flick.viewport-y; } }