mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-01-02 12:28:49 +00:00
90ec3d419c
* Check for haptic capabilities
* Make manager do most of work
* ABC enum
* Fix spelling 😊
* Small tweak
48 lines
1.1 KiB
Swift
48 lines
1.1 KiB
Swift
import Env
|
|
import Foundation
|
|
import Models
|
|
import SwiftUI
|
|
|
|
@MainActor
|
|
class PendingStatusesObserver: ObservableObject {
|
|
@Published var pendingStatusesCount: Int = 0
|
|
|
|
var disableUpdate: Bool = false
|
|
var scrollToIndex: ((Int) -> Void)?
|
|
|
|
var pendingStatuses: [String] = [] {
|
|
didSet {
|
|
pendingStatusesCount = pendingStatuses.count
|
|
}
|
|
}
|
|
|
|
func removeStatus(status: Status) {
|
|
if !disableUpdate, let index = pendingStatuses.firstIndex(of: status.id) {
|
|
pendingStatuses.removeSubrange(index ... (pendingStatuses.count - 1))
|
|
HapticManager.shared.fireHaptic(of: .timeline)
|
|
}
|
|
}
|
|
|
|
init() {}
|
|
}
|
|
|
|
struct PendingStatusesObserverView: View {
|
|
@ObservedObject var observer: PendingStatusesObserver
|
|
|
|
var body: some View {
|
|
if observer.pendingStatusesCount > 0 {
|
|
HStack(spacing: 6) {
|
|
Spacer()
|
|
Button {
|
|
observer.scrollToIndex?(observer.pendingStatusesCount)
|
|
} label: {
|
|
Text("\(observer.pendingStatusesCount)")
|
|
}
|
|
.buttonStyle(.bordered)
|
|
.background(.thinMaterial)
|
|
.cornerRadius(8)
|
|
}
|
|
.padding(12)
|
|
}
|
|
}
|
|
}
|