Skip to content

Commit 7130109

Browse files
committed
feat(search): switch to advanced search
1 parent ee0f839 commit 7130109

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

clients/web/src/common/api/queries/get-saved-items-search.js

+29-17
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,31 @@ import { actionToCamelCase } from 'common/utilities/strings/strings'
66

77
const searchSavedItemsQuery = gql`
88
query SearchSavedItems(
9-
$term: String!
109
$sort: SearchSortInput
1110
$pagination: PaginationInput
12-
$filter: SearchFilterInput
11+
$filter: AdvancedSearchFilters
12+
$queryString: String
1313
) {
1414
user {
15-
searchSavedItems(term: $term, sort: $sort, pagination: $pagination, filter: $filter) {
15+
advancedSearch(
16+
filter: $filter
17+
queryString: $queryString
18+
pagination: $pagination
19+
sort: $sort
20+
) {
21+
pageInfo {
22+
hasNextPage
23+
hasPreviousPage
24+
startCursor
25+
endCursor
26+
}
27+
totalCount
1628
edges {
1729
node {
30+
searchHighlights {
31+
fullText
32+
title
33+
}
1834
savedItem {
1935
url
2036
_createdAt
@@ -31,13 +47,13 @@ const searchSavedItemsQuery = gql`
3147
}
3248
item {
3349
... on Item {
50+
givenUrl
51+
itemId
3452
isArticle
3553
hasImage
3654
hasVideo
3755
timeToRead
3856
shareId: id
39-
itemId
40-
givenUrl
4157
preview {
4258
...ItemPreview
4359
}
@@ -46,13 +62,6 @@ const searchSavedItemsQuery = gql`
4662
}
4763
}
4864
}
49-
pageInfo {
50-
hasNextPage
51-
hasPreviousPage
52-
startCursor
53-
endCursor
54-
}
55-
totalCount
5665
}
5766
}
5867
}
@@ -71,15 +80,18 @@ export async function getSavedItemsSearch({
7180
actionType,
7281
sortOrder = 'DESC',
7382
pagination,
74-
searchTerm: term
83+
searchTerm: queryString
7584
}) {
7685
const requestDetails = itemFiltersFromGraph[actionType]
7786
if (!requestDetails) throw new MalformedItemSearchError()
7887

7988
const { filter, sort } = requestDetails
80-
const variables = { filter: { ...filter }, sort: { ...sort, sortOrder }, term, pagination }
81-
if (Object.keys(variables.filter).length == 0) {
82-
delete variables.filter
89+
90+
const variables = {
91+
...(filter && { filter }),
92+
sort: { ...sort, sortOrder },
93+
queryString,
94+
pagination
8395
}
8496
const operationName = actionToCamelCase(actionType)
8597

@@ -89,7 +101,7 @@ export async function getSavedItemsSearch({
89101
}
90102

91103
function handleResponse(response) {
92-
const responseData = response?.data?.user?.searchSavedItems
104+
const responseData = response?.data?.user?.advancedSearch
93105
const { pageInfo, edges, totalCount } = responseData
94106
return { pageInfo, edges, totalCount }
95107
}

0 commit comments

Comments
 (0)