Skip to content

Commit 8fba1b6

Browse files
committed
feat(future pocket): use item preview metadata
1 parent 9357917 commit 8fba1b6

File tree

2 files changed

+62
-14
lines changed

2 files changed

+62
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { gql } from '@common/utilities/pocket-request'
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/pocket/app/api/get-home-feed/index.ts

+10-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { gql, pocketRequest } from '@common/utilities/pocket-request'
22
import { getErrorMessage } from '@common/utilities/error-handler'
33
import { SUPPORTED_LOCALES } from '@common/localization'
4+
import { FRAGMENT_ITEM_PREVIEW } from '../_fragments/preview'
45

56
// Types
67
import type { CorpusSlate, CorpusRecommendation, CorpusSlateLineup } from '@common/types/pocket'
@@ -33,16 +34,8 @@ const getHomeQuery = gql`
3334
recommendations(count: 12) {
3435
id
3536
corpusItem {
36-
image {
37-
url
38-
}
39-
url
40-
title
41-
excerpt
42-
language
43-
publisher
44-
authors {
45-
name
37+
preview {
38+
...ItemPreview
4639
}
4740
}
4841
reason {
@@ -53,6 +46,8 @@ const getHomeQuery = gql`
5346
}
5447
}
5548
}
49+
50+
${FRAGMENT_ITEM_PREVIEW}
5651
`
5752

5853
/**
@@ -93,21 +88,22 @@ export async function getHomeSlates(locale: string): Promise<HomeQueryResponse |
9388
function getItemsFromSlate({ recommendations }: { recommendations: CorpusRecommendation[] }) {
9489
return recommendations.reduce((previous, current) => {
9590
const corpusItem = current?.corpusItem
91+
const preview = current?.corpusItem?.preview
9692
const topic = current?.reason?.name
9793
const corpusRecommendationId = current?.id
9894
if (!corpusItem) return previous
9995
return {
10096
...previous,
10197
[corpusRecommendationId]: {
102-
...corpusItem,
103-
externalUrl: corpusItem.url,
104-
saveUrl: corpusItem.url,
98+
...preview,
99+
externalUrl: preview.url,
100+
saveUrl: preview.url,
105101
id: corpusRecommendationId,
106102
itemId: corpusRecommendationId,
107103
topic,
108104
corpusRecommendationId,
109105
analyticsData: {
110-
url: corpusItem.url,
106+
url: preview.url,
111107
corpusRecommendationId
112108
}
113109
}

0 commit comments

Comments
 (0)