CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | import React, { useCallback, useEffect, useState } from 'react';
import {
FlatList,
StyleSheet,
Text,
TouchableOpacity,
View,
} from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import type { NativeStackScreenProps } from '@react-navigation/native-stack';
import { listIssues } from '../api/issues';
import type { Issue } from '../api/issues';
import { IssueRow } from '../components/IssueRow';
import { LoadingSpinner } from '../components/LoadingSpinner';
import { ErrorBanner } from '../components/ErrorBanner';
import { colors } from '../theme/colors';
import type { RepoStackParamList } from '../navigation/AppNavigator';
type Props = NativeStackScreenProps<RepoStackParamList, 'Issues'>;
type FilterState = 'open' | 'closed';
export function IssuesScreen({ route, navigation }: Props): React.ReactElement {
const { owner, repo } = route.params;
const [filter, setFilter] = useState<FilterState>('open');
const [issues, setIssues] = useState<Issue[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [page, setPage] = useState(1);
const [hasMore, setHasMore] = useState(true);
useEffect(() => {
let cancelled = false;
setIsLoading(true);
setError(null);
listIssues(owner, repo, filter, 1)
.then((data) => {
if (!cancelled) {
setIssues(data);
setPage(1);
setHasMore(data.length === 30);
}
})
.catch((err) => {
if (!cancelled) {
setError(err instanceof Error ? err.message : 'Failed to load issues');
}
})
.finally(() => {
if (!cancelled) setIsLoading(false);
});
return () => {
cancelled = true;
};
}, [owner, repo, filter]);
const loadMore = useCallback(() => {
if (!hasMore || isLoading) return;
const nextPage = page + 1;
listIssues(owner, repo, filter, nextPage)
.then((data) => {
setIssues((prev) => [...prev, ...data]);
setPage(nextPage);
setHasMore(data.length === 30);
})
.catch(() => {/* ignore pagination errors */});
}, [owner, repo, filter, page, hasMore, isLoading]);
const handleIssuePress = useCallback(
(issue: Issue) => {
navigation.navigate('IssueDetail', { owner, repo, number: issue.number });
},
[navigation, owner, repo],
);
const renderIssue = useCallback(
({ item }: { item: Issue }) => <IssueRow issue={item} onPress={handleIssuePress} />,
[handleIssuePress],
);
const keyExtractor = useCallback((item: Issue) => String(item.id), []);
const renderFooter = useCallback(
() => (hasMore ? <LoadingSpinner size="small" /> : null),
[hasMore],
);
if (isLoading && issues.length === 0) return <LoadingSpinner fullScreen />;
return (
<SafeAreaView style={styles.safe} edges={['bottom']}>
{/* Filter tabs */}
<View style={styles.filterTabs}>
<TouchableOpacity
style={[styles.filterTab, filter === 'open' && styles.filterTabActive]}
onPress={() => setFilter('open')}
>
<Text style={[styles.filterTabText, filter === 'open' && styles.filterTabTextActive]}>
Open
</Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.filterTab, filter === 'closed' && styles.filterTabActive]}
onPress={() => setFilter('closed')}
>
<Text style={[styles.filterTabText, filter === 'closed' && styles.filterTabTextActive]}>
Closed
</Text>
</TouchableOpacity>
</View>
{error !== null && <ErrorBanner message={error} />}
<FlatList
data={issues}
keyExtractor={keyExtractor}
renderItem={renderIssue}
onEndReached={loadMore}
onEndReachedThreshold={0.3}
ListFooterComponent={renderFooter}
ListEmptyComponent={
<View style={styles.emptyState}>
<Text style={styles.emptyText}>
No {filter} issues
</Text>
</View>
}
style={styles.list}
/>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
safe: {
flex: 1,
backgroundColor: colors.bg,
},
filterTabs: {
flexDirection: 'row',
backgroundColor: colors.bgSecondary,
borderBottomWidth: 1,
borderBottomColor: colors.border,
},
filterTab: {
flex: 1,
paddingVertical: 12,
alignItems: 'center',
borderBottomWidth: 2,
borderBottomColor: 'transparent',
},
filterTabActive: {
borderBottomColor: colors.accentBlue,
},
filterTabText: {
fontSize: 14,
fontWeight: '500',
color: colors.textMuted,
},
filterTabTextActive: {
color: colors.text,
},
list: {
flex: 1,
},
emptyState: {
padding: 40,
alignItems: 'center',
},
emptyText: {
fontSize: 14,
color: colors.textMuted,
},
});
|