Change search popout to not list unusable search options when logged out (#27918)

This commit is contained in:
Claire 2023-11-24 10:27:54 +01:00
parent 49820ecefa
commit 86f15cef66
2 changed files with 9 additions and 3 deletions

View file

@ -274,6 +274,7 @@ class Search extends PureComponent {
} }
_calculateOptions (value) { _calculateOptions (value) {
const { signedIn } = this.context.identity;
const trimmedValue = value.trim(); const trimmedValue = value.trim();
const options = []; const options = [];
@ -298,7 +299,7 @@ class Search extends PureComponent {
const couldBeStatusSearch = searchEnabled; const couldBeStatusSearch = searchEnabled;
if (couldBeStatusSearch) { if (couldBeStatusSearch && signedIn) {
options.push({ key: 'status-search', label: <FormattedMessage id='search.quick_action.status_search' defaultMessage='Posts matching {x}' values={{ x: <mark>{trimmedValue}</mark> }} />, action: this.handleStatusSearch }); options.push({ key: 'status-search', label: <FormattedMessage id='search.quick_action.status_search' defaultMessage='Posts matching {x}' values={{ x: <mark>{trimmedValue}</mark> }} />, action: this.handleStatusSearch });
} }
@ -375,7 +376,7 @@ class Search extends PureComponent {
<h4><FormattedMessage id='search_popout.options' defaultMessage='Search options' /></h4> <h4><FormattedMessage id='search_popout.options' defaultMessage='Search options' /></h4>
{searchEnabled ? ( {searchEnabled && signedIn ? (
<div className='search__popout__menu'> <div className='search__popout__menu'>
{this.defaultOptions.map(({ key, label, action }, i) => ( {this.defaultOptions.map(({ key, label, action }, i) => (
<button key={key} onMouseDown={action} className={classNames('search__popout__menu__item', { selected: selectedOption === ((options.length || recent.size) + i) })}> <button key={key} onMouseDown={action} className={classNames('search__popout__menu__item', { selected: selectedOption === ((options.length || recent.size) + i) })}>
@ -385,7 +386,11 @@ class Search extends PureComponent {
</div> </div>
) : ( ) : (
<div className='search__popout__menu__message'> <div className='search__popout__menu__message'>
{searchEnabled ? (
<FormattedMessage id='search_popout.full_text_search_logged_out_message' defaultMessage='Only available when logged in.' />
) : (
<FormattedMessage id='search_popout.full_text_search_disabled_message' defaultMessage='Not available on {domain}.' values={{ domain }} /> <FormattedMessage id='search_popout.full_text_search_disabled_message' defaultMessage='Not available on {domain}.' values={{ domain }} />
)}
</div> </div>
)} )}
</div> </div>

View file

@ -591,6 +591,7 @@
"search.quick_action.status_search": "Posts matching {x}", "search.quick_action.status_search": "Posts matching {x}",
"search.search_or_paste": "Search or paste URL", "search.search_or_paste": "Search or paste URL",
"search_popout.full_text_search_disabled_message": "Not available on {domain}.", "search_popout.full_text_search_disabled_message": "Not available on {domain}.",
"search_popout.full_text_search_logged_out_message": "Only available when logged in.",
"search_popout.language_code": "ISO language code", "search_popout.language_code": "ISO language code",
"search_popout.options": "Search options", "search_popout.options": "Search options",
"search_popout.quick_actions": "Quick actions", "search_popout.quick_actions": "Quick actions",