mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
use typeahead search to handle searches on Android
This commit is contained in:
parent
20a88e78aa
commit
e994462b61
4 changed files with 63 additions and 2 deletions
|
|
@ -0,0 +1,15 @@
|
|||
query TypeaheadSearch($query: String!) {
|
||||
typeaheadSearch(query: $query) {
|
||||
... on TypeaheadSearchSuccess {
|
||||
items {
|
||||
id
|
||||
title
|
||||
slug
|
||||
siteName
|
||||
}
|
||||
}
|
||||
... on TypeaheadSearchError {
|
||||
errorCodes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package app.omnivore.omnivore.networking
|
||||
|
||||
import app.omnivore.omnivore.graphql.generated.SearchQuery
|
||||
import app.omnivore.omnivore.graphql.generated.TypeaheadSearchQuery
|
||||
import app.omnivore.omnivore.models.LinkedItem
|
||||
import com.apollographql.apollo3.api.Optional
|
||||
|
||||
|
|
@ -9,6 +10,46 @@ data class SearchQueryResponse(
|
|||
val items: List<LinkedItem>
|
||||
)
|
||||
|
||||
suspend fun Networker.typeaheadSearch(
|
||||
query: String
|
||||
): SearchQueryResponse {
|
||||
try {
|
||||
val result = authenticatedApolloClient().query(
|
||||
TypeaheadSearchQuery(query)
|
||||
).execute()
|
||||
|
||||
val itemList = result.data?.typeaheadSearch?.onTypeaheadSearchSuccess?.items ?: listOf()
|
||||
|
||||
val items = itemList.map {
|
||||
LinkedItem(
|
||||
id = it.id,
|
||||
title = it.title,
|
||||
createdAt = "",
|
||||
savedAt = "",
|
||||
readAt = "",
|
||||
updatedAt = "",
|
||||
readingProgress = 0.0,
|
||||
readingProgressAnchor = 0,
|
||||
imageURLString = null,
|
||||
pageURLString = "",
|
||||
descriptionText = "",
|
||||
publisherURLString = "",
|
||||
siteName = it.siteName,
|
||||
author = "",
|
||||
publishDate = null,
|
||||
slug = it.slug,
|
||||
isArchived = false,
|
||||
contentReader = null,
|
||||
content = null
|
||||
)
|
||||
}
|
||||
|
||||
return SearchQueryResponse(null, items)
|
||||
} catch (e: java.lang.Exception) {
|
||||
return SearchQueryResponse(null, listOf())
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun Networker.search(
|
||||
cursor: String? = null,
|
||||
limit: Int = 15,
|
||||
|
|
|
|||
|
|
@ -59,7 +59,12 @@ class HomeViewModel @Inject constructor(
|
|||
searchIdx += 1
|
||||
|
||||
// Execute the search
|
||||
val searchResult = networker.search(cursor = cursor, query = searchQuery())
|
||||
val searchResult =
|
||||
if (searchTextLiveData.value != "") {
|
||||
networker.typeaheadSearch(searchTextLiveData.value ?: "")
|
||||
} else {
|
||||
networker.search(cursor = cursor, query = searchQuery())
|
||||
}
|
||||
|
||||
// Search results aren't guaranteed to return in order so this
|
||||
// will discard old results that are returned while a user is typing.
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ fun LinkedItemCard(item: LinkedItem, onClickHandler: () -> Unit, actionHandler:
|
|||
lineHeight = 20.sp
|
||||
)
|
||||
|
||||
if (item.author != null) {
|
||||
if (item.author != null && item.author != "") {
|
||||
Text(
|
||||
text = "By ${item.author}",
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
|
|
|
|||
Loading…
Reference in a new issue