Skip to content

Commit 861f91a

Browse files
committed
add: special question suggess
1 parent 6f08437 commit 861f91a

File tree

4 files changed

+64
-28
lines changed

4 files changed

+64
-28
lines changed

src/data/data.json

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,24 @@
145145
"ja": "<span style=\"color:#49da54;\"><strong>心身のストレスを軽減する: </strong></span>毎日10分間の深呼吸や瞑想、リラックスできる音楽を聴くことで、不安を和らげ、集中力を高め、精神的なバランスを取り戻すのに役立ちます。"
146146
}
147147
},
148+
{
149+
"id": "健康加餐",
150+
"lang": {
151+
"en": "Add one healthy snack per day, such as nuts, eggs, yogurt, or oats. Increase your intake of whole grains and quality protein during meals. Try tracking your diet to ensure your daily calorie intake slightly exceeds your basal metabolic rate.",
152+
"zh": "每天增加1餐健康加餐,如坚果、鸡蛋、酸奶或燕麦。三餐中适量增加主食与优质蛋白摄入。可尝试记录饮食,确保每日摄入热量略高于基础代谢水平",
153+
"zh-HK": "每天增加1餐健康加餐,如堅果、雞蛋、優格或燕麥。三餐中適量增加主食與優質蛋白的攝取。可以嘗試記錄飲食,確保每日攝取的熱量略高於基礎代謝率。",
154+
"ja": "毎日1回、ナッツ、卵、ヨーグルト、オートミールなどの健康的な間食を追加しましょう。3食の中では主食と良質なたんぱく質を適度に増やしてください。食事内容を記録し、1日の摂取カロリーが基礎代謝量を少し上回るよう意識すると良いです。"
155+
}
156+
},
157+
{
158+
"id": "安排休息",
159+
"lang": {
160+
"en": "Take at least two rest days each week. Consider replacing some intense workouts with stretching or walking. After exercise, make sure to replenish nutrients and stay hydrated to help your body recover.",
161+
"zh": "每周安排不少于2天的休息日,可将部分剧烈运动替换为拉伸或散步。运动后注意补充营养与水分,保持身体恢复平衡",
162+
"zh-HK": "每週安排不少於2天的休息日,可將部分劇烈運動替換為伸展或散步。運動後注意補充營養與水分,幫助身體恢復平衡。",
163+
"ja": "週に最低2日は休息日を設け、激しい運動の一部をストレッチや散歩に置き換えることを検討しましょう。運動後は栄養と水分をしっかり補給し、体のバランスを整えることが大切です。"
164+
}
165+
},
148166
{
149167
"id": "UI_SUGGESS_GOOD",
150168
"lang": {
@@ -4813,7 +4831,8 @@
48134831
-1,
48144832
-3
48154833
]
4816-
}
4834+
},
4835+
"suggess": "special1"
48174836
},
48184837
{
48194838
"opt": "Q1健康",
@@ -4856,7 +4875,10 @@
48564875
}
48574876
}
48584877
],
4859-
"suggess": "控制健康体重"
4878+
"suggess": {
4879+
"default": "控制健康体重",
4880+
"special1": "健康加餐"
4881+
}
48604882
},
48614883
{
48624884
"question": "Q2你的运动频率如何",
@@ -4909,10 +4931,14 @@
49094931
-1,
49104932
-4
49114933
]
4912-
}
4934+
},
4935+
"suggess": "special1"
49134936
}
49144937
],
4915-
"suggess": "定期运动"
4938+
"suggess": {
4939+
"default": "定期运动",
4940+
"special1": "安排休息"
4941+
}
49164942
},
49174943
{
49184944
"question": "Q3你的睡眠是否充足",
@@ -4958,7 +4984,9 @@
49584984
}
49594985
}
49604986
],
4961-
"suggess": "保持健康睡眠"
4987+
"suggess": {
4988+
"default": "保持健康睡眠"
4989+
}
49624990
},
49634991
{
49644992
"question": "Q4你的饮酒频率是",
@@ -5011,7 +5039,9 @@
50115039
}
50125040
}
50135041
],
5014-
"suggess": "戒酒"
5042+
"suggess": {
5043+
"default": "戒酒"
5044+
}
50155045
},
50165046
{
50175047
"question": "Q5你的吸烟频率是",
@@ -5074,7 +5104,9 @@
50745104
}
50755105
}
50765106
],
5077-
"suggess": "戒烟"
5107+
"suggess": {
5108+
"default": "戒烟"
5109+
}
50785110
},
50795111
{
50805112
"question": "Q6你的压力与情绪状态如何",
@@ -5117,7 +5149,9 @@
51175149
}
51185150
}
51195151
],
5120-
"suggess": "降低身心压力"
5152+
"suggess": {
5153+
"default": "降低身心压力"
5154+
}
51215155
}
51225156
],
51235157
"random": [
@@ -5218,6 +5252,6 @@
52185252
}
52195253
}
52205254
},
5221-
"version": "2025-03-20T11:39:43.547Z",
5222-
"timestamp": "2025-03-20T11:39:43.547Z"
5255+
"version": "2025-05-07T06:13:30.560Z",
5256+
"timestamp": "2025-05-07T06:13:30.560Z"
52235257
}

