commit 5524d78a73f3d8ea317c739a24304f9cc480714b
parent b0f0420d9763ff6d21a41755e1b1ecd82ee08afe
Author: FIGBERT <figbert@figbert.com>
Date: Fri, 9 Sep 2022 12:56:29 -0700
Implement HistoryView functionality
The key and value types have been swapped to ensure unique URLs are
stored in history and to prevent duplicate entries over time.
Diffstat:
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/Shared/BrowserFunctions.swift b/Shared/BrowserFunctions.swift
@@ -13,7 +13,7 @@ import SwiftGemtext
class BrowserData: ObservableObject {
@Published var url: String = ""
- @Published var history: [Date: URL] = [:]
+ @Published var history: [URL: Date] = [:]
@Published var tabs: [UUID: SwiftGemini.GeminiResponse?] = [:]
@Published var currentTab: UUID? = nil // tabs.isEmpty => nil
@@ -45,7 +45,7 @@ extension BrowserData {
}
self.tabs[uuid] = response
self.currentTab = uuid
- self.history[Date.now] = url
+ self.history[url] = Date.now
self.currentView = .Capsule
self.url = url.absoluteString
}
diff --git a/Shared/HistoryView.swift b/Shared/HistoryView.swift
@@ -12,11 +12,15 @@ struct HistoryView: View {
var body: some View {
List {
- ForEach(data.history.sorted(by: { first, second in first.key > second.key }), id: \.key) { date, url in
+ ForEach(data.history.sorted(by: { first, second in first.value > second.value }), id: \.value) { url, date in
HStack {
- Text(url.absoluteString)
+ Link(destination: url) { Text(url.absoluteString) }
Spacer()
- Text(date.formatted(date: .long, time: .shortened))
+ if date.timeIntervalSince(.now) <= -1*60*60*24 {
+ Text(date.formatted(date: .long, time: .complete))
+ } else {
+ Text(date.formatted(date: .omitted, time: .complete))
+ }
}
}
}