Skip to content

Commit ec275bb

Browse files
StoryItem: unify linkless story row under single Link and DRY comment icon
For stories without a web URL, the entire row is now a single Link targeting the comments tab with one peek preview instead of two. The comment icon JSX is extracted into a shared variable. Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
1 parent e8a6f09 commit ec275bb

1 file changed

Lines changed: 42 additions & 54 deletions

File tree

components/StoryItem.jsx

Lines changed: 42 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useEffect, useRef, useState } from 'react';
1+
import { Fragment, useCallback, useEffect, useRef, useState } from 'react';
22
import { Pressable, StyleSheet, View } from 'react-native';
33

44
import { Link } from 'expo-router';
@@ -100,6 +100,25 @@ export default function StoryItem({ id, position }) {
100100

101101
const shortCommentsCount = shortenNumber(comments_count);
102102

103+
const commentsIcon = (
104+
<>
105+
<SymbolView name="bubble" size={22} weight="medium" />
106+
{comments_count > 0 && (
107+
<Text
108+
style={{
109+
alignSelf: 'stretch',
110+
marginTop: 8,
111+
textAlign: shortCommentsCount.length > 2 ? 'right' : 'center',
112+
}}
113+
type="insignificant"
114+
size={shortCommentsCount.length > 2 ? 'caption2' : 'footnote'}
115+
>
116+
{shortenNumber(comments_count)}
117+
</Text>
118+
)}
119+
</>
120+
);
121+
103122
const handleTouchStart = () => {
104123
clearTimeout(pressTimer.current);
105124
pressTimer.current = setTimeout(() => setPressed(true), 130);
@@ -183,7 +202,7 @@ export default function StoryItem({ id, position }) {
183202
</View>
184203
</View>
185204
</Link.Trigger>
186-
<Link.Preview />
205+
{httpLink && <Link.Preview />}
187206
<Link.Menu>
188207
<Link.MenuAction icon="square.and.arrow.up" onPress={shareHandler}>
189208
Share&hellip;
@@ -250,21 +269,7 @@ export default function StoryItem({ id, position }) {
250269
pressed2 && { opacity: 0.5 },
251270
])}
252271
>
253-
<SymbolView name="bubble" size={22} weight="medium" />
254-
{comments_count > 0 && (
255-
<Text
256-
style={{
257-
alignSelf: 'stretch',
258-
marginTop: 8,
259-
textAlign:
260-
shortCommentsCount.length > 2 ? 'right' : 'center',
261-
}}
262-
type="insignificant"
263-
size={shortCommentsCount.length > 2 ? 'caption2' : 'footnote'}
264-
>
265-
{shortenNumber(comments_count)}
266-
</Text>
267-
)}
272+
{commentsIcon}
268273
</View>
269274
</Link.Trigger>
270275
<Link.Preview />
@@ -279,43 +284,26 @@ export default function StoryItem({ id, position }) {
279284
}
280285

281286
return (
282-
<View style={styles.storyRow}>
283-
{storyWebLink}
284-
<Link href={`/story/${id}?tab=comments`} push>
285-
<Link.Trigger>
286-
<View
287-
onTouchStart={handleTouchStart}
288-
onTouchEnd={handleTouchEnd}
289-
onTouchMove={handleTouchEnd}
290-
onTouchCancel={handleTouchEnd}
291-
style={StyleSheet.flatten([
292-
styles.storyComments,
293-
pressed && { backgroundColor: colors.secondaryBackground },
294-
])}
295-
>
296-
<SymbolView name="bubble" size={22} weight="medium" />
297-
{comments_count > 0 && (
298-
<Text
299-
style={{
300-
alignSelf: 'stretch',
301-
marginTop: 8,
302-
textAlign: shortCommentsCount.length > 2 ? 'right' : 'center',
303-
}}
304-
type="insignificant"
305-
size={shortCommentsCount.length > 2 ? 'caption2' : 'footnote'}
306-
>
307-
{shortenNumber(comments_count)}
308-
</Text>
309-
)}
287+
<Link href={`/story/${id}?tab=comments`} push style={styles.storyRow}>
288+
<Link.Trigger>
289+
<View style={styles.storyRow}>
290+
<View style={[styles.story, styles.flex]}>
291+
{positionView}
292+
<View style={[styles.storyInfo, styles.flex]}>
293+
{storyInfoContent}
294+
</View>
310295
</View>
311-
</Link.Trigger>
312-
<Link.Preview />
313-
<Link.Menu>
314-
<Link.MenuAction icon="square.and.arrow.up" onPress={shareHandler}>
315-
Share story&hellip;
316-
</Link.MenuAction>
317-
</Link.Menu>
318-
</Link>
319-
</View>
296+
<View style={styles.storyComments}>
297+
{commentsIcon}
298+
</View>
299+
</View>
300+
</Link.Trigger>
301+
<Link.Preview />
302+
<Link.Menu>
303+
<Link.MenuAction icon="square.and.arrow.up" onPress={shareHandler}>
304+
Share story&hellip;
305+
</Link.MenuAction>
306+
</Link.Menu>
307+
</Link>
320308
);
321309
}

0 commit comments

Comments
 (0)