1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
| import React, { useCallback } from 'react';
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { colors } from '../theme/colors';
import type { Issue } from '../api/issues';
interface IssueRowProps {
issue: Issue;
onPress: (issue: Issue) => void;
}
function formatRelative(dateStr: string): string {
const diff = Date.now() - new Date(dateStr).getTime();
const mins = Math.floor(diff / 60000);
if (mins < 1) return 'just now';
if (mins < 60) return `${mins}m ago`;
const hrs = Math.floor(mins / 60);
if (hrs < 24) return `${hrs}h ago`;
const days = Math.floor(hrs / 24);
if (days < 30) return `${days}d ago`;
const months = Math.floor(days / 30);
if (months < 12) return `${months}mo ago`;
return `${Math.floor(months / 12)}y ago`;
}
export function IssueRow({ issue, onPress }: IssueRowProps): React.ReactElement {
const handlePress = useCallback(() => onPress(issue), [issue, onPress]);
const stateColor = issue.state === 'open' ? colors.accent : colors.accentRed;
return (
<TouchableOpacity
style={styles.row}
onPress={handlePress}
activeOpacity={0.75}
>
<View style={[styles.stateIndicator, { backgroundColor: stateColor }]} />
<View style={styles.content}>
<View style={styles.titleRow}>
<Text style={styles.title} numberOfLines={2}>
{issue.title}
</Text>
</View>
{issue.labels.length > 0 && (
<View style={styles.labels}>
{issue.labels.slice(0, 4).map((label) => (
<View
key={label.id}
style={[styles.label, { borderColor: `#${label.color}` }]}
>
<Text style={[styles.labelText, { color: `#${label.color}` }]}>
{label.name}
</Text>
</View>
))}
</View>
)}
<View style={styles.meta}>
<Text style={styles.metaText}>
#{issue.number} opened {formatRelative(issue.createdAt)} by {issue.authorUsername}
</Text>
{issue.commentCount > 0 && (
<View style={styles.commentCount}>
<Text style={styles.metaIcon}>💬</Text>
<Text style={styles.metaText}>{issue.commentCount}</Text>
</View>
)}
</View>
</View>
</TouchableOpacity>
);
}
const styles = StyleSheet.create({
row: {
flexDirection: 'row',
backgroundColor: colors.bgSecondary,
borderBottomWidth: 1,
borderBottomColor: colors.border,
paddingVertical: 12,
paddingHorizontal: 16,
gap: 12,
},
stateIndicator: {
width: 14,
height: 14,
borderRadius: 7,
marginTop: 3,
flexShrink: 0,
},
content: {
flex: 1,
gap: 6,
},
titleRow: {
flexDirection: 'row',
alignItems: 'flex-start',
},
title: {
fontSize: 14,
fontWeight: '500',
color: colors.text,
lineHeight: 20,
flex: 1,
},
labels: {
flexDirection: 'row',
flexWrap: 'wrap',
gap: 6,
},
label: {
paddingHorizontal: 7,
paddingVertical: 2,
borderRadius: 20,
borderWidth: 1,
},
labelText: {
fontSize: 11,
fontWeight: '500',
},
meta: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
},
metaText: {
fontSize: 12,
color: colors.textMuted,
},
commentCount: {
flexDirection: 'row',
alignItems: 'center',
gap: 3,
},
metaIcon: {
fontSize: 11,
},
});
|