feat(client): i18n copy + reco lang refresh + home polish

This commit is contained in:
1
2026-02-02 20:11:09 +08:00
parent 64b8352ad3
commit 996999453a
19 changed files with 594 additions and 188 deletions

View File

@@ -1,6 +1,7 @@
import { useState } from 'react';
import { useMemo, useState } from 'react';
import { useRouter } from 'expo-router';
import * as Notifications from 'expo-notifications';
import { useTranslation } from 'react-i18next';
import { OnboardingLayout } from '@/components/onboarding/OnboardingLayout';
import { NameInputStep } from '@/components/onboarding/NameInputStep';
import { SelectionStep } from '@/components/onboarding/SelectionStep';
@@ -16,64 +17,37 @@ import {
setRecoFeedCache,
} from '@/src/storage/appStorage';
const STEPS = [
{ id: 'name', type: 'name', title: '我可以怎么称呼你?' },
{
id: 'status',
type: 'selection',
title: '媽媽的狀態?',
options: [
{ id: 'pregnant', label: '懷孕中/準備成為媽媽' },
{ id: 'has_kids', label: '已經有孩子' },
{ id: 'no_fill', label: '不想填寫' },
]
},
{
id: 'emotion',
type: 'selection',
title: '當下情緒狀態?',
options: [
{ id: 'happy', label: '愉悅、滿足' },
{ id: 'calm', label: '平靜、安穩' },
{ id: 'stressed', label: '被壓得有點喘不過氣' },
{ id: 'low', label: '情緒低落' },
]
},
{
id: 'influence',
type: 'selection',
title: '是什麼影響了你最近的感受?',
options: [
{ id: 'family', label: '家庭與孩子' },
{ id: 'work', label: '工作或學習' },
{ id: 'relationship', label: '親密關係' },
{ id: 'friends', label: '朋友與人際' },
{ id: 'health', label: '身心健康' },
]
},
{
id: 'support',
type: 'selection',
title: '最需要什麼支持?',
options: [
{ id: 'emotional', label: '情緒支持' },
{ id: 'parenting', label: '育兒壓力' },
{ id: 'self_worth', label: '自我價值' },
{ id: 'anxiety', label: '焦慮舒緩' },
{ id: 'balance', label: '休息與平衡' },
]
},
{ id: 'reminder', type: 'reminder', title: '你需要每天几次提醒?' },
type Step =
| { id: 'name'; type: 'name' }
| { id: 'status' | 'emotion' | 'influence' | 'support'; type: 'selection'; optionIds: string[] }
| { id: 'reminder'; type: 'reminder' };
const STEPS: Step[] = [
{ id: 'name', type: 'name' },
{ id: 'status', type: 'selection', optionIds: ['pregnant', 'has_kids', 'no_fill'] },
{ id: 'emotion', type: 'selection', optionIds: ['happy', 'calm', 'stressed', 'low'] },
{ id: 'influence', type: 'selection', optionIds: ['family', 'work', 'relationship', 'friends', 'health'] },
{ id: 'support', type: 'selection', optionIds: ['emotional', 'parenting', 'self_worth', 'anxiety', 'balance'] },
{ id: 'reminder', type: 'reminder' },
];
export default function OnboardingScreen() {
const router = useRouter();
const { t, i18n } = useTranslation();
const [stepIndex, setStepIndex] = useState(0);
const [name, setName] = useState('');
const [selections, setSelections] = useState<Record<string, string[]>>({});
const [reminderTimes, setReminderTimes] = useState(3);
const currentStep = STEPS[stepIndex];
const currentTitle = useMemo(() => t(`onboardingSurvey.steps.${currentStep.id}.title`), [t, currentStep.id]);
const currentOptions = useMemo(() => {
if (currentStep.type !== 'selection') return [];
return currentStep.optionIds.map((optId) => ({
id: optId,
label: t(`onboardingSurvey.steps.${currentStep.id}.options.${optId}`),
}));
}, [t, currentStep]);
async function onFinish() {
// 请求推送权限
@@ -89,6 +63,7 @@ export default function OnboardingScreen() {
// Onboarding 结束后预拉取一次 Feed 文案(失败不阻塞进入首页)
try {
const lang = i18n.language?.toLowerCase().startsWith('zh') ? 'tc' : 'en';
const { items, meta } = await fetchRecoFeed({
k: 30,
user_profile: {
@@ -106,6 +81,7 @@ export default function OnboardingScreen() {
await setRecoFeedCache({
saved_at: new Date().toISOString(),
lang,
items: items.map((x) => ({ content_id: x.content_id, text: x.text })),
meta: meta as Record<string, unknown>,
});
@@ -150,11 +126,13 @@ export default function OnboardingScreen() {
router.replace('/(app)/home');
};
// 题目为选:再次点击可取消;选择其他选项会替换为唯一选项
// 题目为选:点击切换选中状态
const handleToggleSelection = (id: string) => {
setSelections(prev => {
const currentIds = prev[currentStep.id] || [];
const nextIds = currentIds.includes(id) ? [] : [id];
const nextIds = currentIds.includes(id)
? currentIds.filter(i => i !== id)
: [...currentIds, id];
return { ...prev, [currentStep.id]: nextIds };
});
};
@@ -166,7 +144,7 @@ export default function OnboardingScreen() {
return (
<OnboardingLayout
title={currentStep.title}
title={currentTitle}
currentStep={stepIndex}
totalSteps={STEPS.length - 1}
onSkip={onSkip}
@@ -183,11 +161,10 @@ export default function OnboardingScreen() {
{currentStep.type === 'selection' && (
<SelectionStep
options={currentStep.options!}
options={currentOptions}
selectedIds={selections[currentStep.id] || []}
onToggle={handleToggleSelection}
onNext={onNext}
onSkip={handleSkipStep}
/>
)}