2022-02-22 21:58:21 +01:00
|
|
|
import React, { useContext, useEffect } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import { highlightSearchedText } from '../../../helpers/utils/settings-search';
|
|
|
|
import { I18nContext } from '../../../contexts/i18n';
|
2023-02-16 14:26:14 +01:00
|
|
|
import { Icon, ICON_NAMES } from '../../../components/component-library';
|
|
|
|
import { Size } from '../../../helpers/constants/design-system';
|
2022-02-22 21:58:21 +01:00
|
|
|
|
|
|
|
export default function SettingsSearchList({ results, onClickSetting }) {
|
|
|
|
const t = useContext(I18nContext);
|
|
|
|
|
2022-02-24 20:06:30 +01:00
|
|
|
useEffect(highlightSearchedText, [results]);
|
2022-02-22 21:58:21 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="settings-page__header__search__list">
|
2022-02-24 20:06:30 +01:00
|
|
|
{results.slice(0, 5).map((result) => {
|
2023-02-11 02:33:11 +01:00
|
|
|
const { icon, iconName, tabMessage, sectionMessage, route } = result;
|
2022-02-24 20:06:30 +01:00
|
|
|
return (
|
2022-04-06 22:27:08 +02:00
|
|
|
Boolean(icon || tabMessage || sectionMessage) && (
|
|
|
|
<div key={`settings_${route}`}>
|
2022-02-24 20:06:30 +01:00
|
|
|
<div
|
|
|
|
className="settings-page__header__search__list__item"
|
|
|
|
onClick={() => onClickSetting(result)}
|
|
|
|
>
|
2023-02-11 02:33:11 +01:00
|
|
|
{iconName ? (
|
|
|
|
<Icon name={iconName} />
|
|
|
|
) : (
|
|
|
|
<i
|
|
|
|
className={classnames(
|
|
|
|
'settings-page__header__search__list__item__icon',
|
|
|
|
icon,
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
)}
|
2022-02-24 20:06:30 +01:00
|
|
|
<span
|
2022-04-06 22:27:08 +02:00
|
|
|
id={`menu-tab_${route}`}
|
2022-02-24 20:06:30 +01:00
|
|
|
className={classnames(
|
|
|
|
'settings-page__header__search__list__item__tab',
|
|
|
|
{
|
|
|
|
'settings-page__header__search__list__item__tab-multiple-lines':
|
2022-04-06 22:27:08 +02:00
|
|
|
tabMessage(t) === t('securityAndPrivacy'),
|
2022-02-24 20:06:30 +01:00
|
|
|
},
|
|
|
|
)}
|
2022-02-22 21:58:21 +01:00
|
|
|
>
|
2022-04-06 22:27:08 +02:00
|
|
|
{tabMessage(t)}
|
2022-02-24 20:06:30 +01:00
|
|
|
</span>
|
2023-02-16 14:26:14 +01:00
|
|
|
<Icon
|
|
|
|
name={ICON_NAMES.ARROW_RIGHT}
|
|
|
|
size={Size.SM}
|
2022-03-08 22:50:35 +01:00
|
|
|
className="settings-page__header__search__list__item__caret"
|
|
|
|
/>
|
2022-02-24 20:06:30 +01:00
|
|
|
<span
|
2022-04-06 22:27:08 +02:00
|
|
|
id={`menu-section_${route}`}
|
2022-02-24 20:06:30 +01:00
|
|
|
className={classnames(
|
|
|
|
'settings-page__header__search__list__item__section',
|
|
|
|
{
|
|
|
|
'settings-page__header__search__list__item__section-multiple-lines':
|
2022-04-06 22:27:08 +02:00
|
|
|
tabMessage(t) === t('securityAndPrivacy') ||
|
|
|
|
tabMessage(t) === t('alerts'),
|
2022-02-24 20:06:30 +01:00
|
|
|
},
|
|
|
|
)}
|
|
|
|
>
|
2022-04-06 22:27:08 +02:00
|
|
|
{sectionMessage(t)}
|
2022-02-24 20:06:30 +01:00
|
|
|
</span>
|
2022-02-22 21:58:21 +01:00
|
|
|
</div>
|
2022-02-24 20:06:30 +01:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
})}
|
2022-02-22 21:58:21 +01:00
|
|
|
{results.length === 0 && (
|
|
|
|
<div
|
|
|
|
className="settings-page__header__search__list__item"
|
|
|
|
style={{ cursor: 'auto', display: 'flex' }}
|
|
|
|
>
|
|
|
|
<span className="settings-page__header__search__list__item__no-matching">
|
|
|
|
{t('settingsSearchMatchingNotFound')}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<div
|
|
|
|
className="settings-page__header__search__list__item"
|
|
|
|
style={{ cursor: 'auto', display: 'flex' }}
|
|
|
|
>
|
|
|
|
<span className="settings-page__header__search__list__item__request">
|
|
|
|
{t('missingSetting')}
|
|
|
|
</span>
|
|
|
|
<a
|
|
|
|
href="https://community.metamask.io/c/feature-requests-ideas/13"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
key="need-help-link"
|
|
|
|
className="settings-page__header__search__list__item__link"
|
|
|
|
>
|
|
|
|
{t('missingSettingRequest')}
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
SettingsSearchList.propTypes = {
|
|
|
|
results: PropTypes.array,
|
|
|
|
onClickSetting: PropTypes.func,
|
|
|
|
};
|