mirror of
https://github.com/yattee/yattee.git
synced 2024-12-23 05:53:41 +00:00
38 lines
1010 B
Swift
38 lines
1010 B
Swift
import Defaults
|
|
import Foundation
|
|
import SwiftUI
|
|
|
|
struct FavoriteButton: View {
|
|
let item: FavoriteItem!
|
|
let favorites = FavoritesModel.shared
|
|
|
|
@State private var isFavorite = false
|
|
|
|
var body: some View {
|
|
Group {
|
|
if favorites.isEnabled {
|
|
Button {
|
|
guard !item.isNil else {
|
|
return
|
|
}
|
|
|
|
favorites.toggle(item)
|
|
isFavorite.toggle()
|
|
} label: {
|
|
if isFavorite {
|
|
Label("Remove from Favorites", systemImage: "heart.fill")
|
|
} else {
|
|
Label("Add to Favorites", systemImage: "heart")
|
|
}
|
|
}
|
|
.disabled(item.isNil)
|
|
.onAppear {
|
|
isFavorite = item.isNil ? false : favorites.contains(item)
|
|
}
|
|
} else {
|
|
EmptyView()
|
|
}
|
|
}
|
|
}
|
|
}
|