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:
commit
e9fee8aad3
1 changed files with 13 additions and 1 deletions
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue