feat(phase5): star/watch/fork, releases, wiki fallback, capability probe

- endpoints: is-starred (404→false), star/unstar, subscription watch/unwatch,
  fork, releases list/detail
- hooks: useIsStarred/useToggleStar, useSubscription/useToggleWatch,
  useForkRepository, useReleases/useRelease
- repo overview: star/watch/fork actions, Releases + Wiki entries
  (wiki via explicit browser fallback gated by capability probe)
- screens: Releases list, Release detail with downloadable assets
- core/capabilities: version parsing + per-capability minimum versions + tests
- i18n (en/nl); README/ROADMAP/FEATURE_PARITY updated for phases 3-5
This commit is contained in:
JustZoe101 committed 2026-10-09 17:34:15 +02:00
1 parent c9dd49446a
commit 5e8c9492b3
16 files changed
+769 -24

No files matched your search

+130 -1
View File
@@ -7,23 +7,35 @@
import {
keepPreviousData,
useInfiniteQuery,
useMutation,
useQuery,
useQueryClient,
type InfiniteData,
} from '@tanstack/react-query';
import { useSession } from '@/features/accounts/use-session';
import {
fetchIsStarred,
fetchRelease,
fetchRepository,
fetchRepositoryLanguages,
fetchSubscription,
forkRepository,
listMyRepos,
listReleases,
listStarredRepos,
searchRepositories,
starRepo,
unstarRepo,
unwatchRepo,
watchRepo,
type ForkRepoInput,
type ListMyReposParams,
type SearchReposParams,
} from '@/core/api/endpoints';
import type { RawResponse } from '@/core/api/client';
import { queryKeys } from '@/core/api/query-keys';
import type { Repository } from '@/core/api/types';
import type { Release, Repository, Subscription } from '@/core/api/types';
type RepoPage = RawResponse<Repository[]>;
@@ -107,3 +119,120 @@ export function useRepositoryLanguages(owner: string, name: string) {
queryFn: ({ signal }) => fetchRepositoryLanguages(client!, owner, name, { signal }),
});
}
// ---------------------------------------------------------------------------
// Star / watch / fork
// ---------------------------------------------------------------------------
export function useIsStarred(owner: string, name: string) {
const { client, account } = useSession();
const accountId = account?.id ?? '';
return useQuery<boolean>({
queryKey: queryKeys.repoStar(accountId, owner, name),
enabled: Boolean(client) && Boolean(accountId) && owner.length > 0,
queryFn: ({ signal }) => fetchIsStarred(client!, owner, name, { signal }),
staleTime: 60_000,
});
}
export function useToggleStar(owner: string, name: string) {
const { client, account } = useSession();
const queryClient = useQueryClient();
const accountId = account?.id ?? '';
const key = queryKeys.repoStar(accountId, owner, name);
return useMutation({
mutationFn: (starred: boolean) =>
starred ? unstarRepo(client!, owner, name) : starRepo(client!, owner, name),
onSuccess: () => {
void queryClient.invalidateQueries({ queryKey: key });
void queryClient.invalidateQueries({ queryKey: queryKeys.repos.starred(accountId, { limit: 20 }) });
void queryClient.invalidateQueries({ queryKey: queryKeys.repoDetail(accountId, owner, name) });
},
});
}
export function useSubscription(owner: string, name: string) {
const { client, account } = useSession();
const accountId = account?.id ?? '';
return useQuery<Subscription>({
queryKey: queryKeys.repoSubscription(accountId, owner, name),
enabled: Boolean(client) && Boolean(accountId) && owner.length > 0,
queryFn: ({ signal }) => fetchSubscription(client!, owner, name, { signal }),
staleTime: 60_000,
retry: false,
});
}
export function useToggleWatch(owner: string, name: string) {
const { client, account } = useSession();
const queryClient = useQueryClient();
const accountId = account?.id ?? '';
const key = queryKeys.repoSubscription(accountId, owner, name);
return useMutation({
mutationFn: async (watching: boolean): Promise<void> => {
if (watching) {
await unwatchRepo(client!, owner, name);
} else {
await watchRepo(client!, owner, name);
}
},
onSuccess: () => {
void queryClient.invalidateQueries({ queryKey: key });
},
});
}
export function useForkRepository(owner: string, name: string) {
const { client, account } = useSession();
const queryClient = useQueryClient();
const accountId = account?.id ?? '';
return useMutation({
mutationFn: (input: ForkRepoInput) => forkRepository(client!, owner, name, input),
onSuccess: () => {
// A fork can appear in many repo lists; refresh the account's repo data.
void queryClient.invalidateQueries({ queryKey: queryKeys.account(accountId) });
},
});
}
// ---------------------------------------------------------------------------
// Releases
// ---------------------------------------------------------------------------
export function useReleases(owner: string, name: string, limit = 20) {
const { client, account } = useSession();
const accountId = account?.id ?? '';
const params = { limit };
return useInfiniteQuery<
RawResponse<Release[]>,
Error,
InfiniteData<RawResponse<Release[]>>,
readonly unknown[],
number
>({
queryKey: queryKeys.releases(accountId, owner, name, params),
enabled: Boolean(client) && Boolean(accountId),
initialPageParam: 1,
queryFn: ({ pageParam, signal }) =>
listReleases(client!, owner, name, { ...params, page: pageParam }, { signal }),
getNextPageParam: (last, all) => (last.hasMore ? all.length + 1 : undefined),
placeholderData: keepPreviousData,
});
}
export function useRelease(owner: string, name: string, id: number) {
const { client, account } = useSession();
const accountId = account?.id ?? '';
return useQuery({
queryKey: queryKeys.release(accountId, owner, name, id),
enabled: Boolean(client) && Boolean(accountId) && id > 0,
queryFn: ({ signal }) => fetchRelease(client!, owner, name, id, { signal }),
});
}
@@ -0,0 +1,136 @@
import { Linking, Pressable, StyleSheet, View } from 'react-native';
import { useTranslation } from 'react-i18next';
import { Markdown } from '@/components/git/markdown';
import { Screen } from '@/components/layout/screen';
import { AppText } from '@/components/ui/app-text';
import { Avatar } from '@/components/ui/avatar';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Card } from '@/components/ui/card';
import { Icon } from '@/components/ui/icon';
import { ErrorState, LoadingView } from '@/components/ui/state-views';
import { apiErrorMessage } from '@/core/api/error-text';
import { useSession } from '@/features/accounts/use-session';
import { useRelease } from '@/features/repositories/queries';
import { formatBytes, formatDateTime } from '@/core/utils/format';
import { useTheme } from '@/theme/theme-provider';
import { spacing } from '@/theme/tokens';
import type { RepositoryStackParamList } from '@/navigation/types';
import type { ScreenProps } from '@/navigation/typing';
type Props = ScreenProps<RepositoryStackParamList, 'ReleaseDetail'>;
/** One release: metadata, notes and downloadable assets. */
export function ReleaseDetailScreen({ route }: Props) {
const { t } = useTranslation();
const { colors } = useTheme();
const { instance } = useSession();
const { owner, name, id } = route.params;
const query = useRelease(owner, name, id);
const release = query.data;
if (query.isPending) return <LoadingView />;
if (query.isError) {
return (
<ErrorState
title={t('errors.title')}
body={apiErrorMessage(query.error, t)}
retryLabel={t('common.retry')}
onRetry={() => void query.refetch()}
/>
);
}
if (!release) return null;
const assets = release.assets ?? [];
return (
<Screen scroll padded>
<View style={styles.titleBlock}>
<AppText variant="heading">{release.name || release.tag_name}</AppText>
<View style={styles.badges}>
{release.tag_name ? <Badge tone="primary" icon="tag">{release.tag_name}</Badge> : null}
{release.prerelease ? <Badge tone="warning">{t('releases.prerelease')}</Badge> : null}
{release.draft ? <Badge tone="neutral">{t('releases.draft')}</Badge> : null}
</View>
</View>
<View style={styles.authorRow}>
<Avatar url={release.author?.avatar_url} name={release.author?.login ?? '?'} size={28} />
<AppText variant="bodyMedium" style={styles.authorName}>
{release.author?.login ?? t('common.unknown')}
</AppText>
<AppText variant="caption" tone="tertiary">
{formatDateTime(release.published_at ?? release.created_at)}
</AppText>
</View>
{release.body && release.body.trim().length > 0 ? (
<Card>
<Markdown content={release.body} baseUrl={instance?.baseUrl} />
</Card>
) : null}
{assets.length > 0 ? (
<>
<AppText variant="subheading">{t('releases.assets')}</AppText>
<Card padded={false} variant="flat">
{assets.map((asset, index) => (
<Pressable
key={asset.id ?? asset.name ?? index}
onPress={() =>
asset.browser_download_url
? void Linking.openURL(asset.browser_download_url).catch(() => undefined)
: undefined
}
accessibilityRole="button"
accessibilityLabel={asset.name}
style={[styles.assetRow, index < assets.length - 1 && styles.divider]}
>
<Icon name="download" size={18} color={colors.textTertiary} />
<View style={styles.assetBody}>
<AppText variant="bodyMedium" numberOfLines={1}>
{asset.name}
</AppText>
<AppText variant="caption" tone="tertiary">
{t('releases.downloads', {
size: formatBytes(asset.size ?? 0),
count: asset.download_count ?? 0,
})}
</AppText>
</View>
</Pressable>
))}
</Card>
</>
) : null}
{release.html_url ? (
<Button
label={t('repo.viewOnInstance')}
variant="secondary"
iconLeft="externalLink"
onPress={() => void Linking.openURL(release.html_url as string).catch(() => undefined)}
/>
) : null}
</Screen>
);
}
const styles = StyleSheet.create({
titleBlock: { gap: spacing.sm },
badges: { flexDirection: 'row', flexWrap: 'wrap', gap: spacing.sm, alignItems: 'center' },
authorRow: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm },
authorName: { flex: 1 },
assetRow: {
flexDirection: 'row',
alignItems: 'center',
gap: spacing.md,
paddingHorizontal: spacing.lg,
paddingVertical: spacing.md,
},
divider: { borderBottomWidth: StyleSheet.hairlineWidth, borderBottomColor: 'rgba(128,128,128,0.25)' },
assetBody: { flex: 1, gap: 2 },
});
@@ -0,0 +1,66 @@
import { StyleSheet, View } from 'react-native';
import { useTranslation } from 'react-i18next';
import { QueryList } from '@/components/layout/query-list';
import { AppText } from '@/components/ui/app-text';
import { Badge } from '@/components/ui/badge';
import { EmptyState } from '@/components/ui/state-views';
import type { Release } from '@/core/api/types';
import { flattenPages } from '@/core/utils/infinite';
import { formatDateTime } from '@/core/utils/format';
import { useReleases } from '@/features/repositories/queries';
import { spacing } from '@/theme/tokens';
import type { RepositoryStackParamList } from '@/navigation/types';
import type { ScreenProps } from '@/navigation/typing';
type Props = ScreenProps<RepositoryStackParamList, 'Releases'>;
/** Repository releases (newest first). */
export function ReleasesScreen({ navigation, route }: Props) {
const { t } = useTranslation();
const { owner, name } = route.params;
const query = useReleases(owner, name);
const releases: Release[] = flattenPages(query.data);
return (
<QueryList<Release>
query={query}
items={releases}
keyExtractor={(release) => String(release.id ?? release.tag_name)}
renderItem={(release) => (
<View style={styles.row}>
<AppText
variant="bodyMedium"
onPress={() =>
release.id ? navigation.navigate('ReleaseDetail', { owner, name, id: release.id }) : undefined
}
accessibilityRole="button"
>
{release.name || release.tag_name}
</AppText>
<View style={styles.metaRow}>
<Badge tone="neutral">{release.tag_name ?? ''}</Badge>
{release.prerelease ? <Badge tone="warning">{t('releases.prerelease')}</Badge> : null}
{release.draft ? <Badge tone="neutral">{t('releases.draft')}</Badge> : null}
{release.published_at ? (
<AppText variant="caption" tone="tertiary">
{formatDateTime(release.published_at)}
</AppText>
) : null}
</View>
</View>
)}
empty={<EmptyState icon="tag" title={t('releases.empty')} />}
/>
);
}
const styles = StyleSheet.create({
row: {
paddingHorizontal: spacing.lg,
paddingVertical: spacing.md,
gap: spacing.xs,
},
metaRow: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm, flexWrap: 'wrap' },
});
@@ -1,5 +1,5 @@
import { useMemo } from 'react';
import { Linking, StyleSheet, View } from 'react-native';
import { Alert, Linking, StyleSheet, View } from 'react-native';
import { useTranslation } from 'react-i18next';
import { Markdown } from '@/components/git/markdown';
@@ -13,8 +13,17 @@ import { LabelChip } from '@/components/ui/label-chip';
import { ListItem } from '@/components/ui/list-item';
import { ErrorState, LoadingView } from '@/components/ui/state-views';
import { apiErrorMessage } from '@/core/api/error-text';
import { parseGiteaVersion, supports } from '@/core/capabilities';
import { buildEditorUrl } from '@/core/utils/editor-url';
import { useRepository, useRepositoryLanguages } from '@/features/repositories/queries';
import {
useForkRepository,
useIsStarred,
useRepository,
useRepositoryLanguages,
useSubscription,
useToggleStar,
useToggleWatch,
} from '@/features/repositories/queries';
import { decodeBase64, useReadme } from '@/features/repository/queries';
import { useSession } from '@/features/accounts/use-session';
import { useSettingsStore } from '@/features/settings/settings-store';
@@ -38,6 +47,35 @@ export function RepoOverviewScreen({ navigation, route }: Props) {
const readmeRef = ref ?? repo?.default_branch;
const readmeQuery = useReadme(owner, name, readmeRef);
const languagesQuery = useRepositoryLanguages(owner, name);
const isStarred = useIsStarred(owner, name);
const toggleStar = useToggleStar(owner, name);
const subscription = useSubscription(owner, name);
const toggleWatch = useToggleWatch(owner, name);
const forkRepo = useForkRepository(owner, name);
const version = parseGiteaVersion(instance?.version);
const repoUrl = instance ? `${instance.baseUrl}/${owner}/${name}` : null;
const confirmFork = () => {
Alert.alert(t('repo.forkTitle'), t('repo.forkBody', { name }), [
{ text: t('common.cancel'), style: 'cancel' },
{
text: t('repo.fork'),
onPress: () =>
forkRepo.mutate(
{},
{
onSuccess: (forked) =>
Alert.alert(
t('repo.forkedTitle'),
t('repo.forkedBody', { name: forked.full_name ?? name }),
),
onError: (error) => Alert.alert(t('errors.title'), apiErrorMessage(error, t)),
},
),
},
]);
};
const languages = useMemo(() => {
const entries = Object.entries(languagesQuery.data ?? {});
@@ -127,6 +165,33 @@ export function RepoOverviewScreen({ navigation, route }: Props) {
}}
/>
) : null}
<View style={styles.actionRow}>
<Button
label={isStarred.data ? t('repo.unstar') : t('repo.star')}
variant="secondary"
size="md"
iconLeft={isStarred.data ? 'star' : 'starOutline'}
loading={toggleStar.isPending}
onPress={() => toggleStar.mutate(isStarred.data ?? false)}
/>
<Button
label={subscription.data?.subscribed ? t('repo.unwatch') : t('repo.watch')}
variant="secondary"
size="md"
iconLeft="bell"
loading={toggleWatch.isPending}
onPress={() => toggleWatch.mutate(subscription.data?.subscribed ?? false)}
/>
<Button
label={t('repo.fork')}
variant="secondary"
size="md"
iconLeft="fork"
loading={forkRepo.isPending}
onPress={confirmFork}
/>
</View>
</View>
{/* Quick navigation */}
@@ -155,6 +220,20 @@ export function RepoOverviewScreen({ navigation, route }: Props) {
title={t('repo.tags')}
onPress={() => navigation.navigate('Tags', { owner, name })}
/>
{repo.has_releases !== false ? (
<ListItem
leadingIcon="download"
title={t('releases.title')}
onPress={() => navigation.navigate('Releases', { owner, name })}
/>
) : null}
{repo.has_wiki && supports('wiki', version) && repoUrl ? (
<ListItem
leadingIcon="globe"
title={t('repo.wiki')}
onPress={() => void Linking.openURL(`${repoUrl}/wiki`).catch(() => undefined)}
/>
) : null}
{repo.has_issues !== false ? (
<ListItem
leadingIcon="issue"
@@ -299,6 +378,7 @@ const styles = StyleSheet.create({
titleRow: { flexDirection: 'row', alignItems: 'baseline', flexWrap: 'wrap' },
name: { flexShrink: 1 },
badges: { flexDirection: 'row', flexWrap: 'wrap', gap: spacing.sm, alignItems: 'center' },
actionRow: { flexDirection: 'row', flexWrap: 'wrap', gap: spacing.sm },
section: { marginTop: spacing.xl, gap: spacing.sm },
sectionTitle: { paddingHorizontal: spacing.lg },
card: { marginHorizontal: spacing.lg },