[Glitch] Fix case-insensitive comparison of hashtags to do case-folding

Port 3ed2bf92d0 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Claire 2023-08-17 12:49:52 +02:00
parent fe8d9f6221
commit 2ce03420d6
1 changed files with 3 additions and 3 deletions

View File

@ -15,11 +15,11 @@ const VISIBLE_HASHTAGS = 7;
export const HashtagBar = ({ hashtags, text }) => { export const HashtagBar = ({ hashtags, text }) => {
const renderedHashtags = useMemo(() => { const renderedHashtags = useMemo(() => {
const body = domParser.parseFromString(text, 'text/html').documentElement; const body = domParser.parseFromString(text, 'text/html').documentElement;
return [].filter.call(body.querySelectorAll('a[href]'), link => link.textContent[0] === '#' || (link.previousSibling?.textContent?.[link.previousSibling.textContent.length - 1] === '#')).map(node => node.textContent.toLowerCase()); return [].filter.call(body.querySelectorAll('a[href]'), link => link.textContent[0] === '#' || (link.previousSibling?.textContent?.[link.previousSibling.textContent.length - 1] === '#')).map(node => node.textContent);
}, [text]); }, [text]);
const invisibleHashtags = useMemo(() => ( const invisibleHashtags = useMemo(() => (
hashtags.filter(hashtag => !renderedHashtags.some(textContent => textContent === `#${hashtag.get('name').toLowerCase()}` || textContent === hashtag.get('name').toLowerCase())) hashtags.filter(hashtag => !renderedHashtags.some(textContent => textContent.localeCompare(`#${hashtag.get('name')}`, undefined, { sensitivity: 'accent' }) === 0 || textContent.localeCompare(hashtag.get('name'), undefined, { sensitivity: 'accent' }) === 0))
), [hashtags, renderedHashtags]); ), [hashtags, renderedHashtags]);
const [expanded, setExpanded] = useState(false); const [expanded, setExpanded] = useState(false);