From d7f498c1642f9af18818920c68b04f5155f44657 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Fri, 15 Aug 2025 19:54:25 +0100 Subject: [PATCH] added collapsible recents added last connect date added more and collapse button added a thingy that says how many are displayed and the total updated funcs --- ShhShell/Host/History.swift | 1 + ShhShell/Host/HostsManager.swift | 4 +- ShhShell/Views/Hosts/RecentsView.swift | 47 +++++++++++++++++++-- ShhShell/Views/Misc/HostSymbolPreview.swift | 14 +++--- 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/ShhShell/Host/History.swift b/ShhShell/Host/History.swift index bcc1091..53354b8 100644 --- a/ShhShell/Host/History.swift +++ b/ShhShell/Host/History.swift @@ -12,4 +12,5 @@ struct History: Identifiable, Codable { var host: Host var count: Int + var lastConnect: Date = .now } diff --git a/ShhShell/Host/HostsManager.swift b/ShhShell/Host/HostsManager.swift index 0a67ce3..0e25ef7 100644 --- a/ShhShell/Host/HostsManager.swift +++ b/ShhShell/Host/HostsManager.swift @@ -47,6 +47,7 @@ class HostsManager: ObservableObject, @unchecked Sendable { func addToHistory(_ host: Host) { history.append(History(host: host, count: 1)) formatHistory() + saveHistory() } func formatHistory() { @@ -55,6 +56,7 @@ class HostsManager: ObservableObject, @unchecked Sendable { if result.last?.host == item.host { guard var lastOne = result.popLast() else { continue } lastOne.count += 1 + lastOne.lastConnect = .now result.append(lastOne) } else { result.append(History(host: item.host, count: 1)) @@ -68,7 +70,7 @@ class HostsManager: ObservableObject, @unchecked Sendable { userDefaults.set(data, forKey: "history") } - func removeFromHistory(_ toRemove: Host) { + func removeFromHistory(_ toRemove: History) { history.removeAll(where: { $0.id == toRemove.id }) saveHistory() } diff --git a/ShhShell/Views/Hosts/RecentsView.swift b/ShhShell/Views/Hosts/RecentsView.swift index 46e42f3..e2b3469 100644 --- a/ShhShell/Views/Hosts/RecentsView.swift +++ b/ShhShell/Views/Hosts/RecentsView.swift @@ -11,10 +11,13 @@ struct RecentsView: View { @ObservedObject var hostsManager: HostsManager @ObservedObject var keyManager: KeyManager + @State var historyCount: Int = 1 + var body: some View { if !hostsManager.history.isEmpty { Section("Recents") { - ForEach(hostsManager.history) { history in + ForEach(0..