Skip to content

Commit a799a2b

Browse files
committed
fix: links / uselinks optimization
1 parent 0364dae commit a799a2b

File tree

2 files changed

+26
-54
lines changed

2 files changed

+26
-54
lines changed

src/hooks/useLinks.tsx

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,20 @@
1-
import { Icon as BlueprintIcon } from '@blueprintjs/core'
2-
import { Icon as IconifyIcon } from '@iconify/react'
3-
41
import { useTranslation } from 'react-i18next'
5-
62
import { NAV_CONFIG, SOCIAL_CONFIG } from '../links'
73

84
export const useLinks = () => {
95
const { t } = useTranslation()
106

11-
// Transform static config to dynamic content with translations
12-
const NAV_LINKS = NAV_CONFIG.map((link) => ({
13-
to: link.to,
14-
label: t(link.labelKey),
15-
icon: link.icon,
7+
const NAV_LINKS = NAV_CONFIG.map(({ to, labelKey, icon }) => ({
8+
to,
9+
label: t(labelKey),
10+
icon,
1611
}))
1712

18-
const SOCIAL_LINKS = SOCIAL_CONFIG.map((link) => {
19-
// Create the proper icon based on type
20-
let icon
21-
if (link.iconType === 'blueprint') {
22-
icon = (
23-
<BlueprintIcon icon={link.iconName as any} className="mr-2" size={12} />
24-
)
25-
} else if (link.iconType === 'iconify') {
26-
icon = (
27-
<IconifyIcon
28-
icon={link.iconSource as any}
29-
className="mr-2"
30-
fontSize="12px"
31-
/>
32-
)
33-
}
34-
35-
return {
36-
icon,
37-
href: link.href,
38-
label: t(link.labelKey, link.labelParams),
39-
}
40-
})
13+
const SOCIAL_LINKS = SOCIAL_CONFIG.map(({ icon, href, labelKey, labelParams }) => ({
14+
icon,
15+
href,
16+
label: t(labelKey, labelParams),
17+
}))
4118

42-
return {
43-
NAV_LINKS,
44-
SOCIAL_LINKS,
45-
}
19+
return { NAV_LINKS, SOCIAL_LINKS }
4620
}

src/links.tsx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
import { Icon as BlueprintIcon, IconName } from '@blueprintjs/core'
2+
import { Icon as IconifyIcon } from '@iconify/react'
13
import simpleIconsGitHub from '@iconify/icons-simple-icons/github'
24
import simpleIconsQQ from '@iconify/icons-simple-icons/tencentqq'
35

4-
// Keep only the static configuration data
5-
export const NAV_CONFIG = [
6+
export const NAV_CONFIG: {
7+
to: string
8+
labelKey: string
9+
icon: IconName
10+
}[] = [
611
{
712
to: '/',
813
labelKey: 'links.home',
@@ -17,50 +22,43 @@ export const NAV_CONFIG = [
1722
to: '/about',
1823
labelKey: 'links.about',
1924
icon: 'info-sign',
20-
},
25+
}
2126
]
2227

2328
export const SOCIAL_CONFIG = [
2429
{
25-
iconType: 'blueprint',
26-
iconName: 'globe',
30+
icon: <BlueprintIcon icon="globe" className="mr-2" size={12} />,
2731
href: 'https://maa.plus',
2832
labelKey: 'links.official_site',
2933
},
3034
{
31-
iconType: 'blueprint',
32-
iconName: 'edit',
35+
icon: <BlueprintIcon icon="edit" className="mr-2" size={12} />,
3336
href: 'https://github.com/MaaAssistantArknights/maa-copilot-frontend/issues/new/choose',
3437
labelKey: 'links.feedback',
3538
},
3639
{
37-
iconType: 'iconify',
38-
iconSource: simpleIconsGitHub,
40+
icon: <IconifyIcon icon={simpleIconsGitHub} className="mr-2" fontSize="12px" />,
3941
href: 'https://github.com/MaaAssistantArknights/MaaAssistantArknights',
4042
labelKey: 'links.maa_repo',
4143
},
4244
{
43-
iconType: 'iconify',
44-
iconSource: simpleIconsGitHub,
45+
icon: <IconifyIcon icon={simpleIconsGitHub} className="mr-2" fontSize="12px" />,
4546
href: 'https://github.com/MaaAssistantArknights/maa-copilot-frontend',
4647
labelKey: 'links.frontend_repo',
4748
},
4849
{
49-
iconType: 'iconify',
50-
iconSource: simpleIconsGitHub,
50+
icon: <IconifyIcon icon={simpleIconsGitHub} className="mr-2" fontSize="12px" />,
5151
href: 'https://github.com/MaaAssistantArknights/MaaBackendCenter',
5252
labelKey: 'links.backend_repo',
5353
},
5454
{
55-
iconType: 'iconify',
56-
iconSource: simpleIconsQQ,
55+
icon: <IconifyIcon icon={simpleIconsQQ} className="mr-2" fontSize="12px" />,
5756
href: 'https://jq.qq.com/?_wv=1027&k=ElimpMzQ',
5857
labelKey: 'links.creator_group',
59-
labelParams: { groupNumber: '1169188429' }, // Modifiable group number
58+
labelParams: { groupNumber: '1169188429' },
6059
},
6160
{
62-
iconType: 'iconify',
63-
iconSource: simpleIconsQQ,
61+
icon: <IconifyIcon icon={simpleIconsQQ} className="mr-2" fontSize="12px" />,
6462
href: 'https://ota.maa.plus/MaaAssistantArknights/api/qqgroup/index.html',
6563
labelKey: 'links.sharing_group',
6664
},

0 commit comments

Comments
 (0)