Skip to content

Commit

Permalink
Changes to suggestions for adding a removal button
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasstrba committed Oct 18, 2024
1 parent 4b5e53f commit f6bbe43
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
15 changes: 15 additions & 0 deletions Sources/History/HistoryCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public protocol HistoryCoordinating: AnyObject {
func burnDomains(_ baseDomains: Set<String>, tld: TLD, completion: @escaping (Set<URL>) -> Void)
func burnVisits(_ visits: [Visit], completion: @escaping () -> Void)

func removeUrlEntry(_ url: URL, completion: ((Error?) -> Void)?)
}

/// Coordinates access to History. Uses its own queue with high qos for all operations.
Expand Down Expand Up @@ -191,6 +192,20 @@ final public class HistoryCoordinator: HistoryCoordinating {
}
}

public enum EntryRemovalError: Error {
case notAvailable
}

public func removeUrlEntry(_ url: URL, completion: ((Error?) -> Void)? = nil) {
guard let historyDictionary = historyDictionary else { return }
guard let entry = historyDictionary[url] else {
completion?(EntryRemovalError.notAvailable)
return
}

removeEntries([entry], completionHandler: completion)
}

var cleaningDate: Date { .monthAgo }

@objc private func cleanOld() {
Expand Down
12 changes: 9 additions & 3 deletions Sources/Suggestions/Suggestion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public enum Suggestion: Equatable {
case openTab(title: String, url: URL)
case unknown(value: String)

var url: URL? {
public var url: URL? {
switch self {
case .website(url: let url),
.historyEntry(title: _, url: let url, allowedInTopHits: _),
Expand Down Expand Up @@ -67,20 +67,26 @@ public enum Suggestion: Equatable {
}
}

var isOpenTab: Bool {
public var isOpenTab: Bool {
if case .openTab = self {
return true
}
return false
}

var isBookmark: Bool {
public var isBookmark: Bool {
if case .bookmark = self {
return true
}
return false
}

public var isHistoryEntry: Bool {
if case .historyEntry = self {
return true
}
return false
}
}

extension Suggestion {
Expand Down
6 changes: 3 additions & 3 deletions Sources/Suggestions/SuggestionResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public struct SuggestionResult: Equatable {
SuggestionResult(topHits: [], duckduckgoSuggestions: [], localSuggestions: [])
}

private(set) public var topHits: [Suggestion]
private(set) public var duckduckgoSuggestions: [Suggestion]
private(set) public var localSuggestions: [Suggestion]
public var topHits: [Suggestion]
public var duckduckgoSuggestions: [Suggestion]
public var localSuggestions: [Suggestion]

public init(topHits: [Suggestion],
duckduckgoSuggestions: [Suggestion],
Expand Down

0 comments on commit f6bbe43

Please sign in to comment.