feature:基本功能

This commit is contained in:
吕新雨
2026-01-29 19:09:36 +08:00
parent c1a433a469
commit 0dd84b1873
47 changed files with 2978 additions and 219 deletions

View File

@@ -7,10 +7,24 @@ const KEY_ONBOARDING_COMPLETED = 'onboarding.completed';
const KEY_PUSH_PROMPT_STATE = 'push.promptState';
const KEY_CONTENT_REACTIONS = 'content.reactions';
const KEY_FAVORITES_ITEMS = 'favorites.items';
const KEY_CONSENT_ACCEPTED = 'consent.accepted';
const KEY_USER_PROFILE = 'user.profile';
const KEY_UI_THEME_MODE = 'ui.theme.mode';
const KEY_DAILY_REMINDER_SETTINGS = 'dailyReminder.settings';
export type PushPromptState = 'enabled' | 'skipped' | 'unknown';
export type Reaction = 'like' | 'dislike';
export type ReactionsMap = Record<string, Reaction>;
export type ThemeMode = 'scenery' | 'color';
export type UserProfile = {
name?: string;
intents?: string[];
};
export type DailyReminderSettings = {
timesPerDay: number;
pushEnabled: boolean;
};
async function getJson<T>(key: string, fallback: T): Promise<T> {
const raw = await AsyncStorage.getItem(key);
@@ -65,3 +79,50 @@ export async function addFavorite(contentId: string): Promise<void> {
await setJson(KEY_FAVORITES_ITEMS, [...list, contentId]);
}
export async function getConsentAccepted(): Promise<boolean> {
const raw = await AsyncStorage.getItem(KEY_CONSENT_ACCEPTED);
return raw === 'true';
}
export async function setConsentAccepted(accepted: boolean): Promise<void> {
await AsyncStorage.setItem(KEY_CONSENT_ACCEPTED, accepted ? 'true' : 'false');
}
export async function getThemeMode(): Promise<ThemeMode> {
const raw = await AsyncStorage.getItem(KEY_UI_THEME_MODE);
if (raw === 'scenery' || raw === 'color') return raw;
return 'scenery';
}
export async function setThemeMode(mode: ThemeMode): Promise<void> {
await AsyncStorage.setItem(KEY_UI_THEME_MODE, mode);
}
export async function getUserProfile(): Promise<UserProfile> {
return await getJson<UserProfile>(KEY_USER_PROFILE, {});
}
export async function setUserProfile(profile: UserProfile): Promise<void> {
const current = await getUserProfile();
await setJson(KEY_USER_PROFILE, { ...current, ...profile });
}
export async function getDailyReminderSettings(): Promise<DailyReminderSettings> {
const s = await getJson<DailyReminderSettings>(KEY_DAILY_REMINDER_SETTINGS, {
timesPerDay: 3,
pushEnabled: false,
});
const timesPerDay = Number.isFinite(s.timesPerDay) ? s.timesPerDay : 3;
return {
timesPerDay: Math.min(10, Math.max(1, Math.round(timesPerDay))),
pushEnabled: Boolean(s.pushEnabled),
};
}
export async function setDailyReminderSettings(settings: DailyReminderSettings): Promise<void> {
const timesPerDay = Math.min(10, Math.max(1, Math.round(settings.timesPerDay)));
await setJson(KEY_DAILY_REMINDER_SETTINGS, {
timesPerDay,
pushEnabled: Boolean(settings.pushEnabled),
});
}