src/data/data.xlsx

1.31 KB
Binary file not shown.

src/data/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,16 @@ export type Alts = AltNormal | AltRandom
5353
export interface QuestionOption {
5454
opt: string
5555
alt: Alts
56+
suggess?: string
5657
}
5758
export interface Question {
5859
id: number
5960
question: string
6061
options: QuestionOption[]
61-
suggess: string
62+
suggess: {
63+
default: string
64+
[key: string]: string
65+
}
6266
}
6367

6468
export interface Random {
@@ -227,10 +231,7 @@ interface AltsData {
227231
}
228232

229233
export async function getQuestions(country: Country, age: Age, sex: Sex) {
230-
const questions = query('question').map(({ options, ...other }) => ({
231-
options: options.map(({ opt }) => opt),
232-
...other,
233-
}))
234+
const questions = query('question')
234235
const q = await database.get<AltsData>('questions', [
235236
country.value,
236237
age.value,

src/pages/ResultPage.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState, useEffect } from 'react'
22
import { useAnimate } from 'motion/react'
33
import { useLanguage, useCountdown } from '@/hooks'
4-
import type { Country, Age, Sex, Achivement } from '@/data'
4+
import type { Country, Age, Sex, Achivement, Question } from '@/data'
55
import {
66
query,
77
check,
@@ -29,12 +29,6 @@ export interface ResultPageProps {
2929
onBack: () => void
3030
}
3131

32-
interface QuestionItem {
33-
question: string
34-
options: string[]
35-
suggess: string
36-
}
37-
3832
export function ResultPage({
3933
options: { country, age, sex, start },
4034
onBack,
@@ -45,7 +39,7 @@ export function ResultPage({
4539
const [alter, setAlter] = useState(0)
4640
const [time, setTime] = useState(0)
4741
const [countdown, setCountdown] = useCountdown(0, start)
48-
const [questions, setQuestions] = useState<QuestionItem[]>([])
42+
const [questions, setQuestions] = useState<Question[]>([])
4943
const [alts, setAlts] = useState<number[][]>([])
5044
const [cursor, setCursor] = useState(0)
5145
const [selected, setSelected] = useState<number[]>([])
@@ -201,9 +195,9 @@ export function ResultPage({
201195
toast(
202196
<ul style={{ lineHeight: 1.2 }}>
203197
{selected
204-
.map((s, i) => ({ i, a: alts[i][s] }))
198+
.map((s, i) => ({ s, i, a: alts[i][s] }))
205199
.filter(a => a.a < 0)
206-
.map(({ i }, n) => (
200+
.map(({ s, i }, n) => (
207201
<li
208202
key={i}
209203
style={{
@@ -216,7 +210,12 @@ export function ResultPage({
216210
</span>
217211
<span
218212
dangerouslySetInnerHTML={{
219-
__html: t(questions[i].suggess),
213+
__html: t(
214+
questions[i].suggess[
215+
questions[i].options[s].suggess ??
216+
'default'
217+
]
218+
),
220219
}}
221220
/>
222221
</li>
@@ -308,13 +307,15 @@ export function ResultPage({
308307
type="radio"
309308
id={`option${i}`}
310309
name={`question${cursor}`}
311-
value={opt}
310+
value={opt.opt}
312311
checked={selected[cursor] === i}
313312
onChange={e =>
314313
e.target.checked && onSelect(i)
315314
}
316315
/>
317-
<label htmlFor={`option${i}`}>{t(opt)}</label>
316+
<label htmlFor={`option${i}`}>
317+
{t(opt.opt)}
318+
</label>
318319
</li>
319320
))}
320321
</ul>

0 commit comments

Comments
 (0)