2021-12-01 11:22:19 +00:00
|
|
|
import Defaults
|
2021-11-01 21:56:18 +00:00
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct FavoriteButton: View {
|
|
|
|
let item: FavoriteItem
|
|
|
|
let favorites = FavoritesModel.shared
|
|
|
|
|
|
|
|
@State private var isFavorite = false
|
|
|
|
|
2021-12-01 11:22:19 +00:00
|
|
|
@Default(.visibleSections) private var visibleSections
|
|
|
|
|
2021-11-01 21:56:18 +00:00
|
|
|
var body: some View {
|
2021-12-01 11:22:19 +00:00
|
|
|
Group {
|
|
|
|
if visibleSections.contains(.favorites) {
|
|
|
|
Button {
|
|
|
|
favorites.toggle(item)
|
|
|
|
isFavorite.toggle()
|
|
|
|
} label: {
|
|
|
|
if isFavorite {
|
|
|
|
Label("Remove from Favorites", systemImage: "heart.fill")
|
|
|
|
} else {
|
|
|
|
Label("Add to Favorites", systemImage: "heart")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.onAppear {
|
|
|
|
isFavorite = favorites.contains(item)
|
|
|
|
}
|
2021-11-01 21:56:18 +00:00
|
|
|
} else {
|
2021-12-01 11:22:19 +00:00
|
|
|
EmptyView()
|
2021-11-01 21:56:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|