Skip to content

Commit 5e6a83c

Browse files
committed
add: suggess
1 parent 30e3493 commit 5e6a83c

File tree

6 files changed

+160
-21
lines changed

6 files changed

+160
-21
lines changed

src/data/data.json

Lines changed: 104 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,87 @@
8282
"ja": "世界銀行\r\n世界保健機関 (WHO)\r\n健康指標と評価研究所 (IHME)"
8383
}
8484
},
85+
{
86+
"id": "UI_SUGGESS",
87+
"lang": {
88+
"en": "Health advice",
89+
"zh": "健康建议",
90+
"zh-HK": "健康建議",
91+
"ja": "健康アドバイス"
92+
}
93+
},
94+
{
95+
"id": "控制健康体重",
96+
"lang": {
97+
"en": "Maintain a healthy weight",
98+
"zh": "控制健康体重",
99+
"zh-HK": "維持健康體重",
100+
"ja": "健康的な体重を維持する"
101+
}
102+
},
103+
{
104+
"id": "定期运动",
105+
"lang": {
106+
"en": "Exercise regularly",
107+
"zh": "定期运动",
108+
"zh-HK": "定期運動",
109+
"ja": "定期的に運動する"
110+
}
111+
},
112+
{
113+
"id": "保持健康睡眠",
114+
"lang": {
115+
"en": "Ensure adequate and healthy sleep",
116+
"zh": "保持健康睡眠",
117+
"zh-HK": "保持健康睡眠",
118+
"ja": "健康的な睡眠を確保する"
119+
}
120+
},
121+
{
122+
"id": "戒酒",
123+
"lang": {
124+
"en": "Quit drinking alcohol",
125+
"zh": "戒酒",
126+
"zh-HK": "戒酒",
127+
"ja": "アルコールを断つ"
128+
}
129+
},
130+
{
131+
"id": "戒烟",
132+
"lang": {
133+
"en": "Quit smoking",
134+
"zh": "戒烟",
135+
"zh-HK": "戒煙",
136+
"ja": "喫煙を断つ"
137+
}
138+
},
139+
{
140+
"id": "降低身心压力",
141+
"lang": {
142+
"en": "Reduce physical and mental stress",
143+
"zh": "降低身心压力",
144+
"zh-HK": "降低身心壓力",
145+
"ja": "身体的および精神的ストレスを減らす "
146+
}
147+
},
148+
{
149+
"id": "UI_SUGGESS_GOOD",
150+
"lang": {
151+
"en": "Your lifestyle habits are very healthy\r\nPlease continue to maintain them",
152+
"zh": "你的生活习惯很健康,请继续保持",
153+
"zh-HK": "你的生活習慣很健康,請繼續保持",
154+
"ja": "現在の生活習慣は極めて健全です\r\nこの良好な状態を維持し続けてください"
155+
}
156+
},
157+
{
158+
"id": "UI_SUGGESS_EXTEND",
159+
"lang": {
160+
"en": "Your life expectancy will increase by: {years} years",
161+
"zh": "你的寿命将延长:{years}年",
162+
"zh-HK": "您的壽命將延長:{years}年",
163+
"ja": "あなたの寿命は{years}年延びます"
164+
}
165+
},
85166
{
86167
"id": "UI_TITLE",
87168
"lang": {
@@ -94,16 +175,16 @@
94175
{
95176
"id": "UI_SUB_TITLE",
96177
"lang": {
97-
"en": "How much time do you have left in your life?",
178+
"en": "How Much Time Is Left in Your Life?",
98179
"zh": "你的生命还剩下多久?",
99-
"zh-HK": "你的生命還剩下多久",
100-
"ja": "あなたの人生にはあとどれくらいの時間が残っていますか"
180+
"zh-HK": "你的生命還剩下多長時間",
181+
"ja": "あなたの命はあとどれくらい残っているのか"
101182
}
102183
},
103184
{
104185
"id": "UI_START",
105186
"lang": {
106-
"en": "Start countdown",
187+
"en": "Start the Countdown",
107188
"zh": "开始倒计时",
108189
"zh-HK": "開始倒計時",
109190
"ja": "カウントダウン開始"
@@ -112,28 +193,28 @@
112193
{
113194
"id": "UI_COUNTDOWN",
114195
"lang": {
115-
"en": "Your life is left:",
196+
"en": "Your Life Is Left With:",
116197
"zh": "你的生命还剩下:",
117198
"zh-HK": "你的生命還剩下:",
118-
"ja": "君の残る命は"
199+
"ja": "あなたの命に残された時間"
119200
}
120201
},
121202
{
122203
"id": "UI_DEATH",
123204
"lang": {
124-
"en": "You can live to {MM}/{DD}/{YYYY} ",
205+
"en": "You can live until {MM}/{DD}/{YYYY} ",
125206
"zh": "你可以活到{YYYY}年{MM}月{DD}日",
126207
"zh-HK": "你可以活到{YYYY}年{MM}月{DD}日",
127-
"ja": "君は{YYYY}年{MM}月{DD}日まで生きられます"
208+
"ja": "あなたは{YYYY}年{MM}月{DD}日まで生きることができます"
128209
}
129210
},
130211
{
131212
"id": "UI_PERCENT_BEFORE",
132213
"lang": {
133-
"en": "Better than {percent}% of people",
214+
"en": "Beat {percent}% of people",
134215
"zh": "击败了{percent}%的人",
135216
"zh-HK": "擊敗了{percent}%的人",
136-
"ja": "{pe​​rcent}% の人に勝ちました"
217+
"ja": "{percent}% の人に勝った"
137218
}
138219
},
139220
{
@@ -4774,7 +4855,8 @@
47744855
]
47754856
}
47764857
}
4777-
]
4858+
],
4859+
"suggess": "控制健康体重"
47784860
},
47794861
{
47804862
"question": "Q2你的运动频率如何",
@@ -4829,7 +4911,8 @@
48294911
]
48304912
}
48314913
}
4832-
]
4914+
],
4915+
"suggess": "定期运动"
48334916
},
48344917
{
48354918
"question": "Q3你的睡眠是否充足",
@@ -4874,7 +4957,8 @@
48744957
]
48754958
}
48764959
}
4877-
]
4960+
],
4961+
"suggess": "保持健康睡眠"
48784962
},
48794963
{
48804964
"question": "Q4你的饮酒频率是",
@@ -4926,7 +5010,8 @@
49265010
]
49275011
}
49285012
}
4929-
]
5013+
],
5014+
"suggess": "戒酒"
49305015
},
49315016
{
49325017
"question": "Q5你的吸烟频率是",
@@ -4988,7 +5073,8 @@
49885073
"args": -15
49895074
}
49905075
}
4991-
]
5076+
],
5077+
"suggess": "戒烟"
49925078
},
49935079
{
49945080
"question": "Q6你的压力与情绪状态如何",
@@ -5030,7 +5116,8 @@
50305116
]
50315117
}
50325118
}
5033-
]
5119+
],
5120+
"suggess": "降低身心压力"
50345121
}
50355122
],
50365123
"random": [
@@ -5066,7 +5153,7 @@
50665153
},
50675154
"lifeStd": {
50685155
"key": "lifeStd",
5069-
"value": 10
5156+
"value": 12
50705157
},
50715158
"year": {
50725159
"key": "year",

src/data/data.xlsx

1.08 KB
Binary file not shown.

src/data/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export interface Question {
5858
id: number
5959
question: string
6060
options: QuestionOption[]
61+
suggess: string
6162
}
6263

6364
export interface Random {
@@ -226,9 +227,9 @@ interface AltsData {
226227
}
227228

228229
export async function getQuestions(country: Country, age: Age, sex: Sex) {
229-
const questions = query('question').map(({ question, options }) => ({
230-
question,
230+
const questions = query('question').map(({ options, ...other }) => ({
231231
options: options.map(({ opt }) => opt),
232+
...other,
232233
}))
233234
const q = await database.get<AltsData>('questions', [
234235
country.value,

src/hooks/useLanguage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface FormatData {
1515
}
1616
function format(template: string, formatData: FormatData) {
1717
return template.replace(/\{([^{}]+)\}/g, (match, key) => {
18-
return (formatData[key] as string) || match
18+
return (formatData[key.trim()] as string) || match
1919
})
2020
}
2121

src/index.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ svg {
4848
}
4949
}
5050

51+
.btn.success {
52+
border-color: #8f8;
53+
}
54+
.btn.success:hover {
55+
border-color: #4f4;
56+
}
57+
5158
.btn:hover {
5259
border-color: #08f;
5360
}

src/pages/ResultPage.tsx

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface ResultPageProps {
3232
interface QuestionItem {
3333
question: string
3434
options: string[]
35+
suggess: string
3536
}
3637

3738
export function ResultPage({
@@ -180,6 +181,43 @@ export function ResultPage({
180181
)
181182
}
182183

184+
const toastSuggess = () => {
185+
if (altWorst >= 0) {
186+
toast(t('UI_SUGGESS_GOOD'))
187+
return
188+
}
189+
190+
const { alt } = processAlt(
191+
base,
192+
alts.map(a => Math.max(...a))
193+
)
194+
195+
toast(
196+
<ul>
197+
{selected
198+
.map((s, i) => ({ i, a: alts[i][s] }))
199+
.filter(a => a.a < 0)
200+
.map(({ i }, n) => (
201+
<li key={i}>
202+
{n + 1}. {t(questions[i].suggess)}
203+
</li>
204+
))}
205+
{
206+
<li>
207+
<b>
208+
{t('UI_SUGGESS_EXTEND', {
209+
years: (alt - alter)
210+
.toFixed(2)
211+
.replace('.00', ''),
212+
})}
213+
</b>
214+
</li>
215+
}
216+
</ul>
217+
)
218+
selected.filter(a => a >= 0).map((s, i) => alts[i][s])
219+
}
220+
183221
return (
184222
<div id="result">
185223
<div className="btn back" onClick={onBack}>
@@ -266,7 +304,13 @@ export function ResultPage({
266304
</div>
267305
)}
268306
{cursor === questions.length - 1 ? (
269-
<div className="btn disabled">{t('UI_NQ')}</div>
307+
selected.includes(-1) ? (
308+
<div className="btn disabled">{t('UI_NQ')}</div>
309+
) : (
310+
<div className="btn success" onClick={toastSuggess}>
311+
{t('UI_SUGGESS')}
312+
</div>
313+
)
270314
) : (
271315
<div
272316
className="btn"

0 commit comments

Comments
 (0)