@adminide-stack/yantra-mobile 12.0.102-alpha.2 → 12.0.103-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,234 @@
1
+ import {jsxs,jsx}from'react/jsx-runtime';import {memo}from'react';import {Pressable,StyleSheet,View,Text,Platform}from'react-native';import {Image}from'expo-image';import {CommonActions}from'@react-navigation/native';import {mobileColors}from'../../theme/mobileTokens.js';import {getStoryId,formatPublishedAt,getSourceCountLabel}from'./articleContent.js';var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ const DISCOVER_SERIF = Platform.select({
21
+ ios: "Georgia",
22
+ android: "serif",
23
+ default: void 0
24
+ });
25
+ function discoverPalette(isDark) {
26
+ const color = mobileColors(isDark);
27
+ return __spreadProps(__spreadValues({}, color), {
28
+ card: isDark ? color.surface : "#ffffff",
29
+ cardBorder: isDark ? color.border : "#eceae6",
30
+ imagePlaceholder: isDark ? "#334155" : "#f1f5f9",
31
+ dot: isDark ? "rgba(148,163,184,0.45)" : "rgba(100,116,139,0.28)"
32
+ });
33
+ }
34
+ function openDiscoverArticle(navigation, story, orgName) {
35
+ var _a;
36
+ (_a = navigation == null ? void 0 : navigation.dispatch) == null ? void 0 : _a.call(navigation, CommonActions.navigate({
37
+ name: "MainStack.DiscoverArticle",
38
+ params: {
39
+ orgName: orgName != null ? orgName : void 0,
40
+ slug: getStoryId(story)
41
+ }
42
+ }));
43
+ }
44
+ function TagChip({
45
+ label,
46
+ palette
47
+ }) {
48
+ if (!label) return null;
49
+ return /* @__PURE__ */ jsx(View, { style: [styles.tag, {
50
+ backgroundColor: palette.primarySoft,
51
+ borderColor: palette.primaryBorder
52
+ }], children: /* @__PURE__ */ jsx(Text, { style: [styles.tagLabel, {
53
+ color: palette.primary
54
+ }], numberOfLines: 1, children: label }) });
55
+ }
56
+ function SourceDots({
57
+ count,
58
+ palette
59
+ }) {
60
+ const dots = Math.min(Math.max(count, 0), 3);
61
+ if (dots === 0) return null;
62
+ return /* @__PURE__ */ jsx(View, { style: styles.dots, children: Array.from({
63
+ length: dots
64
+ }).map((_, index) => /* @__PURE__ */ jsx(View, { style: [styles.dot, {
65
+ backgroundColor: palette.dot,
66
+ borderColor: palette.card
67
+ }, index > 0 && styles.dotOverlap] }, index)) });
68
+ }
69
+ function StoryMetaRow({
70
+ story,
71
+ palette
72
+ }) {
73
+ const published = formatPublishedAt(story.publishedAt);
74
+ return /* @__PURE__ */ jsxs(View, { style: styles.metaRow, children: [
75
+ /* @__PURE__ */ jsx(TagChip, { label: story.tag || story.topic, palette }),
76
+ /* @__PURE__ */ jsxs(View, { style: styles.sources, children: [
77
+ /* @__PURE__ */ jsx(SourceDots, { count: story.sourceCount, palette }),
78
+ /* @__PURE__ */ jsx(Text, { style: [styles.metaText, {
79
+ color: palette.textMuted
80
+ }], children: getSourceCountLabel(story.sourceCount) })
81
+ ] }),
82
+ published ? /* @__PURE__ */ jsx(Text, { style: [styles.metaText, {
83
+ color: palette.textMuted
84
+ }], numberOfLines: 1, children: published.replace(/^Published /, "") }) : null
85
+ ] });
86
+ }
87
+ const LeadStoryCard = memo(function LeadStoryCard2({
88
+ story,
89
+ palette,
90
+ onPress
91
+ }) {
92
+ return /* @__PURE__ */ jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: story.title, onPress: () => onPress(story), style: ({
93
+ pressed
94
+ }) => [styles.card, {
95
+ backgroundColor: palette.card,
96
+ borderColor: palette.cardBorder
97
+ }, pressed && styles.pressed], children: [
98
+ /* @__PURE__ */ jsx(View, { style: [styles.leadImage, {
99
+ backgroundColor: palette.imagePlaceholder
100
+ }], children: story.imageUrl ? /* @__PURE__ */ jsx(Image, { source: {
101
+ uri: story.imageUrl
102
+ }, style: StyleSheet.absoluteFill, contentFit: "cover", transition: 150, accessibilityIgnoresInvertColors: true }) : null }),
103
+ /* @__PURE__ */ jsxs(View, { style: styles.leadBody, children: [
104
+ /* @__PURE__ */ jsx(Text, { style: [styles.leadTitle, {
105
+ color: palette.text
106
+ }], numberOfLines: 4, children: story.title }),
107
+ story.summary ? /* @__PURE__ */ jsx(Text, { style: [styles.leadSummary, {
108
+ color: palette.textMuted
109
+ }], numberOfLines: 3, children: story.summary }) : null,
110
+ /* @__PURE__ */ jsx(View, { style: [styles.leadFooter, {
111
+ borderTopColor: palette.cardBorder
112
+ }], children: /* @__PURE__ */ jsx(StoryMetaRow, { story, palette }) })
113
+ ] })
114
+ ] });
115
+ });
116
+ const CompactStoryCard = memo(function CompactStoryCard2({
117
+ story,
118
+ palette,
119
+ onPress
120
+ }) {
121
+ return /* @__PURE__ */ jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: story.title, onPress: () => onPress(story), style: ({
122
+ pressed
123
+ }) => [styles.card, styles.compactCard, {
124
+ backgroundColor: palette.card,
125
+ borderColor: palette.cardBorder
126
+ }, pressed && styles.pressed], children: [
127
+ /* @__PURE__ */ jsxs(View, { style: styles.compactText, children: [
128
+ /* @__PURE__ */ jsx(Text, { style: [styles.compactTitle, {
129
+ color: palette.text
130
+ }], numberOfLines: 3, children: story.title }),
131
+ /* @__PURE__ */ jsx(StoryMetaRow, { story, palette })
132
+ ] }),
133
+ /* @__PURE__ */ jsx(View, { style: [styles.thumb, {
134
+ backgroundColor: palette.imagePlaceholder
135
+ }], children: story.imageUrl ? /* @__PURE__ */ jsx(Image, { source: {
136
+ uri: story.imageUrl
137
+ }, style: StyleSheet.absoluteFill, contentFit: "cover", transition: 150, accessibilityIgnoresInvertColors: true }) : null })
138
+ ] });
139
+ });
140
+ const styles = StyleSheet.create({
141
+ card: {
142
+ borderRadius: 18,
143
+ borderWidth: StyleSheet.hairlineWidth,
144
+ overflow: "hidden"
145
+ },
146
+ pressed: {
147
+ opacity: 0.85
148
+ },
149
+ leadImage: {
150
+ width: "100%",
151
+ aspectRatio: 16 / 9
152
+ },
153
+ leadBody: {
154
+ padding: 16,
155
+ gap: 10
156
+ },
157
+ leadTitle: {
158
+ fontFamily: DISCOVER_SERIF,
159
+ fontSize: 22,
160
+ lineHeight: 28,
161
+ fontWeight: "700",
162
+ letterSpacing: -0.3
163
+ },
164
+ leadSummary: {
165
+ fontSize: 15,
166
+ lineHeight: 22
167
+ },
168
+ leadFooter: {
169
+ marginTop: 2,
170
+ paddingTop: 12,
171
+ borderTopWidth: StyleSheet.hairlineWidth
172
+ },
173
+ compactCard: {
174
+ flexDirection: "row",
175
+ padding: 14,
176
+ gap: 12
177
+ },
178
+ compactText: {
179
+ flex: 1,
180
+ minWidth: 0,
181
+ gap: 10,
182
+ justifyContent: "space-between"
183
+ },
184
+ compactTitle: {
185
+ fontFamily: DISCOVER_SERIF,
186
+ fontSize: 17,
187
+ lineHeight: 23,
188
+ fontWeight: "700"
189
+ },
190
+ thumb: {
191
+ width: 92,
192
+ height: 92,
193
+ borderRadius: 12,
194
+ overflow: "hidden"
195
+ },
196
+ metaRow: {
197
+ flexDirection: "row",
198
+ flexWrap: "wrap",
199
+ alignItems: "center",
200
+ gap: 8
201
+ },
202
+ tag: {
203
+ borderRadius: 999,
204
+ borderWidth: StyleSheet.hairlineWidth,
205
+ paddingHorizontal: 9,
206
+ paddingVertical: 3,
207
+ maxWidth: 160
208
+ },
209
+ tagLabel: {
210
+ fontSize: 12,
211
+ fontWeight: "600"
212
+ },
213
+ sources: {
214
+ flexDirection: "row",
215
+ alignItems: "center",
216
+ gap: 5
217
+ },
218
+ dots: {
219
+ flexDirection: "row",
220
+ alignItems: "center"
221
+ },
222
+ dot: {
223
+ width: 13,
224
+ height: 13,
225
+ borderRadius: 7,
226
+ borderWidth: 1.5
227
+ },
228
+ dotOverlap: {
229
+ marginLeft: -5
230
+ },
231
+ metaText: {
232
+ fontSize: 12
233
+ }
234
+ });export{CompactStoryCard,DISCOVER_SERIF,LeadStoryCard,StoryMetaRow,TagChip,discoverPalette,openDiscoverArticle};//# sourceMappingURL=DiscoverStoryCards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DiscoverStoryCards.js","sources":["../../../src/features/discover/DiscoverStoryCards.tsx"],"sourcesContent":["/**\n * Story cards for the native Discover feed — the phone-width take on the\n * browser's `DiscoverNewsPage` lead / compact cards.\n */\nimport React, { memo } from 'react';\nimport { Platform, Pressable, StyleSheet, Text, View } from 'react-native';\nimport { Image } from 'expo-image';\nimport { CommonActions, type NavigationProp, type ParamListBase } from '@react-navigation/native';\nimport type { IAccountNewsArticle } from 'common';\nimport { mobileColors } from '../../theme/mobileTokens';\nimport { formatPublishedAt, getSourceCountLabel, getStoryId } from './articleContent';\n\n/** The browser sets headlines in a serif; these are the closest system faces. */\nexport const DISCOVER_SERIF = Platform.select({ ios: 'Georgia', android: 'serif', default: undefined });\n\nexport type DiscoverPalette = ReturnType<typeof discoverPalette>;\n\nexport function discoverPalette(isDark: boolean) {\n const color = mobileColors(isDark);\n return {\n ...color,\n card: isDark ? color.surface : '#ffffff',\n cardBorder: isDark ? color.border : '#eceae6',\n imagePlaceholder: isDark ? '#334155' : '#f1f5f9',\n dot: isDark ? 'rgba(148,163,184,0.45)' : 'rgba(100,116,139,0.28)',\n };\n}\n\n/** Opens the native reader. The route is registered as `discover-article` in `compute.ts`. */\nexport function openDiscoverArticle(\n navigation: Pick<NavigationProp<ParamListBase>, 'dispatch'> | null | undefined,\n story: Pick<IAccountNewsArticle, 'slug' | 'id'>,\n orgName?: string | null,\n): void {\n navigation?.dispatch?.(\n CommonActions.navigate({\n name: 'MainStack.DiscoverArticle',\n params: { orgName: orgName ?? undefined, slug: getStoryId(story) },\n }),\n );\n}\n\nexport function TagChip({ label, palette }: { label: string; palette: DiscoverPalette }) {\n if (!label) return null;\n return (\n <View style={[styles.tag, { backgroundColor: palette.primarySoft, borderColor: palette.primaryBorder }]}>\n <Text style={[styles.tagLabel, { color: palette.primary }]} numberOfLines={1}>\n {label}\n </Text>\n </View>\n );\n}\n\nfunction SourceDots({ count, palette }: { count: number; palette: DiscoverPalette }) {\n const dots = Math.min(Math.max(count, 0), 3);\n if (dots === 0) return null;\n return (\n <View style={styles.dots}>\n {Array.from({ length: dots }).map((_, index) => (\n <View\n key={index}\n style={[\n styles.dot,\n { backgroundColor: palette.dot, borderColor: palette.card },\n index > 0 && styles.dotOverlap,\n ]}\n />\n ))}\n </View>\n );\n}\n\nexport function StoryMetaRow({ story, palette }: { story: IAccountNewsArticle; palette: DiscoverPalette }) {\n const published = formatPublishedAt(story.publishedAt);\n return (\n <View style={styles.metaRow}>\n <TagChip label={story.tag || story.topic} palette={palette} />\n <View style={styles.sources}>\n <SourceDots count={story.sourceCount} palette={palette} />\n <Text style={[styles.metaText, { color: palette.textMuted }]}>\n {getSourceCountLabel(story.sourceCount)}\n </Text>\n </View>\n {published ? (\n <Text style={[styles.metaText, { color: palette.textMuted }]} numberOfLines={1}>\n {published.replace(/^Published /, '')}\n </Text>\n ) : null}\n </View>\n );\n}\n\n/** Full-width card: 16:9 picture over the headline and summary. Opens every five-story block. */\nexport const LeadStoryCard = memo(function LeadStoryCard({\n story,\n palette,\n onPress,\n}: {\n story: IAccountNewsArticle;\n palette: DiscoverPalette;\n onPress: (story: IAccountNewsArticle) => void;\n}) {\n return (\n <Pressable\n accessibilityRole=\"button\"\n accessibilityLabel={story.title}\n onPress={() => onPress(story)}\n style={({ pressed }) => [\n styles.card,\n { backgroundColor: palette.card, borderColor: palette.cardBorder },\n pressed && styles.pressed,\n ]}\n >\n <View style={[styles.leadImage, { backgroundColor: palette.imagePlaceholder }]}>\n {story.imageUrl ? (\n <Image\n source={{ uri: story.imageUrl }}\n style={StyleSheet.absoluteFill}\n contentFit=\"cover\"\n transition={150}\n accessibilityIgnoresInvertColors\n />\n ) : null}\n </View>\n <View style={styles.leadBody}>\n <Text style={[styles.leadTitle, { color: palette.text }]} numberOfLines={4}>\n {story.title}\n </Text>\n {story.summary ? (\n <Text style={[styles.leadSummary, { color: palette.textMuted }]} numberOfLines={3}>\n {story.summary}\n </Text>\n ) : null}\n <View style={[styles.leadFooter, { borderTopColor: palette.cardBorder }]}>\n <StoryMetaRow story={story} palette={palette} />\n </View>\n </View>\n </Pressable>\n );\n});\n\n/** Headline beside a square thumbnail, for the rest of each block. */\nexport const CompactStoryCard = memo(function CompactStoryCard({\n story,\n palette,\n onPress,\n}: {\n story: IAccountNewsArticle;\n palette: DiscoverPalette;\n onPress: (story: IAccountNewsArticle) => void;\n}) {\n return (\n <Pressable\n accessibilityRole=\"button\"\n accessibilityLabel={story.title}\n onPress={() => onPress(story)}\n style={({ pressed }) => [\n styles.card,\n styles.compactCard,\n { backgroundColor: palette.card, borderColor: palette.cardBorder },\n pressed && styles.pressed,\n ]}\n >\n <View style={styles.compactText}>\n <Text style={[styles.compactTitle, { color: palette.text }]} numberOfLines={3}>\n {story.title}\n </Text>\n <StoryMetaRow story={story} palette={palette} />\n </View>\n <View style={[styles.thumb, { backgroundColor: palette.imagePlaceholder }]}>\n {story.imageUrl ? (\n <Image\n source={{ uri: story.imageUrl }}\n style={StyleSheet.absoluteFill}\n contentFit=\"cover\"\n transition={150}\n accessibilityIgnoresInvertColors\n />\n ) : null}\n </View>\n </Pressable>\n );\n});\n\nconst styles = StyleSheet.create({\n card: {\n borderRadius: 18,\n borderWidth: StyleSheet.hairlineWidth,\n overflow: 'hidden',\n },\n pressed: {\n opacity: 0.85,\n },\n leadImage: {\n width: '100%',\n aspectRatio: 16 / 9,\n },\n leadBody: {\n padding: 16,\n gap: 10,\n },\n leadTitle: {\n fontFamily: DISCOVER_SERIF,\n fontSize: 22,\n lineHeight: 28,\n fontWeight: '700',\n letterSpacing: -0.3,\n },\n leadSummary: {\n fontSize: 15,\n lineHeight: 22,\n },\n leadFooter: {\n marginTop: 2,\n paddingTop: 12,\n borderTopWidth: StyleSheet.hairlineWidth,\n },\n compactCard: {\n flexDirection: 'row',\n padding: 14,\n gap: 12,\n },\n compactText: {\n flex: 1,\n minWidth: 0,\n gap: 10,\n justifyContent: 'space-between',\n },\n compactTitle: {\n fontFamily: DISCOVER_SERIF,\n fontSize: 17,\n lineHeight: 23,\n fontWeight: '700',\n },\n thumb: {\n width: 92,\n height: 92,\n borderRadius: 12,\n overflow: 'hidden',\n },\n metaRow: {\n flexDirection: 'row',\n flexWrap: 'wrap',\n alignItems: 'center',\n gap: 8,\n },\n tag: {\n borderRadius: 999,\n borderWidth: StyleSheet.hairlineWidth,\n paddingHorizontal: 9,\n paddingVertical: 3,\n maxWidth: 160,\n },\n tagLabel: {\n fontSize: 12,\n fontWeight: '600',\n },\n sources: {\n flexDirection: 'row',\n alignItems: 'center',\n gap: 5,\n },\n dots: {\n flexDirection: 'row',\n alignItems: 'center',\n },\n dot: {\n width: 13,\n height: 13,\n borderRadius: 7,\n borderWidth: 1.5,\n },\n dotOverlap: {\n marginLeft: -5,\n },\n metaText: {\n fontSize: 12,\n },\n});\n"],"names":["LeadStoryCard","CompactStoryCard"],"mappings":";;;;;;;;;;;;;;;;;;;AAaa,MAAA,cAAA,GAAiB,SAAS,MAAO,CAAA;AAAA,EAC5C,GAAK,EAAA,SAAA;AAAA,EACL,OAAS,EAAA,OAAA;AAAA,EACT,OAAS,EAAA;AACX,CAAC;AAEM,SAAS,gBAAgB,MA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GAAK,EAAA;AAAA,IACH,YAAc,EAAA,GAAA;AAAA,IACd,aAAa,UAAW,CAAA,aAAA;AAAA,IACxB,iBAAmB,EAAA,CAAA;AAAA,IACnB,eAAiB,EAAA,CAAA;AAAA,IACjB,QAAU,EAAA;AAAA,GACZ;AAAA,EACA,QAAU,EAAA;AAAA,IACR,QAAU,EAAA,EAAA;AAAA,IACV,UAAY,EAAA;AAAA,GACd;AAAA,EACA,OAAS,EAAA;AAAA,IACP,aAAe,EAAA,KAAA;AAAA,IACf,UAAY,EAAA,QAAA;AAAA,IACZ,GAAK,EAAA;AAAA,GACP;AAAA,EACA,IAAM,EAAA;AAAA,IACJ,aAAe,EAAA,KAAA;AAAA,IACf,UAAY,EAAA;AAAA,GACd;AAAA,EACA,GAAK,EAAA;AAAA,IACH,KAAO,EAAA,EAAA;AAAA,IACP,MAAQ,EAAA,EAAA;AAAA,IACR,YAAc,EAAA,CAAA;AAAA,IACd,WAAa,EAAA;AAAA,GACf;AAAA,EACA,UAAY,EAAA;AAAA,IACV,UAAY,EAAA;AAAA,GACd;AAAA,EACA,QAAU,EAAA;AAAA,IACR,QAAU,EAAA;AAAA;AAEd,CAAC,CAAA"}
@@ -0,0 +1,184 @@
1
+ const MINUTE_MS = 6e4;
2
+ const HOUR_MS = 60 * MINUTE_MS;
3
+ const DAY_MS = 24 * HOUR_MS;
4
+ const WEEK_MS = 7 * DAY_MS;
5
+ const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
6
+ function formatPublishedAt(publishedAt, now = Date.now()) {
7
+ if (!publishedAt) return null;
8
+ const published = new Date(publishedAt);
9
+ if (Number.isNaN(published.getTime())) return null;
10
+ const diff = now - published.getTime();
11
+ if (diff < MINUTE_MS) return "Published just now";
12
+ if (diff < HOUR_MS) {
13
+ const mins = Math.floor(diff / MINUTE_MS);
14
+ return `Published ${mins} ${mins === 1 ? "minute" : "minutes"} ago`;
15
+ }
16
+ if (diff < DAY_MS) {
17
+ const hours = Math.floor(diff / HOUR_MS);
18
+ return `Published ${hours} ${hours === 1 ? "hour" : "hours"} ago`;
19
+ }
20
+ if (diff < WEEK_MS) {
21
+ const days = Math.floor(diff / DAY_MS);
22
+ return `Published ${days} ${days === 1 ? "day" : "days"} ago`;
23
+ }
24
+ return `Published ${MONTHS[published.getMonth()]} ${published.getDate()}, ${published.getFullYear()}`;
25
+ }
26
+ function getStoryId(story) {
27
+ return story.slug || story.id;
28
+ }
29
+ function getSourceCountLabel(sourceCount) {
30
+ return sourceCount === 1 ? "1 source" : `${sourceCount} sources`;
31
+ }
32
+ const JUNK_LINE_PATTERNS = [
33
+ /^published$/i,
34
+ /^discover more$/i,
35
+ /^read (more|full (story|article))$/i,
36
+ /^show more$/i,
37
+ /^back$/i,
38
+ /^\d+\s+sources?$/i,
39
+ /^(a|an|\d+)\s+(second|minute|hour|day|week|month|year)s?\s+ago$/i,
40
+ /^just now$/i,
41
+ // Scraped page chrome (Perplexity composer / cookie banner / gallery labels).
42
+ /^ask follow-?ups?$/i,
43
+ /^search( computer)?$/i,
44
+ /^computer$/i,
45
+ /^model$/i,
46
+ /^images:?$/i,
47
+ /^(decline optional|got it|accept all|decline)\b.*$/i,
48
+ /^cookie policy$/i,
49
+ /^related( (stories|articles|news|topics))?$/i,
50
+ // Scraped app-shell nav rail captured above the headline ("Projects / No projects / Sessions").
51
+ /^(projects|no projects|sessions|no sessions|spaces|library|threads|new thread|sign in|log in)$/i,
52
+ // A bare source domain on its own line, e.g. "npr.org" or "english.ahram.org".
53
+ /^[a-z0-9-]+(\.[a-z0-9-]+)*\.[a-z]{2,}$/i
54
+ ];
55
+ const TAIL_JUNK_MARKERS = [/^[ \t>*_-]*#{0,6}\s*cookie policy\s*$/im, /^\s*we and our partners use cookies/im, /^[ \t>*_-]*#{0,6}\s*(discover|explore|see)\s+more\s*$/im, /^[ \t>*_-]*#{0,6}\s*related\s*(stories|articles|news|topics)?\s*$/im, /^[ \t>*_-]*#{0,6}\s*more\s+(news|stories|articles)\s*$/im, /^\s*ask follow-?up\s*$/im, /^\s*decline optional\b/im, /^\s*images:\s*$/im];
56
+ const LEADING_CHROME_SCAN_LINES = 40;
57
+ function imageKey(url) {
58
+ return url.split(/[?#]/)[0].replace(/\/+$/, "").toLowerCase();
59
+ }
60
+ function truncateLeadingChrome(content, title) {
61
+ const normalizedTitle = title.trim().toLowerCase();
62
+ if (!normalizedTitle) {
63
+ return content;
64
+ }
65
+ const lines = content.split("\n");
66
+ const headlineIndex = lines.slice(0, LEADING_CHROME_SCAN_LINES).findIndex((line) => line.trim().replace(/^#{1,6}\s*/, "").replace(/^\*\*(.*)\*\*$/, "$1").trim().toLowerCase() === normalizedTitle);
67
+ return headlineIndex > 0 ? lines.slice(headlineIndex).join("\n") : content;
68
+ }
69
+ function truncateTailJunk(content) {
70
+ let cut = content.length;
71
+ for (const marker of TAIL_JUNK_MARKERS) {
72
+ const match = marker.exec(content);
73
+ if (match && match.index < cut) {
74
+ cut = match.index;
75
+ }
76
+ }
77
+ return content.slice(0, cut);
78
+ }
79
+ const LINK_OR_IMAGE_PATTERN = /(!?)\[([^\]\n]*)\]\((https?:\/\/[^)\s]+)\)/g;
80
+ const TRAILING_LINK_OR_IMAGE_PATTERN = /\s*(!?)\[[^\]\n]*\]\(https?:\/\/[^)\s]+\)\s*$/;
81
+ function replaceLinks(line, replacer) {
82
+ return line.replace(LINK_OR_IMAGE_PATTERN, (match, bang, label) => bang ? match : replacer(label));
83
+ }
84
+ function countLinks(line) {
85
+ let count = 0;
86
+ replaceLinks(line, () => {
87
+ count += 1;
88
+ return "";
89
+ });
90
+ return count;
91
+ }
92
+ function cleanLinksInLine(line) {
93
+ const links = countLinks(line);
94
+ if (links === 0) {
95
+ return line;
96
+ }
97
+ if (links >= 2) {
98
+ return null;
99
+ }
100
+ const withoutLinks = replaceLinks(line, () => "").replace(/[\s|·•–—,-]+/g, " ").trim();
101
+ if (withoutLinks.length < 3) {
102
+ return null;
103
+ }
104
+ const withoutTrailing = line.replace(TRAILING_LINK_OR_IMAGE_PATTERN, (match, bang) => bang ? match : "");
105
+ return replaceLinks(withoutTrailing, (label) => label).trimEnd();
106
+ }
107
+ function stripRedundantMedia(content, heroUrl) {
108
+ let out = content;
109
+ out = out.replace(/!\[\s*image\s+\d+:[^\]\n]*\]\([^)\n]*\)/gi, "");
110
+ const heroKey = heroUrl ? imageKey(heroUrl) : void 0;
111
+ const seenImages = /* @__PURE__ */ new Set();
112
+ out = out.replace(/!\[[^\]\n]*\]\((https?:\/\/[^\s)]+)\)/g, (match, url) => {
113
+ const key = imageKey(url);
114
+ if (heroKey && key === heroKey || seenImages.has(key)) {
115
+ return "";
116
+ }
117
+ seenImages.add(key);
118
+ return match;
119
+ });
120
+ out = out.replace(/^([ \t]*)[-*+][ \t]+(!\[[^\]\n]*\]\([^)\n]*\))[ \t]*$/gm, "$2").replace(/^[ \t]*[-*+][ \t]*$/gm, "");
121
+ return out;
122
+ }
123
+ function cleanArticleContent(content, title, summary, heroUrl) {
124
+ const normalizedTitle = title.trim().toLowerCase();
125
+ const normalizedSummary = summary == null ? void 0 : summary.trim().toLowerCase();
126
+ const cleaned = stripRedundantMedia(truncateTailJunk(truncateLeadingChrome(content, title)), heroUrl).split("\n").map((rawLine) => rawLine.replace(/(\S)\+\d+\b/g, "$1")).reduce((lines, rawLine) => {
127
+ const trimmed = rawLine.trim();
128
+ if (!trimmed) {
129
+ lines.push(rawLine);
130
+ return lines;
131
+ }
132
+ const normalizedLine = trimmed.replace(/^#{1,6}\s*/, "").replace(/^\*\*(.*)\*\*$/, "$1").trim().toLowerCase();
133
+ if (normalizedLine === normalizedTitle || normalizedSummary && normalizedLine === normalizedSummary) {
134
+ return lines;
135
+ }
136
+ if (JUNK_LINE_PATTERNS.some((pattern) => pattern.test(trimmed))) {
137
+ return lines;
138
+ }
139
+ const linkCleaned = cleanLinksInLine(rawLine);
140
+ if (linkCleaned === null || !linkCleaned.trim()) {
141
+ return lines;
142
+ }
143
+ lines.push(linkCleaned);
144
+ return lines;
145
+ }, []).join("\n");
146
+ return cleaned.replace(/\n{3,}/g, "\n\n").trim();
147
+ }
148
+ function toHostname(value) {
149
+ const match = /^https?:\/\/([^/?#:]+)/i.exec(value.trim());
150
+ if (match) {
151
+ return match[1].toLowerCase().replace(/^www\./, "");
152
+ }
153
+ const candidate = value.trim().toLowerCase();
154
+ if (/^[a-z0-9.-]+\.[a-z]{2,}$/.test(candidate)) {
155
+ return candidate.replace(/^www\./, "");
156
+ }
157
+ return void 0;
158
+ }
159
+ function normalizeSources(items, sources) {
160
+ if (items && items.length > 0) {
161
+ return items.map((item) => {
162
+ var _a, _b, _c, _d;
163
+ const host = (_b = toHostname((_a = item.url) != null ? _a : "")) != null ? _b : toHostname(item.name);
164
+ const name = toHostname(item.name) === item.name.trim().toLowerCase() ? host != null ? host : item.name : item.name;
165
+ return {
166
+ name: name || host || "Source",
167
+ host,
168
+ url: (_c = item.url) != null ? _c : void 0,
169
+ title: (_d = item.title) != null ? _d : void 0
170
+ };
171
+ });
172
+ }
173
+ return (sources != null ? sources : []).map((raw) => {
174
+ const host = toHostname(raw);
175
+ return {
176
+ name: host != null ? host : raw,
177
+ host,
178
+ url: /^https?:\/\//i.test(raw) ? raw : void 0
179
+ };
180
+ });
181
+ }
182
+ function faviconUrl(host) {
183
+ return `https://www.google.com/s2/favicons?domain=${encodeURIComponent(host)}&sz=64`;
184
+ }export{cleanArticleContent,faviconUrl,formatPublishedAt,getSourceCountLabel,getStoryId,normalizeSources};//# sourceMappingURL=articleContent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"articleContent.js","sources":["../../../src/features/discover/articleContent.ts"],"sourcesContent":["/**\n * Pure helpers behind the native Discover reader, ported from the browser's\n * `pages/discover/components/DiscoverArticlePage.tsx` and\n * `pages/discover/utils/formatPublishedAt.ts`. Keep the two in step: the same\n * scraped article must read the same on web and in the app.\n *\n * The browser regexes lean on lookbehind (`(?<!!)`, `(?<=\\S)`); these are\n * rewritten without it so they do not depend on the JS engine's regex support.\n */\nimport type { IAccountNewsArticle, IAccountNewsArticleSource } from 'common';\n\n/** A source normalized for display, whether it came from `sourceItems` or a plain string. */\nexport interface NormalizedSource {\n name: string;\n host?: string;\n url?: string;\n title?: string;\n}\n\nconst MINUTE_MS = 60_000;\nconst HOUR_MS = 60 * MINUTE_MS;\nconst DAY_MS = 24 * HOUR_MS;\nconst WEEK_MS = 7 * DAY_MS;\n\nconst MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];\n\n/** Human-readable relative label for a publishedAt ISO string, e.g. \"Published 2 hours ago\". */\nexport function formatPublishedAt(publishedAt: string | null | undefined, now: number = Date.now()): string | null {\n if (!publishedAt) return null;\n\n const published = new Date(publishedAt);\n\n if (Number.isNaN(published.getTime())) return null;\n\n const diff = now - published.getTime();\n\n if (diff < MINUTE_MS) return 'Published just now';\n if (diff < HOUR_MS) {\n const mins = Math.floor(diff / MINUTE_MS);\n return `Published ${mins} ${mins === 1 ? 'minute' : 'minutes'} ago`;\n }\n if (diff < DAY_MS) {\n const hours = Math.floor(diff / HOUR_MS);\n return `Published ${hours} ${hours === 1 ? 'hour' : 'hours'} ago`;\n }\n if (diff < WEEK_MS) {\n const days = Math.floor(diff / DAY_MS);\n return `Published ${days} ${days === 1 ? 'day' : 'days'} ago`;\n }\n\n return `Published ${MONTHS[published.getMonth()]} ${published.getDate()}, ${published.getFullYear()}`;\n}\n\nexport function getStoryId(story: Pick<IAccountNewsArticle, 'slug' | 'id'>): string {\n return story.slug || story.id;\n}\n\nexport function getSourceCountLabel(sourceCount: number): string {\n return sourceCount === 1 ? '1 source' : `${sourceCount} sources`;\n}\n\n/** Standalone lines that scraped content leaves behind but add no value in the reader. */\nconst JUNK_LINE_PATTERNS: RegExp[] = [\n /^published$/i,\n /^discover more$/i,\n /^read (more|full (story|article))$/i,\n /^show more$/i,\n /^back$/i,\n /^\\d+\\s+sources?$/i,\n /^(a|an|\\d+)\\s+(second|minute|hour|day|week|month|year)s?\\s+ago$/i,\n /^just now$/i,\n // Scraped page chrome (Perplexity composer / cookie banner / gallery labels).\n /^ask follow-?ups?$/i,\n /^search( computer)?$/i,\n /^computer$/i,\n /^model$/i,\n /^images:?$/i,\n /^(decline optional|got it|accept all|decline)\\b.*$/i,\n /^cookie policy$/i,\n /^related( (stories|articles|news|topics))?$/i,\n // Scraped app-shell nav rail captured above the headline (\"Projects / No projects / Sessions\").\n /^(projects|no projects|sessions|no sessions|spaces|library|threads|new thread|sign in|log in)$/i,\n // A bare source domain on its own line, e.g. \"npr.org\" or \"english.ahram.org\".\n /^[a-z0-9-]+(\\.[a-z0-9-]+)*\\.[a-z]{2,}$/i,\n];\n\n/** Markers where the scraped page's trailing chrome / \"Discover more\" / cookie junk begins. */\nconst TAIL_JUNK_MARKERS: RegExp[] = [\n /^[ \\t>*_-]*#{0,6}\\s*cookie policy\\s*$/im,\n /^\\s*we and our partners use cookies/im,\n /^[ \\t>*_-]*#{0,6}\\s*(discover|explore|see)\\s+more\\s*$/im,\n /^[ \\t>*_-]*#{0,6}\\s*related\\s*(stories|articles|news|topics)?\\s*$/im,\n /^[ \\t>*_-]*#{0,6}\\s*more\\s+(news|stories|articles)\\s*$/im,\n /^\\s*ask follow-?up\\s*$/im,\n /^\\s*decline optional\\b/im,\n /^\\s*images:\\s*$/im,\n];\n\n/** How far into the body to look for the headline. Chrome sits above it; prose does not. */\nconst LEADING_CHROME_SCAN_LINES = 40;\n\n/** Normalizes an image URL (drop query/hash/trailing slash) so duplicates compare equal. */\nfunction imageKey(url: string): string {\n return url.split(/[?#]/)[0].replace(/\\/+$/, '').toLowerCase();\n}\n\n/**\n * Cuts the scraped page's LEADING chrome — the nav rail captured above the headline. Anchors\n * on the first line (within the first `LEADING_CHROME_SCAN_LINES`) that repeats the title.\n */\nfunction truncateLeadingChrome(content: string, title: string): string {\n const normalizedTitle = title.trim().toLowerCase();\n\n if (!normalizedTitle) {\n return content;\n }\n\n const lines = content.split('\\n');\n const headlineIndex = lines.slice(0, LEADING_CHROME_SCAN_LINES).findIndex(\n (line) =>\n line\n .trim()\n .replace(/^#{1,6}\\s*/, '')\n .replace(/^\\*\\*(.*)\\*\\*$/, '$1')\n .trim()\n .toLowerCase() === normalizedTitle,\n );\n\n return headlineIndex > 0 ? lines.slice(headlineIndex).join('\\n') : content;\n}\n\n/** Cuts everything from the earliest trailing-junk marker onward. */\nfunction truncateTailJunk(content: string): string {\n let cut = content.length;\n for (const marker of TAIL_JUNK_MARKERS) {\n const match = marker.exec(content);\n if (match && match.index < cut) {\n cut = match.index;\n }\n }\n return content.slice(0, cut);\n}\n\n/**\n * `[label](http…)` with an optional leading `!`. An image match (`!` captured) is passed\n * through untouched by `replaceLinks` — the lookbehind-free form of `(?<!!)\\[…\\]\\(…\\)`.\n */\nconst LINK_OR_IMAGE_PATTERN = /(!?)\\[([^\\]\\n]*)\\]\\((https?:\\/\\/[^)\\s]+)\\)/g;\nconst TRAILING_LINK_OR_IMAGE_PATTERN = /\\s*(!?)\\[[^\\]\\n]*\\]\\(https?:\\/\\/[^)\\s]+\\)\\s*$/;\n\n/** Rewrites every non-image markdown link on `line`; images are left as they are. */\nfunction replaceLinks(line: string, replacer: (label: string) => string): string {\n return line.replace(LINK_OR_IMAGE_PATTERN, (match, bang: string, label: string) =>\n bang ? match : replacer(label),\n );\n}\n\nfunction countLinks(line: string): number {\n let count = 0;\n replaceLinks(line, () => {\n count += 1;\n return '';\n });\n return count;\n}\n\n/**\n * Cleans links on a single line. Returns null when the line is a citation block or a scraped\n * \"related article\" snippet (two-plus links, or a lone link with no prose); otherwise strips a\n * trailing citation link and unwraps any inline link to its label so real prose survives.\n */\nfunction cleanLinksInLine(line: string): string | null {\n const links = countLinks(line);\n\n if (links === 0) {\n return line;\n }\n\n // Two-plus links on one line → a citation block / \"related\" snippet list.\n if (links >= 2) {\n return null;\n }\n\n // A single link that is essentially the whole line → a bare citation / related snippet.\n const withoutLinks = replaceLinks(line, () => '')\n .replace(/[\\s|·•–—,-]+/g, ' ')\n .trim();\n if (withoutLinks.length < 3) {\n return null;\n }\n\n // One inline link inside real prose → drop it if trailing, else keep its label text.\n const withoutTrailing = line.replace(TRAILING_LINK_OR_IMAGE_PATTERN, (match, bang: string) => (bang ? match : ''));\n return replaceLinks(withoutTrailing, (label) => label).trimEnd();\n}\n\n/**\n * Strips media already shown elsewhere on the page (the hero and repeated images), the scraped\n * \"Image N:\" gallery/related thumbnails, and the source-logo bullets citations leave behind.\n */\nfunction stripRedundantMedia(content: string, heroUrl?: string): string {\n let out = content;\n\n out = out.replace(/!\\[\\s*image\\s+\\d+:[^\\]\\n]*\\]\\([^)\\n]*\\)/gi, '');\n\n const heroKey = heroUrl ? imageKey(heroUrl) : undefined;\n const seenImages = new Set<string>();\n out = out.replace(/!\\[[^\\]\\n]*\\]\\((https?:\\/\\/[^\\s)]+)\\)/g, (match, url: string) => {\n const key = imageKey(url);\n if ((heroKey && key === heroKey) || seenImages.has(key)) {\n return '';\n }\n seenImages.add(key);\n return match;\n });\n\n // A list item that is now just an image (or empty) shouldn't render as a bullet.\n out = out\n .replace(/^([ \\t]*)[-*+][ \\t]+(!\\[[^\\]\\n]*\\]\\([^)\\n]*\\))[ \\t]*$/gm, '$2')\n .replace(/^[ \\t]*[-*+][ \\t]*$/gm, '');\n\n return out;\n}\n\n/**\n * Removes the artifacts scraped article content carries: page chrome above the headline and\n * after the body, repeats of the title/summary, standalone junk lines, \"+N\" markers,\n * citation-link blocks, and media already shown elsewhere on the page.\n */\nexport function cleanArticleContent(content: string, title: string, summary?: string, heroUrl?: string): string {\n const normalizedTitle = title.trim().toLowerCase();\n const normalizedSummary = summary?.trim().toLowerCase();\n\n // Leading cut runs FIRST: `truncateTailJunk` cuts at the earliest marker anywhere, so a nav\n // rail containing \"Discover more\" / \"Related\" would otherwise truncate the whole article.\n const cleaned = stripRedundantMedia(truncateTailJunk(truncateLeadingChrome(content, title)), heroUrl)\n .split('\\n')\n .map((rawLine) => rawLine.replace(/(\\S)\\+\\d+\\b/g, '$1'))\n .reduce<string[]>((lines, rawLine) => {\n const trimmed = rawLine.trim();\n\n if (!trimmed) {\n lines.push(rawLine);\n return lines;\n }\n\n const normalizedLine = trimmed\n .replace(/^#{1,6}\\s*/, '')\n .replace(/^\\*\\*(.*)\\*\\*$/, '$1')\n .trim()\n .toLowerCase();\n\n // The title and summary are already rendered in the header — drop repeats.\n if (normalizedLine === normalizedTitle || (normalizedSummary && normalizedLine === normalizedSummary)) {\n return lines;\n }\n\n if (JUNK_LINE_PATTERNS.some((pattern) => pattern.test(trimmed))) {\n return lines;\n }\n\n const linkCleaned = cleanLinksInLine(rawLine);\n if (linkCleaned === null || !linkCleaned.trim()) {\n return lines;\n }\n\n lines.push(linkCleaned);\n return lines;\n }, [])\n .join('\\n');\n\n return cleaned.replace(/\\n{3,}/g, '\\n\\n').trim();\n}\n\nfunction toHostname(value: string): string | undefined {\n const match = /^https?:\\/\\/([^/?#:]+)/i.exec(value.trim());\n if (match) {\n return match[1].toLowerCase().replace(/^www\\./, '');\n }\n\n const candidate = value.trim().toLowerCase();\n if (/^[a-z0-9.-]+\\.[a-z]{2,}$/.test(candidate)) {\n return candidate.replace(/^www\\./, '');\n }\n\n return undefined;\n}\n\n/**\n * Builds the source list for the cards row: prefers the structured `sourceItems`\n * ({name, url, title}) and falls back to the plain `sources` strings when it's empty.\n */\nexport function normalizeSources(\n items: ReadonlyArray<IAccountNewsArticleSource> | null | undefined,\n sources: ReadonlyArray<string> | null | undefined,\n): NormalizedSource[] {\n if (items && items.length > 0) {\n return items.map((item) => {\n const host = toHostname(item.url ?? '') ?? toHostname(item.name);\n const name = toHostname(item.name) === item.name.trim().toLowerCase() ? (host ?? item.name) : item.name;\n return {\n name: name || host || 'Source',\n host,\n url: item.url ?? undefined,\n title: item.title ?? undefined,\n };\n });\n }\n\n return (sources ?? []).map((raw) => {\n const host = toHostname(raw);\n return {\n name: host ?? raw,\n host,\n url: /^https?:\\/\\//i.test(raw) ? raw : undefined,\n };\n });\n}\n\nexport function faviconUrl(host: string): string {\n return `https://www.google.com/s2/favicons?domain=${encodeURIComponent(host)}&sz=64`;\n}\n"],"names":[],"mappings":"AAkBA,MAAM,SAAY,GAAA,GAAA;AAClB,MAAM,UAAU,EAAK,GAAA,SAAA;AACrB,MAAM,SAAS,EAAK,GAAA,OAAA;AACpB,MAAM,UAAU,CAAI,GAAA,MAAA;AACpB,MAAM,MAAS,GAAA,CAAC,KAAO,EAAA,KAAA,EAAO,KAAO,EAAA,KAAA,EAAO,KAAO,EAAA,KAAA,EAAO,KAAO,EAAA,KAAA,EAAO,KAAO,EAAA,KAAA,EAAO,OAAO,KAAK,CAAA;AAG3F,SAAS,iBAAkB,CAAA,WAAA,EAAwC,GAAc,GAAA,IAAA,CAAK,KAAsB,EAAA;AACjH,EAAI,IAAA,CAAC,aAAoB,OAAA,IAAA;AACzB,EAAM,MAAA,SAAA,GAAY,IAAI,IAAA,CAAK,WAAW,CAAA;AACtC,EAAA,IAAI,OAAO,KAAM,CAAA,SAAA,CAAU,OAAQ,EAAC,GAAU,OAAA,IAAA;AAC9C,EAAM,MAAA,IAAA,GAAO,GAAM,GAAA,SAAA,CAAU,OAAQ,EAAA;AACrC,EAAI,IAAA,IAAA,GAAO,WAAkB,OAAA,oBAAA;AAC7B,EAAA,IAAI,OAAO,OAAS,EAAA;AAClB,IAAA,MAAM,IAAO,GAAA,IAAA,CAAK,KAAM,CAAA,IAAA,GAAO,SAAS,CAAA;AACxC,IAAA,OAAO,aAAa,IAAI,CAAA,CAAA,EAAI,IAAS,KAAA,CAAA,GAAI,WAAW,SAAS,CAAA,IAAA,CAAA;AAAA;AAE/D,EAAA,IAAI,OAAO,MAAQ,EAAA;AACjB,IAAA,MAAM,KAAQ,GAAA,IAAA,CAAK,KAAM,CAAA,IAAA,GAAO,OAAO,CAAA;AACvC,IAAA,OAAO,aAAa,KAAK,CAAA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AAO,OAAA;AAAA,MACL,MAAM,IAAQ,IAAA,IAAA,GAAA,IAAA,GAAA,GAAA;AAAA,MACd,IAAA;AAAA,MACA,GAAK,EAAA,eAAA,CAAgB,IAAK,CAAA,GAAG,IAAI,GAAM,GAAA;AAAA,KACzC;AAAA,GACD,CAAA;AACH;AACO,SAAS,WAAW,IAAsB,EAAA;AAC/C,EAAO,OAAA,CAAA,0CAAA,EAA6C,kBAAmB,CAAA,IAAI,CAAC,CAAA,MAAA,CAAA;AAC9E"}
@@ -0,0 +1,97 @@
1
+ import {useMemo,useState,useCallback}from'react';import {useGetAccountNewsArticlesQuery,useGetAccountNewsArticleBySlugQuery}from'common/graphql';const DISCOVER_PAGE_SIZE = 10;
2
+ const DISCOVER_TOPICS = [{
3
+ key: "top",
4
+ label: "Top"
5
+ }, {
6
+ key: "sports",
7
+ label: "Sports"
8
+ }, {
9
+ key: "finance",
10
+ label: "Business"
11
+ }, {
12
+ key: "entertainment",
13
+ label: "Entertainment"
14
+ }, {
15
+ key: "tech",
16
+ label: "Tech & Science"
17
+ }, {
18
+ key: "arts",
19
+ label: "Arts & Culture"
20
+ }];
21
+ function useNewsArticlesInfinite(options) {
22
+ var _a, _b, _c, _d, _e;
23
+ const pageSize = (_a = options.pageSize) != null ? _a : DISCOVER_PAGE_SIZE;
24
+ const filter = useMemo(() => ({
25
+ topic: options.topic,
26
+ limit: pageSize,
27
+ skip: 0
28
+ }), [options.topic, pageSize]);
29
+ const {
30
+ data,
31
+ loading,
32
+ error,
33
+ fetchMore,
34
+ refetch
35
+ } = useGetAccountNewsArticlesQuery({
36
+ variables: {
37
+ filter
38
+ },
39
+ skip: options.skipQuery,
40
+ fetchPolicy: "cache-and-network",
41
+ notifyOnNetworkStatusChange: true
42
+ });
43
+ const [loadingMore, setLoadingMore] = useState(false);
44
+ const articles = (_c = (_b = data == null ? void 0 : data.getAccountNewsArticles) == null ? void 0 : _b.data) != null ? _c : [];
45
+ const totalCount = (_e = (_d = data == null ? void 0 : data.getAccountNewsArticles) == null ? void 0 : _d.totalCount) != null ? _e : 0;
46
+ const hasMore = articles.length < totalCount;
47
+ const loadMore = useCallback(async () => {
48
+ if (loadingMore || !hasMore) {
49
+ return;
50
+ }
51
+ setLoadingMore(true);
52
+ try {
53
+ await fetchMore({
54
+ variables: {
55
+ filter: {
56
+ topic: options.topic,
57
+ limit: pageSize,
58
+ skip: articles.length
59
+ }
60
+ }
61
+ });
62
+ } finally {
63
+ setLoadingMore(false);
64
+ }
65
+ }, [fetchMore, hasMore, loadingMore, options.topic, pageSize, articles.length]);
66
+ return {
67
+ articles,
68
+ totalCount,
69
+ loading,
70
+ loadingMore,
71
+ hasMore,
72
+ error,
73
+ loadMore,
74
+ refetch
75
+ };
76
+ }
77
+ function useNewsArticle(options) {
78
+ var _a, _b;
79
+ const {
80
+ data,
81
+ loading,
82
+ error,
83
+ refetch
84
+ } = useGetAccountNewsArticleBySlugQuery({
85
+ variables: {
86
+ slug: (_a = options.slug) != null ? _a : ""
87
+ },
88
+ skip: !options.slug,
89
+ fetchPolicy: "cache-and-network"
90
+ });
91
+ return {
92
+ article: (_b = data == null ? void 0 : data.getAccountNewsArticleBySlug) != null ? _b : null,
93
+ loading,
94
+ error,
95
+ refetch
96
+ };
97
+ }export{DISCOVER_PAGE_SIZE,DISCOVER_TOPICS,useNewsArticle,useNewsArticlesInfinite};//# sourceMappingURL=useDiscoverNews.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDiscoverNews.js","sources":["../../../src/features/discover/useDiscoverNews.ts"],"sourcesContent":["/**\n * Discover news data, mirroring the browser's `hooks/useNewsApi.ts`: the same\n * `getAccountNewsArticles` / `getAccountNewsArticleBySlug` queries, so web and\n * app read one feed. Pages merge by `skip` via `mergeNewsArticlesList` in\n * `graphql/typePolicies.ts` (keyed on topic only).\n */\nimport { useCallback, useMemo, useState } from 'react';\nimport { useGetAccountNewsArticleBySlugQuery, useGetAccountNewsArticlesQuery } from 'common/graphql';\nimport type { IAccountNewsArticlesFilterInput } from 'common';\n\nexport const DISCOVER_PAGE_SIZE = 10;\n\nexport interface DiscoverTopic {\n /** Server-side topic key. */\n key: string;\n label: string;\n}\n\n/** Same tabs, order and labels as the browser Discover header (\"For You\" is off there too). */\nexport const DISCOVER_TOPICS: DiscoverTopic[] = [\n { key: 'top', label: 'Top' },\n { key: 'sports', label: 'Sports' },\n { key: 'finance', label: 'Business' },\n { key: 'entertainment', label: 'Entertainment' },\n { key: 'tech', label: 'Tech & Science' },\n { key: 'arts', label: 'Arts & Culture' },\n];\n\nexport function useNewsArticlesInfinite(options: { topic: string; pageSize?: number; skipQuery?: boolean }) {\n const pageSize = options.pageSize ?? DISCOVER_PAGE_SIZE;\n\n const filter = useMemo<IAccountNewsArticlesFilterInput>(\n () => ({ topic: options.topic, limit: pageSize, skip: 0 }),\n [options.topic, pageSize],\n );\n\n const { data, loading, error, fetchMore, refetch } = useGetAccountNewsArticlesQuery({\n variables: { filter },\n skip: options.skipQuery,\n fetchPolicy: 'cache-and-network',\n notifyOnNetworkStatusChange: true,\n });\n\n const [loadingMore, setLoadingMore] = useState(false);\n\n const articles = data?.getAccountNewsArticles?.data ?? [];\n const totalCount = data?.getAccountNewsArticles?.totalCount ?? 0;\n const hasMore = articles.length < totalCount;\n\n const loadMore = useCallback(async () => {\n if (loadingMore || !hasMore) {\n return;\n }\n\n setLoadingMore(true);\n\n try {\n await fetchMore({\n variables: {\n filter: { topic: options.topic, limit: pageSize, skip: articles.length },\n },\n });\n } finally {\n setLoadingMore(false);\n }\n }, [fetchMore, hasMore, loadingMore, options.topic, pageSize, articles.length]);\n\n return { articles, totalCount, loading, loadingMore, hasMore, error, loadMore, refetch };\n}\n\nexport function useNewsArticle(options: { slug?: string | null }) {\n const { data, loading, error, refetch } = useGetAccountNewsArticleBySlugQuery({\n variables: { slug: options.slug ?? '' },\n skip: !options.slug,\n fetchPolicy: 'cache-and-network',\n });\n\n return {\n article: data?.getAccountNewsArticleBySlug ?? null,\n loading,\n error,\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