- portable UTF-8 base64 helpers (Hermes-safe), used for file round-trips - endpoints: updateFileContents, createFileContents, createPull - hooks: useCommitFile (invalidates repo cache), useCreatePull - FileEdit screen: native monospace editor, dirty/discard, branch picker, commit-to-new-branch, protected-branch handling, post-commit PR creation; stale-SHA 409 surfaces as a conflict message - settings: editor URL template; repo overview 'Open in editor' (no token) - tests: base64 round-trips (accents/emoji), editor URL expansion
63 lines
2.4 KiB
TypeScript
63 lines
2.4 KiB
TypeScript
/**
|
|
* 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;
|
|
/**
|
|
* Optional editor/IDE URL template for the "Open in editor" action.
|
|
* Placeholders: {owner} {repo} {path} {cloneUrl}. Empty hides the action.
|
|
* Opened in the system browser/app only — the API token is never appended.
|
|
*/
|
|
editorUrlTemplate: string;
|
|
setThemePreference: (preference: ThemePreference) => void;
|
|
setLanguage: (language: LanguagePreference) => void;
|
|
setBiometricsEnabled: (enabled: boolean) => void;
|
|
setNotificationPollSeconds: (seconds: number) => void;
|
|
setEditorUrlTemplate: (template: string) => void;
|
|
}
|
|
|
|
export const useSettingsStore = create<SettingsState>()(
|
|
persist(
|
|
(set) => ({
|
|
themePreference: 'system',
|
|
language: 'system',
|
|
biometricsEnabled: false,
|
|
notificationPollSeconds: 60,
|
|
editorUrlTemplate: '',
|
|
setThemePreference: (themePreference) => set({ themePreference }),
|
|
setLanguage: (language) => set({ language }),
|
|
setBiometricsEnabled: (biometricsEnabled) => set({ biometricsEnabled }),
|
|
setNotificationPollSeconds: (notificationPollSeconds) => set({ notificationPollSeconds }),
|
|
setEditorUrlTemplate: (editorUrlTemplate) => set({ editorUrlTemplate }),
|
|
}),
|
|
{
|
|
name: 'gitea-native:settings:v1',
|
|
storage: createJSONStorage(() => AsyncStorage),
|
|
partialize: (state) => ({
|
|
themePreference: state.themePreference,
|
|
language: state.language,
|
|
biometricsEnabled: state.biometricsEnabled,
|
|
notificationPollSeconds: state.notificationPollSeconds,
|
|
editorUrlTemplate: state.editorUrlTemplate,
|
|
}),
|
|
},
|
|
),
|
|
);
|