Skip to content

feat: Add Full-Text Search (FTS) setup and search functionality #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor: improve structure and readability of SearchScreen
- Refactored the layout of the `SearchScreen` to enhance readability.
- Maintained existing functionality while reorganizing the code for better clarity.
- Ensured proper handling of search text changes and loading states.
  • Loading branch information
morristech committed Apr 10, 2025
commit 6e6606831c1771d0836b28af1ed9028af85ede23
60 changes: 29 additions & 31 deletions Demo/PowerSyncExample/Screens/SearchScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,38 @@ struct SearchScreen: View {
@State private var searchTask: Task<Void, Never>? = nil

var body: some View {
NavigationView {
List {
if isLoading {
HStack {
Spacer()
ProgressView()
Spacer()
}
} else if let error = searchError {
Text("Error: \(error)")
} else if searchText.isEmpty {
ContentUnavailableView("Search Lists & Todos", systemImage: "magnifyingglass")
} else if searchResults.isEmpty && !searchText.isEmpty {
ContentUnavailableView.search(text: searchText)
} else {
ForEach(searchResults) { item in
SearchResultRow(item: item)
}
List {
if isLoading {
HStack {
Spacer()
ProgressView()
Spacer()
}
}
.navigationTitle("Search")
.searchable(text: $searchText,
placement: .toolbar,
prompt: "Search Lists & Todos")
.onChange(of: searchText) { _, newValue in
triggerSearch(term: newValue)
}
.onChange(of: searchText) { _, newValue in
if newValue.isEmpty && !isLoading {
searchResults = []
searchError = nil
} else if let error = searchError {
Text("Error: \(error)")
} else if searchText.isEmpty {
ContentUnavailableView("Search Lists & Todos", systemImage: "magnifyingglass")
} else if searchResults.isEmpty && !searchText.isEmpty {
ContentUnavailableView.search(text: searchText)
} else {
ForEach(searchResults) { item in
SearchResultRow(item: item)
}
}
}.navigationViewStyle(.stack)
}
.navigationTitle("Search")
.searchable(text: $searchText,
placement: .toolbar,
prompt: "Search Lists & Todos")
.onChange(of: searchText) { _, newValue in
triggerSearch(term: newValue)
}
.onChange(of: searchText) { _, newValue in
if newValue.isEmpty && !isLoading {
searchResults = []
searchError = nil
}
}
}

private func triggerSearch(term: String) {
Expand Down