mirror of
https://github.com/yattee/yattee.git
synced 2024-12-13 22:00:31 +05:30
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()
|
|
}
|
|
}
|
|
}
|
|
}
|