Skip to content

Commit 493d0b4

Browse files
committed
feat: use i18n for subprofession in quick editor
1 parent 6a5edd7 commit 493d0b4

File tree

1 file changed

+39
-14
lines changed

1 file changed

+39
-14
lines changed

src/components/editor/operator/sheet/sheetOperator/ProfClassificationWithFilters.tsx

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { Button, Divider, H4, H5 } from '@blueprintjs/core'
22
import { Popover2 } from '@blueprintjs/popover2'
33

44
import clsx from 'clsx'
5+
import { useAtomValue } from 'jotai'
56
import { FC, ImgHTMLAttributes, useEffect, useMemo } from 'react'
67

78
import { PROFESSIONS } from 'models/operator'
89

9-
import { useTranslation } from '../../../../../i18n/i18n'
10+
import { languageAtom, useTranslation } from '../../../../../i18n/i18n'
1011
import {
1112
DEFAULTPROFID,
1213
DEFAULTSUBPROFID,
@@ -25,6 +26,7 @@ export const ProfClassificationWithFilters: FC<
2526
ProfClassificationWithFiltersProp
2627
> = ({ toTop }) => {
2728
const t = useTranslation()
29+
const language = useAtomValue(languageAtom)
2830
const {
2931
useProfFilterState: [{ selectedProf }, setProfFilter],
3032
usePaginationFilterState: [_, setPaginationFilter],
@@ -36,19 +38,31 @@ export const ProfClassificationWithFilters: FC<
3638
id: DEFAULTPROFID.ALL,
3739
name: t.components.editor.operator.sheet.sheetOperator
3840
.ProfClassificationWithFilters.all,
41+
name_en:
42+
t.components.editor.operator.sheet.sheetOperator
43+
.ProfClassificationWithFilters.all,
3944
sub: [],
4045
},
4146
{
4247
id: DEFAULTPROFID.FAV,
4348
name: t.components.editor.operator.sheet.sheetOperator
4449
.ProfClassificationWithFilters.favorites,
50+
name_en:
51+
t.components.editor.operator.sheet.sheetOperator
52+
.ProfClassificationWithFilters.favorites,
4553
sub: [],
4654
},
47-
...PROFESSIONS,
55+
...PROFESSIONS.map((profession) => ({
56+
...profession,
57+
name_en: profession.name_en || profession.name,
58+
})),
4859
{
4960
id: DEFAULTPROFID.OTHERS,
5061
name: t.components.editor.operator.sheet.sheetOperator
5162
.ProfClassificationWithFilters.others,
63+
name_en:
64+
t.components.editor.operator.sheet.sheetOperator
65+
.ProfClassificationWithFilters.others,
5266
sub: [],
5367
},
5468
],
@@ -60,11 +74,17 @@ export const ProfClassificationWithFilters: FC<
6074
id: DEFAULTSUBPROFID.ALL,
6175
name: t.components.editor.operator.sheet.sheetOperator
6276
.ProfClassificationWithFilters.all,
77+
name_en:
78+
t.components.editor.operator.sheet.sheetOperator
79+
.ProfClassificationWithFilters.all,
6380
},
6481
{
6582
id: DEFAULTSUBPROFID.SELECTED,
6683
name: t.components.editor.operator.sheet.sheetOperator
6784
.ProfClassificationWithFilters.selected,
85+
name_en:
86+
t.components.editor.operator.sheet.sheetOperator
87+
.ProfClassificationWithFilters.selected,
6888
},
6989
...(formattedProfessions.find(({ id }) => id === selectedProf[0])?.sub ||
7090
[]),
@@ -95,16 +115,16 @@ export const ProfClassificationWithFilters: FC<
95115
return (
96116
<div className="flex flex-row-reverse relative h-full">
97117
<ul className="h-full flex flex-col w-6 sm:w-12">
98-
{formattedProfessions.map(({ id, name }) => (
118+
{formattedProfessions.map((prof) => (
99119
<ProfIcon
100-
key={id}
101-
profId={id}
102-
name={name}
103-
selected={selectedProf.includes(id)}
120+
key={prof.id}
121+
profId={prof.id}
122+
name={language === 'en' && prof.name_en ? prof.name_en : prof.name}
123+
selected={selectedProf.includes(prof.id)}
104124
onProfClick={() =>
105125
setProfFilter((prev) => ({
106126
...prev,
107-
selectedProf: [id, DEFAULTSUBPROFID.ALL],
127+
selectedProf: [prof.id, DEFAULTSUBPROFID.ALL],
108128
}))
109129
}
110130
/>
@@ -113,22 +133,27 @@ export const ProfClassificationWithFilters: FC<
113133
<Divider className="mr-0" />
114134
<div className="h-full flex flex-col justify-center items-end absolute right-full sm:relative sm:left-0">
115135
<ul>
116-
{subProfs.map(({ id, name }) => (
117-
<li key={id}>
136+
{subProfs.map((subProf) => (
137+
<li key={subProf.id}>
118138
<H4
119139
className={clsx(
120140
'truncate cursor-pointer my-3 opacity-50 hover:underline hover:opacity-90',
121-
selectedProf.includes(id) && '!opacity-100 underline',
122-
name.length > 3 && '!text-base',
141+
selectedProf.includes(subProf.id) && '!opacity-100 underline',
142+
(language === 'en' && subProf.name_en
143+
? subProf.name_en
144+
: subProf.name
145+
).length > 3 && '!text-base',
123146
)}
124147
onClick={() =>
125148
setProfFilter(({ selectedProf, ...rest }) => ({
126-
selectedProf: [selectedProf[0], id],
149+
selectedProf: [selectedProf[0], subProf.id],
127150
...rest,
128151
}))
129152
}
130153
>
131-
{name}
154+
{language === 'en' && subProf.name_en
155+
? subProf.name_en
156+
: subProf.name}
132157
</H4>
133158
</li>
134159
))}

0 commit comments

Comments
 (0)