1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-14 22:30:32 +05:30
yattee/Shared/Views/FavoriteButton.swift

35 lines
928 B
Swift
Raw Normal View History

import Defaults
2021-11-02 03:26:18 +05:30
import Foundation
import SwiftUI
struct FavoriteButton: View {
let item: FavoriteItem
let favorites = FavoritesModel.shared
@State private var isFavorite = false
@Default(.visibleSections) private var visibleSections
2021-11-02 03:26:18 +05:30
var body: some View {
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-02 03:26:18 +05:30
} else {
EmptyView()
2021-11-02 03:26:18 +05:30
}
}
}
}