import { useMemo } from 'react'; import { Alert, Linking, 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 { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Card } from '@/components/ui/card'; import { Icon } from '@/components/ui/icon'; 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 { 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'; import { useTheme } from '@/theme/theme-provider'; import { radius, spacing } from '@/theme/tokens'; import type { RepositoryStackParamList } from '@/navigation/types'; import type { ScreenProps } from '@/navigation/typing'; type Props = ScreenProps; /** Repository landing page: metadata, quick navigation, stats, languages, README. */ export function RepoOverviewScreen({ navigation, route }: Props) { const { t } = useTranslation(); const { colors } = useTheme(); const { instance } = useSession(); const editorUrlTemplate = useSettingsStore((s) => s.editorUrlTemplate); const { owner, name, ref } = route.params; const repoQuery = useRepository(owner, name); const repo = repoQuery.data; 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 ?? {}); const total = entries.reduce((sum, [, bytes]) => sum + bytes, 0); if (total <= 0) return []; return entries .map(([language, bytes]) => ({ language, bytes, percent: (bytes / total) * 100 })) .sort((a, b) => b.bytes - a.bytes) .slice(0, 6); }, [languagesQuery.data]); if (!repo && repoQuery.isPending) return ; if (!repo && repoQuery.isError) { return ( void repoQuery.refetch()} /> ); } if (!repo) return null; const readmeText = decodeReadme(readmeQuery.data?.content); return ( {/* Header */} {owner}/ {name} {repo.description ?? t('repo.noDescription')} {repo.private ? {t('repositories.private')} : null} {repo.fork ? {t('repositories.fork')} : null} {repo.archived ? {t('repositories.archived')} : null} {repo.template ? {t('repositories.template')} : null} {repo.mirror ? {t('repositories.mirror')} : null} {repo.default_branch ? ( {repo.default_branch} ) : null} {repo.topics && repo.topics.length > 0 ? ( {repo.topics.slice(0, 8).map((topic) => ( ))} ) : null} {repo.html_url ? (