Merge branch 'search-ux' into 'develop'

Remove search term after navigating away from Search page

See merge request soapbox-pub/soapbox!2498
This commit is contained in:
Chewbacca 2023-05-08 16:11:15 +00:00
commit e9fee8aad3

View file

@ -1,6 +1,6 @@
import clsx from 'clsx';
import debounce from 'lodash/debounce';
import React, { useCallback } from 'react';
import React, { useCallback, useEffect } from 'react';
import { defineMessages, useIntl } from 'react-intl';
import { useHistory } from 'react-router-dom';
@ -135,6 +135,18 @@ const Search = (props: ISearch) => {
componentProps.autoSelect = false;
}
useEffect(() => {
return () => {
const newPath = history.location.pathname;
const shouldPersistSearch = !!newPath.match(/@.+\/posts\/\d+/g)
|| !!newPath.match(/\/tags\/.+/g);
if (!shouldPersistSearch) {
dispatch(changeSearch(''));
}
};
}, []);
return (
<div className='w-full'>
<label htmlFor='search' className='sr-only'>{intl.formatMessage(messages.placeholder)}</label>