- API: Actions (workflows/runs/jobs/logs getText), repo create/edit/delete, collaborators, webhooks, branch protections, orgs, packages, user keys/GPG keys/tokens, release create/edit/delete - hooks: features/actions, repositories/settings-queries, features/profile - screens: Actions + run detail (expandable job logs), RepoSettings, Collaborators, Webhooks, Protections, CreateRepo, Organizations, OrgRepos, Packages, Credentials, ReleaseCompose; releases list/detail management - navigation + i18n (en/nl) wired for all new screens
145 lines
4.9 KiB
TypeScript
145 lines
4.9 KiB
TypeScript
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 { Button } from '@/components/ui/button';
|
|
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 style={styles.newRepo}>
|
|
<Button
|
|
label={t('createRepo.title')}
|
|
variant="secondary"
|
|
iconLeft="plus"
|
|
fullWidth
|
|
onPress={() => navigation.navigate('CreateRepo')}
|
|
/>
|
|
</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 },
|
|
newRepo: { paddingHorizontal: spacing.lg, paddingBottom: spacing.sm },
|
|
});
|