feat(features): auth, accounts, home, repositories, issues, notifications
- auth: welcome/connect screens, shared connect form, connect flow, app lock - accounts: session hook, actions, switcher + add-account screens - home: dashboard (identity, shortcuts, recent repos, assigned issues, review requests, activity, unread badge) - repositories/repository: list+search, overview, files, file viewer, commits, commit detail, branches, tags, repo issues/pulls, issue/pull detail - issues/notifications: cross-repo search, query hooks, inbox with read marking and lifecycle-aware polling - settings: theme/language/biometrics/poll interval/cache/about
This commit is contained in:
1 parent
ad81db07b3
commit
0a889ebfed
36 files changed
+4186
No files matched your search
@@ -0,0 +1,133 @@
|
||||
import { useMemo, useState } from 'react';
|
||||
import { View, StyleSheet } from 'react-native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { RepoListItem } from '@/components/git/repo-list-item';
|
||||
import { QueryList } from '@/components/layout/query-list';
|
||||
import { SearchBar } from '@/components/ui/search-bar';
|
||||
import { EmptyState } from '@/components/ui/state-views';
|
||||
import { SegmentedControl } from '@/components/ui/segmented';
|
||||
|
||||
import { useMyRepos, useSearchRepos } from '@/features/repositories/queries';
|
||||
import { flattenPages } from '@/core/utils/infinite';
|
||||
import type { Repository } from '@/core/api/types';
|
||||
import { spacing } from '@/theme/tokens';
|
||||
import type { RepositoriesStackParamList } from '@/navigation/types';
|
||||
import type { ScreenProps } from '@/navigation/typing';
|
||||
|
||||
type Props = ScreenProps<RepositoriesStackParamList, 'RepositoryList'>;
|
||||
|
||||
type Visibility = 'all' | 'private' | 'public';
|
||||
type SortKey = 'updated' | 'name' | 'stars' | 'created';
|
||||
|
||||
/** Repository browser: search, visibility filter and client-side sorting. */
|
||||
export function RepositoryListScreen({ navigation }: Props) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [search, setSearch] = useState('');
|
||||
const [visibility, setVisibility] = useState<Visibility>('all');
|
||||
const [sort, setSort] = useState<SortKey>('updated');
|
||||
|
||||
const searching = search.trim().length > 0;
|
||||
const browseQuery = useMyRepos(visibility);
|
||||
const searchQuery = useSearchRepos(search);
|
||||
|
||||
// One list at a time: search endpoint while typing, /user/repos otherwise.
|
||||
const query = searching ? searchQuery : browseQuery;
|
||||
const rawItems: Repository[] = useMemo(
|
||||
() => flattenPages(searching ? searchQuery.data : browseQuery.data),
|
||||
[searching, searchQuery.data, browseQuery.data],
|
||||
);
|
||||
|
||||
// /user/repos has no sort parameter; sort the loaded pages client-side.
|
||||
const items = useMemo(() => {
|
||||
if (searching) return rawItems;
|
||||
const sorted = [...rawItems];
|
||||
switch (sort) {
|
||||
case 'name':
|
||||
sorted.sort((a, b) => (a.name ?? '').localeCompare(b.name ?? ''));
|
||||
break;
|
||||
case 'stars':
|
||||
sorted.sort((a, b) => (b.stars_count ?? 0) - (a.stars_count ?? 0));
|
||||
break;
|
||||
case 'created':
|
||||
sorted.sort((a, b) => (b.created_at ?? '').localeCompare(a.created_at ?? ''));
|
||||
break;
|
||||
case 'updated':
|
||||
default:
|
||||
break; // server order = recently updated
|
||||
}
|
||||
return sorted;
|
||||
}, [rawItems, sort, searching]);
|
||||
|
||||
const header = (
|
||||
<View>
|
||||
<SearchBar
|
||||
value={search}
|
||||
onChangeText={setSearch}
|
||||
placeholder={t('repositories.searchPlaceholder')}
|
||||
testID="repo-search"
|
||||
/>
|
||||
<View style={styles.filters}>
|
||||
<SegmentedControl<Visibility>
|
||||
accessibilityLabel={t('repositories.title')}
|
||||
value={visibility}
|
||||
onChange={setVisibility}
|
||||
options={[
|
||||
{ value: 'all', label: t('repositories.visibilityAll') },
|
||||
{ value: 'private', label: t('repositories.visibilityPrivate') },
|
||||
{ value: 'public', label: t('repositories.visibilityPublic') },
|
||||
]}
|
||||
/>
|
||||
{!searching ? (
|
||||
<SegmentedControl<SortKey>
|
||||
accessibilityLabel={t('repositories.title')}
|
||||
value={sort}
|
||||
onChange={setSort}
|
||||
options={[
|
||||
{ value: 'updated', label: t('repositories.sortUpdated') },
|
||||
{ value: 'name', label: t('repositories.sortName') },
|
||||
{ value: 'stars', label: t('repositories.sortStars') },
|
||||
{ value: 'created', label: t('repositories.sortCreated') },
|
||||
]}
|
||||
/>
|
||||
) : null}
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
|
||||
return (
|
||||
<QueryList<Repository>
|
||||
query={query}
|
||||
items={items}
|
||||
keyExtractor={(repo) => repo.full_name}
|
||||
header={header}
|
||||
loadingRows={8}
|
||||
renderItem={(repo) => (
|
||||
<RepoListItem
|
||||
repo={repo}
|
||||
onPress={() =>
|
||||
navigation.navigate('Repository', {
|
||||
screen: 'RepoOverview',
|
||||
params: { owner: repo.owner?.login ?? repo.full_name.split('/')[0], name: repo.name },
|
||||
})
|
||||
}
|
||||
/>
|
||||
)}
|
||||
empty={
|
||||
searching ? (
|
||||
<EmptyState
|
||||
icon="search"
|
||||
title={t('repositories.emptySearch', { query: search.trim() })}
|
||||
/>
|
||||
) : (
|
||||
<EmptyState icon="repo" title={t('repositories.empty')} />
|
||||
)
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
filters: { gap: spacing.sm, paddingHorizontal: spacing.lg, paddingBottom: spacing.sm },
|
||||
});
|
||||
Reference in new issue
Block a user