mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
fix crash when deleting a recent
make history ordered correctly
This commit is contained in:
@@ -51,6 +51,7 @@ class HostsManager: ObservableObject, @unchecked Sendable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func addToHistory(_ host: Host) {
|
func addToHistory(_ host: Host) {
|
||||||
|
history = [History(host: host, count: 1)] + history
|
||||||
history.append(History(host: host, count: 1))
|
history.append(History(host: host, count: 1))
|
||||||
formatHistory()
|
formatHistory()
|
||||||
saveHistory()
|
saveHistory()
|
||||||
|
|||||||
@@ -13,11 +13,12 @@ struct RecentsView: View {
|
|||||||
|
|
||||||
@State var historyCount: Int = 1
|
@State var historyCount: Int = 1
|
||||||
|
|
||||||
|
// @State var displayedHistory: [History] = []
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
if !hostsManager.history.isEmpty {
|
if !hostsManager.history.isEmpty {
|
||||||
Section("Recents") {
|
Section("Recents") {
|
||||||
ForEach(0..<historyCount, id: \.self) { index in
|
ForEach(hostsManager.history.reversed().prefix(historyCount)) { history in
|
||||||
let history = hostsManager.history[index]
|
|
||||||
NavigationLink() {
|
NavigationLink() {
|
||||||
ConnectionView(
|
ConnectionView(
|
||||||
handler: SSHHandler(
|
handler: SSHHandler(
|
||||||
@@ -47,7 +48,7 @@ struct RecentsView: View {
|
|||||||
.tint(.red)
|
.tint(.red)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if historyCount <= hostsManager.history.count {
|
// if historyCount <= hostsManager.history.count {
|
||||||
HStack(alignment: .center) {
|
HStack(alignment: .center) {
|
||||||
Button() {
|
Button() {
|
||||||
var increment = 2
|
var increment = 2
|
||||||
@@ -86,7 +87,7 @@ struct RecentsView: View {
|
|||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
.disabled(historyCount == 0)
|
.disabled(historyCount == 0)
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
.transition(.opacity)
|
.transition(.opacity)
|
||||||
|
|||||||
Reference in New Issue
Block a user