All checks were successful
CI / build-and-deploy (push) Successful in 24s
Expose Marks to Siri, Spotlight, and Shortcuts via App Intents: - BookmarkEntity (AppEntity + IndexedEntity, keyed on the Linkding server id) with a server-backed EntityStringQuery for live lookup - Intents: Add, Open (OpenIntent), Search, ShowUnread, and an AI Summarize intent backed by ClaudeService; AppShortcutsProvider with spoken phrases; Siri snippet views and dialog - SearchMarksIntent conforms to the system.search App Schema (@AppIntent(schema:), ShowInAppSearchResultsIntent) so it is executable by conversational Siri / Apple Intelligence - IntentRouter bridges intents (run in the app process) to the SwiftUI scene for open/search navigation; widgets refreshed after adds - Link AppIntents.framework so the metadata processor extracts shortcut phrases and validates the assistant schema Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
101 lines
3.8 KiB
Swift
101 lines
3.8 KiB
Swift
import SwiftUI
|
|
|
|
struct SearchView: View {
|
|
@Bindable var viewModel: BookmarksViewModel
|
|
|
|
@State private var searchText = ""
|
|
@State private var useSemanticSearch = false
|
|
@State private var semanticResults: [Bookmark]? = nil
|
|
@State private var searchTask: Task<Void, Never>?
|
|
@State private var browsingBookmark: Bookmark?
|
|
|
|
var body: some View {
|
|
NavigationStack {
|
|
List {
|
|
ForEach(results) { bookmark in
|
|
BookmarkListRow(
|
|
bookmark: bookmark,
|
|
viewModel: viewModel,
|
|
onOpen: { browsingBookmark = bookmark }
|
|
)
|
|
}
|
|
}
|
|
.listStyle(.plain)
|
|
.navigationTitle("Search")
|
|
.toolbar {
|
|
ToolbarItem(placement: .topBarTrailing) {
|
|
Toggle(isOn: $useSemanticSearch) {
|
|
Label("Semantic", systemImage: "sparkles")
|
|
}
|
|
.toggleStyle(.button)
|
|
.onChange(of: useSemanticSearch) { _, _ in scheduleSearch() }
|
|
}
|
|
}
|
|
.overlay {
|
|
if searchText.isEmpty {
|
|
ContentUnavailableView("Search Bookmarks", systemImage: "magnifyingglass", description: Text("Search by title, URL, or tag."))
|
|
} else if results.isEmpty && !viewModel.isLoading {
|
|
ContentUnavailableView.search(text: searchText)
|
|
}
|
|
if viewModel.isLoading {
|
|
ProgressView()
|
|
}
|
|
}
|
|
.sensoryFeedback(.selection, trigger: browsingBookmark?.id)
|
|
.sheet(item: $browsingBookmark) { bookmark in
|
|
if let url = URL(string: bookmark.url) {
|
|
BrowserView(
|
|
url: url,
|
|
title: bookmark.displayTitle,
|
|
claude: viewModel.claude,
|
|
podcastPlayer: viewModel.podcastPlayer
|
|
) {
|
|
await viewModel.archive(bookmark)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.searchable(text: $searchText, prompt: "Titles, URLs, tags…")
|
|
.onChange(of: searchText) { _, _ in scheduleSearch() }
|
|
.onAppear { consumeIntentSearch() }
|
|
.onChange(of: IntentRouter.shared.searchRequest) { _, _ in consumeIntentSearch() }
|
|
}
|
|
|
|
/// Pulls a query handed over by `SearchMarksIntent` into the search field.
|
|
private func consumeIntentSearch() {
|
|
guard let query = IntentRouter.shared.searchRequest else { return }
|
|
searchText = query
|
|
IntentRouter.shared.searchRequest = nil
|
|
}
|
|
|
|
private var results: [Bookmark] {
|
|
if let semantic = semanticResults { return semantic }
|
|
guard !searchText.isEmpty else { return [] }
|
|
let q = searchText.lowercased()
|
|
return viewModel.bookmarks.filter { b in
|
|
b.displayTitle.lowercased().contains(q) ||
|
|
b.url.lowercased().contains(q) ||
|
|
b.tagNames.contains { $0.lowercased().contains(q) } ||
|
|
(b.aiTags ?? []).contains { $0.lowercased().contains(q) } ||
|
|
(b.aiSummary ?? "").lowercased().contains(q)
|
|
}
|
|
}
|
|
|
|
private func scheduleSearch() {
|
|
semanticResults = nil
|
|
searchTask?.cancel()
|
|
guard !searchText.isEmpty, useSemanticSearch else { return }
|
|
let claude = viewModel.claude
|
|
searchTask = Task {
|
|
try? await Task.sleep(for: .milliseconds(500))
|
|
guard !Task.isCancelled else { return }
|
|
let q = searchText
|
|
let all = viewModel.bookmarks
|
|
do {
|
|
let ranked = try await claude.semanticSearch(query: q, in: all)
|
|
await MainActor.run { semanticResults = ranked }
|
|
} catch {}
|
|
}
|
|
}
|
|
}
|