38 lines
1.0 KiB
Swift
38 lines
1.0 KiB
Swift
//
|
|
// FavoriteButton.swift
|
|
// Mobile Music Assistant
|
|
//
|
|
// Created by Sven Hanold on 05.04.26.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
/// Reusable heart button for toggling favorites on artists, albums, and tracks.
|
|
struct FavoriteButton: View {
|
|
@Environment(MAService.self) private var service
|
|
let uri: String
|
|
var size: CGFloat = 22
|
|
var showInLight: Bool = false
|
|
|
|
private var isFavorite: Bool {
|
|
service.libraryManager.isFavorite(uri: uri)
|
|
}
|
|
|
|
var body: some View {
|
|
Button {
|
|
Task {
|
|
await service.libraryManager.toggleFavorite(
|
|
uri: uri,
|
|
currentlyFavorite: isFavorite
|
|
)
|
|
}
|
|
} label: {
|
|
Image(systemName: isFavorite ? "heart.fill" : "heart")
|
|
.font(.system(size: size))
|
|
.foregroundStyle(isFavorite ? .red : (showInLight ? .white.opacity(0.7) : .secondary))
|
|
.contentTransition(.symbolEffect(.replace))
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
}
|