SPB Git

Repository Public

ArtistsView.swift 8.1 KB 173 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : SP Music pour macOS9// File             : Features/Artists/ArtistsView.swift10// Description      : Artists grid and artist detail.11// Module           : Features12// Repository       : https://git.spboucher.ai/sp-music-macos13// Created          : 2026-11-1814// Last Modified    : 2026-11-1815//16// =============================================================================17// AUTHOR & PROFESSIONAL AFFILIATION18// =============================================================================19//20// Author           : Simon-Pierre Boucher21// Position         : Professor of Finance22// Institution      : Université du Québec en Outaouais (UQO)23// Department       : Département des sciences administratives24// Organization     : SP Boucher25//26// Website          : https://spboucher.ai27// Git              : https://git.spboucher.ai28//29// =============================================================================30// OFFICIAL CONTACT DIRECTORY31// =============================================================================32//33// General          : info@spboucher.ai34// Professional     : contact@spboucher.ai35// Direct           : simon@spboucher.ai36// Research         : research@spboucher.ai37// Development      : dev@spboucher.ai38// Support          : support@spboucher.ai39// Security/Admin   : admin@spboucher.ai40// Notifications    : notifications@spboucher.ai41//42// Preferred Contact: support@spboucher.ai43//44// =============================================================================45// COPYRIGHT & INTELLECTUAL PROPERTY46// =============================================================================47//48// Copyright (c) 202649// Simon-Pierre Boucher50//51// All rights reserved where applicable.52//53// This file is governed by the applicable project license,54// copyright notices, institutional agreements and relevant law.55//56// Unless expressly authorized by the applicable license or57// rights holder, copying, redistribution, sublicensing,58// publication and commercial exploitation are not permitted.59//60// Existing third-party rights and notices remain unaffected.61//62// =============================================================================63// CONFIDENTIALITY & SECURITY64// =============================================================================65//66// Classification   : Public67// Distribution     : Public repository; use is governed by the project license68// Security Contact : admin@spboucher.ai69//70// Access to this source does not independently grant permission71// to redistribute or disclose confidential materials.72//73// Do not embed credentials, private keys, access tokens,74// certificates or confidential personal information.75//76// =============================================================================77// LICENSE & MAINTENANCE78// =============================================================================79//80// License          : None specified (no license file in this repository)81// Maintainer       : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import SwiftUI89import SPMusicCore9091struct ArtistsView: View {92    @Environment(AppModel.self) private var model93    @State private var artists: [Artist] = []94    @State private var loaded = false9596    var body: some View {97        Group {98            if loaded && artists.isEmpty {99                EmptyState(symbol: "music.mic", title: model.downloadedOnly ? "Aucun artiste téléchargé" : "Aucun artiste")100            } else {101                ScrollView {102                    LazyVGrid(columns: [GridItem(.adaptive(minimum: 140, maximum: 180), spacing: 20, alignment: .top)], spacing: 22) {103                        ForEach(artists) { a in104                            VStack(spacing: 8) {105                                ArtworkView(artworkID: a.artworkID, size: 130, cornerRadius: 65, symbol: "music.mic").shadow(color: .black.opacity(0.15), radius: 6, y: 3)106                                Text(a.name).font(.callout.weight(.medium)).lineLimit(1)107                                Text("\(a.albumCount) album\(a.albumCount > 1 ? "s" : "")").font(.caption).foregroundStyle(.secondary)108                            }109                            .frame(width: 140).contentShape(Rectangle())110                            .onTapGesture { model.show(.artist(a.id)) }111                            .accessibilityElement(children: .combine).accessibilityAddTraits(.isButton)112                        }113                    }114                    .padding(24)115                }116            }117        }118        .navigationTitle("Artistes").navigationSubtitle(loaded ? "\(artists.count) artistes" : "")119        .libraryTask(model) { artists = await model.store?.artists(downloadedOnly: model.downloadedOnly) ?? []; loaded = true }120    }121}122123struct ArtistDetailView: View {124    @Environment(AppModel.self) private var model125    let artistID: String126    @State private var artist: Artist?127    @State private var albums: [Album] = []128    @State private var tracks: [Track] = []129    @State private var loaded = false130131    var body: some View {132        ZStack {133            Color.clear134            if let artist {135                ScrollView {136                    VStack(alignment: .leading, spacing: 24) {137                        HStack(alignment: .bottom, spacing: 20) {138                            ArtworkView(artworkID: artist.artworkID, size: 150, cornerRadius: 75, symbol: "music.mic").shadow(color: .black.opacity(0.2), radius: 12, y: 6)139                            VStack(alignment: .leading, spacing: 8) {140                                Text(artist.name).font(.system(size: 34, weight: .bold))141                                Text("\(albums.count) album\(albums.count > 1 ? "s" : "") · \(tracks.count) titres").foregroundStyle(.secondary)142                                HStack {143                                    Button { model.play(tracks) } label: { Label("Lire", systemImage: "play.fill") }.buttonStyle(.borderedProminent).controlSize(.large)144                                    Button { model.play(tracks, shuffle: true) } label: { Label("Aléatoire", systemImage: "shuffle") }.controlSize(.large)145                                    if tracks.contains(where: { !$0.isDownloaded }) {146                                        Button { model.download(tracks) } label: { Label("Tout télécharger", systemImage: "arrow.down.circle") }.controlSize(.large).disabled(!model.isOnline)147                                    }148                                }149                            }150                        }151                        if !albums.isEmpty { VStack(alignment: .leading, spacing: 10) { SectionHeader(title: "Albums"); AlbumGrid(albums: albums) } }152                        if !tracks.isEmpty {153                            VStack(alignment: .leading, spacing: 6) {154                                SectionHeader(title: "Titres")155                                ForEach(Array(tracks.prefix(200).enumerated()), id: \.element.id) { i, t in TrackRow(track: t, showArtist: false) { model.play(tracks, at: i) } }156                            }157                        }158                    }159                    .padding(24).frame(maxWidth: .infinity, alignment: .leading)160                }161            } else if loaded { EmptyState(symbol: "music.mic", title: "Artiste introuvable") }162        }163        .navigationTitle(artist?.name ?? "")164        .libraryTask(model, extra: artistID) {165            guard let s = model.store else { return }166            artist = await s.artist(artistID)167            albums = await s.artistAlbums(artistID, downloadedOnly: model.downloadedOnly)168            tracks = await s.artistTracks(artistID, downloadedOnly: model.downloadedOnly)169            loaded = true170        }171    }172}173
Files main
Menu

Theme