Add settings for selecting visible sections (fixes #16)

This commit is contained in:
Arkadiusz Fal
2021-12-01 12:22:19 +01:00
parent ff83abd103
commit e61d1dfe2e
11 changed files with 265 additions and 129 deletions

View File

@@ -1,3 +1,4 @@
import Defaults
import Foundation
import SwiftUI
@@ -7,19 +8,27 @@ struct FavoriteButton: View {
@State private var isFavorite = false
@Default(.visibleSections) private var visibleSections
var body: some View {
Button {
favorites.toggle(item)
isFavorite.toggle()
} label: {
if isFavorite {
Label("Remove from Favorites", systemImage: "heart.fill")
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)
}
} else {
Label("Add to Favorites", systemImage: "heart")
EmptyView()
}
}
.onAppear {
isFavorite = favorites.contains(item)
}
}
}