Skip to content

Commit 0a271b3

Browse files
committed
adoptio-asiasanan special case
1 parent e7b1f7f commit 0a271b3

File tree

1 file changed

+48
-17
lines changed

1 file changed

+48
-17
lines changed

frontend/src/components/KeywordListBase.tsx

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ interface KeywordListBaseProps extends KeywordPageType {
99
routeBasePath: string
1010
}
1111

12+
type KeywordRow = KeysType & {
13+
displayKeyword?: string
14+
}
15+
1216
const KeywordListBase = ({ language, apiBasePath, routeBasePath }: KeywordListBaseProps) => {
1317
const [keywords, setKeywords] = useState<KeysType[]>([])
1418
const [lan, setLan] = useState<string>(() => localStorage.getItem('language') || language)
@@ -53,18 +57,6 @@ const KeywordListBase = ({ language, apiBasePath, routeBasePath }: KeywordListBa
5357
getKeywords(path)
5458
}, [path])
5559

56-
57-
const sortedKeywords = useMemo(() => {
58-
const collator = new Intl.Collator('fi', {
59-
usage: 'sort',
60-
sensitivity: 'base',
61-
ignorePunctuation: true,
62-
numeric: false
63-
})
64-
65-
return [...keywords].sort((a, b) => collator.compare(a.keyword, b.keyword))
66-
}, [keywords])
67-
6860
function prepareLink(keyword_id: string) {
6961
return `${routeBasePath}/${encodeURIComponent(keyword_id)}`
7062
}
@@ -76,6 +68,41 @@ const KeywordListBase = ({ language, apiBasePath, routeBasePath }: KeywordListBa
7668
setKeywords([])
7769
}
7870

71+
const displayRows: KeywordRow[] = useMemo(() => {
72+
const rows: KeywordRow[] = keywords.map(k => ({ ...k }))
73+
74+
// Special-case: in Finnish keyword list, show "lapseksiottaminen" also under A as
75+
// "Adoptio / Lapseksiottaminen" (same link/keyword_id).
76+
if (lan === 'fin') {
77+
const target = rows.find(
78+
r => r.keyword.trim().toLocaleLowerCase('fi') === 'lapseksiottaminen'
79+
)
80+
81+
if (target) {
82+
rows.push({
83+
...target,
84+
displayKeyword: 'Adoptio / Lapseksiottaminen',
85+
id: `${target.id}-alias-adoptio`
86+
})
87+
}
88+
}
89+
90+
return rows
91+
}, [keywords, lan])
92+
93+
const sortedRows = useMemo(() => {
94+
const collator = new Intl.Collator('fi', {
95+
usage: 'sort',
96+
sensitivity: 'base',
97+
ignorePunctuation: true,
98+
numeric: false
99+
})
100+
101+
const getLabel = (r: KeywordRow) => r.displayKeyword ?? r.keyword
102+
103+
return [...displayRows].sort((a, b) => collator.compare(getLabel(a), getLabel(b)))
104+
}, [displayRows])
105+
79106
return (
80107
<>
81108
<Helmet>
@@ -89,15 +116,19 @@ const KeywordListBase = ({ language, apiBasePath, routeBasePath }: KeywordListBa
89116
<div style={contentStyle} id="contentdiv">
90117
<div id="contentDiv" style={contentContainerStyle}>
91118
<h1>{title}</h1>
92-
{Array.isArray(sortedKeywords) && sortedKeywords.map(keyword => {
93-
const firstLetter = keyword.keyword.charAt(0).toLocaleUpperCase('fi')
119+
{Array.isArray(sortedRows) && sortedRows.map(row => {
120+
const label = row.displayKeyword ?? row.keyword
121+
const firstLetter = label.charAt(0).toLocaleUpperCase('fi')
94122
const letterChanged = firstLetter !== letter
95123
letter = firstLetter
124+
96125
return (
97-
<div key={`${keyword.id}-upper`}>
126+
<div key={`${row.id}-upper`}>
98127
{letterChanged && <h2>{firstLetter}</h2>}
99-
<div key={keyword.id}>
100-
<a href={prepareLink(keyword.id)}>{keyword.keyword}</a>
128+
<div key={row.id}>
129+
<a href={prepareLink(row.id.replace('-alias-adoptio', ''))}>
130+
{label}
131+
</a>
101132
</div>
102133
</div>
103134
)

0 commit comments

Comments
 (0)