diff --git a/client/src/javascript/components/general/form-elements/TagSelect.tsx b/client/src/javascript/components/general/form-elements/TagSelect.tsx index f6f34bb6..a78eedf1 100644 --- a/client/src/javascript/components/general/form-elements/TagSelect.tsx +++ b/client/src/javascript/components/general/form-elements/TagSelect.tsx @@ -1,6 +1,7 @@ import classnames from 'classnames'; import {FC, ReactNode, ReactNodeArray, useEffect, useRef, useState} from 'react'; import {FormattedMessage} from 'react-intl'; +import sort from 'fast-sort'; import {useKeyPressEvent} from 'react-use'; import type {TorrentProperties} from '@shared/types/Torrent'; @@ -104,33 +105,36 @@ const TagSelect: FC = ({defaultValue, placeholder, id, label, on overlayProps={{isInteractive: false}} ref={menuRef} triggerRef={textboxRef}> - {[...new Set([...Object.keys(TorrentFilterStore.taxonomy.tagCounts), ...selectedTags])].reduce( - (accumulator: ReactNodeArray, tag) => { - if (tag === '') { - return accumulator; - } - - accumulator.push( - { - if (tag === 'untagged') { - setSelectedTags([]); - } else if (selectedTags.includes(tag)) { - setSelectedTags(selectedTags.filter((key) => key !== tag && key !== '')); - } else { - setSelectedTags([...selectedTags.filter((key) => key !== ''), tag]); - } - }}> - {tag === 'untagged' ? : tag} - , - ); + {[ + ...new Set([ + 'untagged', + ...sort(Object.keys(TorrentFilterStore.taxonomy.tagCounts)).asc(), + ...selectedTags, + ]), + ].reduce((accumulator: ReactNodeArray, tag) => { + if (tag === '') { return accumulator; - }, - [], - )} + } + + accumulator.push( + { + if (tag === 'untagged') { + setSelectedTags([]); + } else if (selectedTags.includes(tag)) { + setSelectedTags(selectedTags.filter((key) => key !== tag && key !== '')); + } else { + setSelectedTags([...selectedTags.filter((key) => key !== ''), tag]); + } + }}> + {tag === 'untagged' ? : tag} + , + ); + return accumulator; + }, [])}