Skip to content

Commit 89afad0

Browse files
committed
fix: adjust tag order in userTagsMemo and ensure MenuDivider appears correctly for 'global' tag
1 parent 3f00234 commit 89afad0

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/features/cards/components/CardSettings.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ type CardSettingsProps = {
2525
}
2626

2727
const DEFAULT_SORT_OPTIONS = [{ label: 'Newest', value: 'published_at', icon: <MdDateRange /> }]
28+
const SPECIAL_LABELS = ['global', MY_LANGUAGES_OPTION.label.toLowerCase()]
29+
2830
export const CardSettings = ({
2931
id,
3032
url,
@@ -46,10 +48,10 @@ export const CardSettings = ({
4648
const newTags = userSelectedTags.sort((a, b) => a.label.localeCompare(b.label))
4749
let tags = [...newTags]
4850
if (globalTag) {
49-
tags = [globalTag, ...tags]
51+
tags = [...tags, globalTag]
5052
}
5153

52-
tags = [MY_LANGUAGES_OPTION, ...tags]
54+
tags = [...tags, MY_LANGUAGES_OPTION]
5355
return tags
5456
}, [userSelectedTags, globalTag])
5557

@@ -63,6 +65,11 @@ export const CardSettings = ({
6365
window.open(link, openLinksNewTab ? '_blank' : '_self')
6466
}, [url, openLinksNewTab])
6567

68+
const firstSpecialIndex = useMemo(
69+
() => userTagsMemo.findIndex((tag) => SPECIAL_LABELS.includes(tag.label.toLowerCase())),
70+
[userTagsMemo]
71+
)
72+
6673
return (
6774
<Menu
6875
menuButton={<GoGear />}
@@ -80,8 +87,9 @@ export const CardSettings = ({
8087
<AiOutlineCode /> Language
8188
</span>
8289
}>
83-
{userTagsMemo.map((tag) => (
90+
{userTagsMemo.map((tag, i) => (
8491
<>
92+
{i === firstSpecialIndex && <MenuDivider />}
8593
<MenuItem
8694
className={`menuItem`}
8795
type="radio"
@@ -93,7 +101,6 @@ export const CardSettings = ({
93101
}}>
94102
{tag.label}
95103
</MenuItem>
96-
{tag.label.toLowerCase() === 'global' && <MenuDivider />}
97104
</>
98105
))}
99106
</SubMenu>

0 commit comments

Comments
 (0)