Skip to content

Commit daf98c6

Browse files
committed
fix(search): switch to item preview
1 parent 5ae59ab commit daf98c6

File tree

3 files changed

+64
-39
lines changed

3 files changed

+64
-39
lines changed

clients/web/src/common/api/derivers/item.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ export function deriveListItem(edge) {
9999

100100
export function deriveSearchItem(edge) {
101101
const { node = {}, cursor = null } = edge
102-
const { preview, searchHighlights } = node
102+
const { item, searchHighlights } = node
103+
const preview = item?.preview
103104
return deriveItem({ item: { ...preview, searchHighlights }, cursor, utmId: 'pocket_search' })
104105
}
105106

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { gql } from 'common/utilities/gql/gql'
2+
3+
export const FRAGMENT_ITEM_PREVIEW = gql`
4+
fragment ItemPreview on PocketMetadata {
5+
... on ItemSummary {
6+
id
7+
image {
8+
caption
9+
credit
10+
url
11+
cachedImages(imageOptions: [{ id: "WebPImage", fileType: WEBP, width: 640 }]) {
12+
url
13+
id
14+
}
15+
}
16+
excerpt
17+
title
18+
authors {
19+
name
20+
}
21+
domain {
22+
name
23+
}
24+
datePublished
25+
url
26+
}
27+
... on OEmbed {
28+
id
29+
image {
30+
caption
31+
credit
32+
url
33+
cachedImages(imageOptions: [{ id: "WebPImage", fileType: WEBP, width: 640 }]) {
34+
url
35+
id
36+
}
37+
}
38+
excerpt
39+
title
40+
authors {
41+
name
42+
}
43+
domain {
44+
name
45+
}
46+
datePublished
47+
url
48+
htmlEmbed
49+
type
50+
}
51+
}
52+
`

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

+10-38
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { gql } from 'common/utilities/gql/gql'
22
import { requestGQL } from 'common/utilities/request/request'
33
import { deriveSearchItem } from 'common/api/derivers/item'
4+
import { FRAGMENT_ITEM_PREVIEW } from 'common/api/fragments/fragment.preview'
45

56
const getSearchQuery = gql`
67
query CorpusSearchQuery(
@@ -14,54 +15,25 @@ const getSearchQuery = gql`
1415
endCursor
1516
}
1617
edges {
18+
cursor
1719
node {
18-
preview {
19-
... on ItemSummary {
20-
id
21-
image {
22-
url
23-
}
24-
excerpt
25-
title
26-
authors {
27-
name
28-
}
29-
domain {
30-
name
31-
}
32-
datePublished
33-
url
34-
}
35-
... on OEmbed {
36-
id
37-
image {
38-
url
39-
}
40-
excerpt
41-
title
42-
authors {
43-
name
44-
}
45-
domain {
46-
name
47-
}
48-
datePublished
49-
url
50-
htmlEmbed
51-
type
52-
}
53-
}
5420
searchHighlights {
5521
excerpt
22+
fullText
5623
publisher
5724
title
5825
}
26+
item {
27+
preview {
28+
...ItemPreview
29+
}
30+
}
5931
}
60-
cursor
6132
}
6233
totalCount
6334
}
6435
}
36+
${FRAGMENT_ITEM_PREVIEW}
6537
`
6638

6739
/**
@@ -93,7 +65,7 @@ function handleResponse(response) {
9365

9466
function getItemsByIdFromEdges(edges) {
9567
return edges.reduce((previous, current) => {
96-
if (!current?.node?.preview?.id) return previous
68+
if (!current?.node?.item?.preview?.id) return previous
9769

9870
const item = deriveSearchItem(current)
9971
const searchHighlights = current?.node?.searchHighlights

0 commit comments

Comments
 (0)