mirror of
https://github.com/yattee/yattee.git
synced 2025-08-05 02:04:07 +00:00
Add Edit favorites
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct DropFavorite: DropDelegate {
|
||||
let item: FavoriteItem
|
||||
@Binding var favorites: [FavoriteItem]
|
||||
@Binding var current: FavoriteItem?
|
||||
|
||||
func dropEntered(info _: DropInfo) {
|
||||
guard item != current else {
|
||||
return
|
||||
}
|
||||
|
||||
guard let current else {
|
||||
return
|
||||
}
|
||||
|
||||
let from = favorites.firstIndex(of: current)
|
||||
let to = favorites.firstIndex(of: item)
|
||||
|
||||
guard let from, let to else {
|
||||
return
|
||||
}
|
||||
|
||||
guard favorites[to].id != current.id else {
|
||||
return
|
||||
}
|
||||
|
||||
favorites.move(
|
||||
fromOffsets: IndexSet(integer: from),
|
||||
toOffset: to > from ? to + 1 : to
|
||||
)
|
||||
}
|
||||
|
||||
func dropUpdated(info _: DropInfo) -> DropProposal? {
|
||||
DropProposal(operation: .move)
|
||||
}
|
||||
|
||||
func performDrop(info _: DropInfo) -> Bool {
|
||||
current = nil
|
||||
return true
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct DropFavoriteOutside: DropDelegate {
|
||||
@Binding var current: FavoriteItem?
|
||||
|
||||
func performDrop(info _: DropInfo) -> Bool {
|
||||
current = nil
|
||||
return true
|
||||
}
|
||||
}
|
@@ -56,16 +56,6 @@ struct FavoriteItemView: View {
|
||||
resource?.addObserver(store)
|
||||
resource?.loadIfNeeded()
|
||||
}
|
||||
#if !os(tvOS)
|
||||
.onDrag {
|
||||
dragging = item
|
||||
return NSItemProvider(object: item.id as NSString)
|
||||
}
|
||||
.onDrop(
|
||||
of: [UTType.text],
|
||||
delegate: DropFavorite(item: item, favorites: $favorites, current: $dragging)
|
||||
)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
.onChange(of: accounts.current) { _ in
|
||||
|
Reference in New Issue
Block a user