fix crash when deleting a recent

make history ordered correctly
This commit is contained in:
neon443
2025-08-18 15:36:15 +01:00
parent ca4a114c93
commit e8ad06b429
2 changed files with 6 additions and 4 deletions

View File

@@ -51,6 +51,7 @@ class HostsManager: ObservableObject, @unchecked Sendable {
}
func addToHistory(_ host: Host) {
history = [History(host: host, count: 1)] + history
history.append(History(host: host, count: 1))
formatHistory()
saveHistory()

View File

@@ -13,11 +13,12 @@ struct RecentsView: View {
@State var historyCount: Int = 1
// @State var displayedHistory: [History] = []
var body: some View {
if !hostsManager.history.isEmpty {
Section("Recents") {
ForEach(0..<historyCount, id: \.self) { index in
let history = hostsManager.history[index]
ForEach(hostsManager.history.reversed().prefix(historyCount)) { history in
NavigationLink() {
ConnectionView(
handler: SSHHandler(
@@ -47,7 +48,7 @@ struct RecentsView: View {
.tint(.red)
}
}
if historyCount <= hostsManager.history.count {
// if historyCount <= hostsManager.history.count {
HStack(alignment: .center) {
Button() {
var increment = 2
@@ -86,7 +87,7 @@ struct RecentsView: View {
.buttonStyle(.plain)
.disabled(historyCount == 0)
}
}
// }
}
.transition(.opacity)