mirror of
https://github.com/yattee/yattee.git
synced 2024-11-10 08:18:19 +00:00
26 lines
605 B
Swift
26 lines
605 B
Swift
|
import Foundation
|
||
|
import SwiftUI
|
||
|
|
||
|
struct FavoriteButton: View {
|
||
|
let item: FavoriteItem
|
||
|
let favorites = FavoritesModel.shared
|
||
|
|
||
|
@State private var isFavorite = false
|
||
|
|
||
|
var body: some View {
|
||
|
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)
|
||
|
}
|
||
|
}
|
||
|
}
|