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,223 @@
|
||||
import Constants from 'expo-constants';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Alert, Linking, StyleSheet, Switch, View } from 'react-native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { Screen } from '@/components/layout/screen';
|
||||
import { AppText } from '@/components/ui/app-text';
|
||||
import { Card } from '@/components/ui/card';
|
||||
import { ListItem } from '@/components/ui/list-item';
|
||||
import { SegmentedControl } from '@/components/ui/segmented';
|
||||
import { queryClient } from '@/core/api/query-client';
|
||||
import type { BiometricSupport } from '@/core/security/biometrics';
|
||||
import { getBiometricSupport } from '@/core/security/biometrics';
|
||||
import { useSettingsStore, type ThemePreference } from '@/features/settings/settings-store';
|
||||
import { useRootNavigation } from '@/navigation/use-root-navigation';
|
||||
import type { LanguagePreference } from '@/i18n';
|
||||
import { useTheme } from '@/theme/theme-provider';
|
||||
import { spacing } from '@/theme/tokens';
|
||||
import type { SettingsStackParamList } from '@/navigation/types';
|
||||
import type { ScreenProps } from '@/navigation/typing';
|
||||
|
||||
type Props = ScreenProps<SettingsStackParamList, 'Settings'>;
|
||||
|
||||
type PollKey = '0' | '30' | '60' | '300';
|
||||
|
||||
const GITEA_HOME_URL = 'https://gitea.com';
|
||||
|
||||
/** App settings: appearance, language, security, notifications, data, about. */
|
||||
export function SettingsScreen(_props: Props) {
|
||||
const navigation = useRootNavigation();
|
||||
const { t } = useTranslation();
|
||||
const { colors } = useTheme();
|
||||
|
||||
const themePreference = useSettingsStore((s) => s.themePreference);
|
||||
const language = useSettingsStore((s) => s.language);
|
||||
const biometricsEnabled = useSettingsStore((s) => s.biometricsEnabled);
|
||||
const notificationPollSeconds = useSettingsStore((s) => s.notificationPollSeconds);
|
||||
const setThemePreference = useSettingsStore((s) => s.setThemePreference);
|
||||
const setLanguage = useSettingsStore((s) => s.setLanguage);
|
||||
const setBiometricsEnabled = useSettingsStore((s) => s.setBiometricsEnabled);
|
||||
const setNotificationPollSeconds = useSettingsStore((s) => s.setNotificationPollSeconds);
|
||||
|
||||
const [support, setSupport] = useState<BiometricSupport | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
void getBiometricSupport().then((value) => {
|
||||
if (!cancelled) setSupport(value);
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, []);
|
||||
|
||||
const version = Constants.expoConfig?.version ?? '0.1.0';
|
||||
|
||||
const confirmClearCache = () => {
|
||||
Alert.alert(t('settings.clearCacheTitle'), t('settings.clearCacheConfirm'), [
|
||||
{ text: t('common.cancel'), style: 'cancel' },
|
||||
{
|
||||
text: t('common.confirm'),
|
||||
style: 'destructive',
|
||||
onPress: () => {
|
||||
queryClient.clear();
|
||||
Alert.alert(t('settings.clearCacheDone'));
|
||||
},
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
return (
|
||||
<Screen scroll padded>
|
||||
{/* Appearance */}
|
||||
<Section title={t('settings.appearance')}>
|
||||
<Card style={styles.card}>
|
||||
<AppText variant="label" tone="secondary">
|
||||
{t('settings.theme')}
|
||||
</AppText>
|
||||
<SegmentedControl<ThemePreference>
|
||||
value={themePreference}
|
||||
onChange={setThemePreference}
|
||||
accessibilityLabel={t('settings.theme')}
|
||||
options={[
|
||||
{ value: 'system', label: t('settings.themeSystem') },
|
||||
{ value: 'light', label: t('settings.themeLight') },
|
||||
{ value: 'dark', label: t('settings.themeDark') },
|
||||
]}
|
||||
/>
|
||||
<AppText variant="label" tone="secondary" style={styles.spaced}>
|
||||
{t('settings.language')}
|
||||
</AppText>
|
||||
<SegmentedControl<LanguagePreference>
|
||||
value={language}
|
||||
onChange={setLanguage}
|
||||
accessibilityLabel={t('settings.language')}
|
||||
options={[
|
||||
{ value: 'system', label: t('settings.languageSystem') },
|
||||
{ value: 'en', label: 'English' },
|
||||
{ value: 'nl', label: 'Nederlands' },
|
||||
]}
|
||||
/>
|
||||
</Card>
|
||||
</Section>
|
||||
|
||||
{/* Security */}
|
||||
<Section title={t('settings.security')}>
|
||||
<Card padded={false} variant="flat">
|
||||
<View style={styles.switchRow}>
|
||||
<View style={styles.switchBody}>
|
||||
<AppText variant="bodyMedium">{t('settings.biometrics')}</AppText>
|
||||
<AppText variant="caption" tone="tertiary">
|
||||
{support && !support.usable
|
||||
? t('settings.biometricsUnavailable')
|
||||
: t('settings.biometricsHelp')}
|
||||
</AppText>
|
||||
</View>
|
||||
<Switch
|
||||
value={biometricsEnabled}
|
||||
onValueChange={setBiometricsEnabled}
|
||||
disabled={!support?.usable}
|
||||
trackColor={{ true: colors.primary, false: colors.surfaceSecondary }}
|
||||
thumbColor={colors.surface}
|
||||
accessibilityLabel={t('settings.biometrics')}
|
||||
/>
|
||||
</View>
|
||||
</Card>
|
||||
</Section>
|
||||
|
||||
{/* Notifications */}
|
||||
<Section title={t('settings.notifications')}>
|
||||
<Card style={styles.card}>
|
||||
<AppText variant="label" tone="secondary">
|
||||
{t('settings.pollInterval')}
|
||||
</AppText>
|
||||
<SegmentedControl<PollKey>
|
||||
value={String(notificationPollSeconds) as PollKey}
|
||||
onChange={(value) => setNotificationPollSeconds(Number(value))}
|
||||
accessibilityLabel={t('settings.pollInterval')}
|
||||
options={[
|
||||
{ value: '0', label: t('settings.pollIntervalManual') },
|
||||
{ value: '30', label: t('settings.pollIntervalSeconds', { count: 30 }) },
|
||||
{ value: '60', label: t('settings.pollIntervalSeconds', { count: 60 }) },
|
||||
{ value: '300', label: t('settings.pollIntervalSeconds', { count: 300 }) },
|
||||
]}
|
||||
/>
|
||||
</Card>
|
||||
</Section>
|
||||
|
||||
{/* Data */}
|
||||
<Section title={t('settings.data')}>
|
||||
<Card padded={false} variant="flat">
|
||||
<ListItem
|
||||
leadingIcon="trash"
|
||||
title={t('settings.clearCache')}
|
||||
subtitle={t('settings.clearCacheConfirm')}
|
||||
onPress={confirmClearCache}
|
||||
divider={false}
|
||||
/>
|
||||
</Card>
|
||||
</Section>
|
||||
|
||||
{/* Accounts */}
|
||||
<Section title={t('settings.accounts')}>
|
||||
<Card padded={false} variant="flat">
|
||||
<ListItem
|
||||
leadingIcon="people"
|
||||
title={t('accounts.title')}
|
||||
onPress={() => navigation.navigate('Accounts', { screen: 'Accounts' })}
|
||||
divider={false}
|
||||
/>
|
||||
</Card>
|
||||
</Section>
|
||||
|
||||
{/* About */}
|
||||
<Section title={t('settings.about')}>
|
||||
<Card padded={false} variant="flat">
|
||||
<ListItem
|
||||
leadingIcon="info"
|
||||
title={t('settings.version', { version })}
|
||||
subtitle={t('settings.aboutBody')}
|
||||
/>
|
||||
<ListItem
|
||||
leadingIcon="globe"
|
||||
title={t('settings.giteaProject')}
|
||||
onPress={() => void Linking.openURL(GITEA_HOME_URL).catch(() => undefined)}
|
||||
divider={false}
|
||||
/>
|
||||
</Card>
|
||||
</Section>
|
||||
|
||||
<AppText variant="caption" tone="tertiary" style={styles.footer}>
|
||||
{t('common.unofficialNotice')}
|
||||
</AppText>
|
||||
</Screen>
|
||||
);
|
||||
}
|
||||
|
||||
function Section({ title, children }: { title: string; children: React.ReactNode }) {
|
||||
return (
|
||||
<View style={styles.section}>
|
||||
<AppText variant="label" tone="secondary" style={styles.sectionTitle}>
|
||||
{title}
|
||||
</AppText>
|
||||
{children}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
section: { gap: spacing.sm },
|
||||
sectionTitle: { textTransform: 'uppercase', letterSpacing: 0.5 },
|
||||
card: { gap: spacing.sm },
|
||||
spaced: { marginTop: spacing.md },
|
||||
switchRow: {
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
gap: spacing.md,
|
||||
paddingHorizontal: spacing.lg,
|
||||
paddingVertical: spacing.md,
|
||||
},
|
||||
switchBody: { flex: 1, gap: 2 },
|
||||
footer: { textAlign: 'center', paddingVertical: spacing.xl },
|
||||
});
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Client-side settings (non-sensitive, persisted to AsyncStorage).
|
||||
*
|
||||
* Secrets never live here — tokens are stored via Expo SecureStore only.
|
||||
*/
|
||||
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import { create } from 'zustand';
|
||||
import { createJSONStorage, persist } from 'zustand/middleware';
|
||||
|
||||
import type { LanguagePreference } from '@/i18n';
|
||||
|
||||
export type ThemePreference = 'system' | 'light' | 'dark';
|
||||
|
||||
export interface SettingsState {
|
||||
themePreference: ThemePreference;
|
||||
/** UI language; 'system' follows the device locale. */
|
||||
language: LanguagePreference;
|
||||
/** Require biometrics (Face ID / fingerprint) when the app becomes active again. */
|
||||
biometricsEnabled: boolean;
|
||||
/** Background polling interval for the notifications inbox, in seconds. 0 = only manual/foreground refresh. */
|
||||
notificationPollSeconds: number;
|
||||
setThemePreference: (preference: ThemePreference) => void;
|
||||
setLanguage: (language: LanguagePreference) => void;
|
||||
setBiometricsEnabled: (enabled: boolean) => void;
|
||||
setNotificationPollSeconds: (seconds: number) => void;
|
||||
}
|
||||
|
||||
export const useSettingsStore = create<SettingsState>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
themePreference: 'system',
|
||||
language: 'system',
|
||||
biometricsEnabled: false,
|
||||
notificationPollSeconds: 60,
|
||||
setThemePreference: (themePreference) => set({ themePreference }),
|
||||
setLanguage: (language) => set({ language }),
|
||||
setBiometricsEnabled: (biometricsEnabled) => set({ biometricsEnabled }),
|
||||
setNotificationPollSeconds: (notificationPollSeconds) => set({ notificationPollSeconds }),
|
||||
}),
|
||||
{
|
||||
name: 'gitea-native:settings:v1',
|
||||
storage: createJSONStorage(() => AsyncStorage),
|
||||
partialize: (state) => ({
|
||||
themePreference: state.themePreference,
|
||||
language: state.language,
|
||||
biometricsEnabled: state.biometricsEnabled,
|
||||
notificationPollSeconds: state.notificationPollSeconds,
|
||||
}),
|
||||
},
|
||||
),
|
||||
);
|
||||
Reference in new issue
Block a user