mirror of
https://github.com/yattee/yattee.git
synced 2025-10-14 11:28:13 +00:00
Managing Favorites sections
This commit is contained in:
25
Shared/Views/FavoriteButton.swift
Normal file
25
Shared/Views/FavoriteButton.swift
Normal file
@@ -0,0 +1,25 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user