Added search filter for isVerified accounts
• Added: - search filter for isVerified accounts • Todo: - Implement in account search query
This commit is contained in:
@@ -2,6 +2,7 @@ import api from '../api';
|
||||
import { fetchRelationships } from './accounts';
|
||||
import { fetchGroupsSuccess, fetchGroupRelationships } from './groups'
|
||||
import { importFetchedAccounts, importFetchedStatuses } from './importer';
|
||||
import { SEARCH_FILTERS } from '../constants'
|
||||
|
||||
export const SEARCH_CHANGE = 'SEARCH_CHANGE';
|
||||
export const SEARCH_CLEAR = 'SEARCH_CLEAR';
|
||||
@@ -11,6 +12,8 @@ export const SEARCH_FETCH_REQUEST = 'SEARCH_FETCH_REQUEST';
|
||||
export const SEARCH_FETCH_SUCCESS = 'SEARCH_FETCH_SUCCESS';
|
||||
export const SEARCH_FETCH_FAIL = 'SEARCH_FETCH_FAIL';
|
||||
|
||||
export const SEARCH_FILTER_SET = 'SEARCH_FILTER_SET'
|
||||
|
||||
export function changeSearch(value) {
|
||||
return {
|
||||
type: SEARCH_CHANGE,
|
||||
@@ -27,15 +30,15 @@ export function clearSearch() {
|
||||
export function submitSearch() {
|
||||
return (dispatch, getState) => {
|
||||
const value = getState().getIn(['search', 'value']);
|
||||
const onlyVerified = getState().getIn(['search', 'filter', 'onlyVerified'])
|
||||
|
||||
if (value.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (value.length === 0) return
|
||||
|
||||
dispatch(fetchSearchRequest());
|
||||
|
||||
api(getState).get('/api/v2/search', {
|
||||
params: {
|
||||
onlyVerified,
|
||||
q: value,
|
||||
resolve: true,
|
||||
},
|
||||
@@ -86,3 +89,14 @@ export function showSearch() {
|
||||
type: SEARCH_SHOW,
|
||||
};
|
||||
};
|
||||
|
||||
export function setFilter(path, value, shouldSubmit) {
|
||||
return (dispatch) => {
|
||||
dispatch({
|
||||
type: SEARCH_FILTER_SET,
|
||||
path: path,
|
||||
value: value,
|
||||
})
|
||||
if (shouldSubmit) dispatch(submitSearch())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,57 @@
|
||||
import { Fragment } from 'react'
|
||||
import { defineMessages, injectIntl } from 'react-intl'
|
||||
import ImmutablePureComponent from 'react-immutable-pure-component'
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes'
|
||||
import { shortNumberFormat } from '../../utils/numbers'
|
||||
import { setFilter } from '../../actions/search'
|
||||
import PanelLayout from './panel_layout'
|
||||
import Button from '../button'
|
||||
import Divider from '../divider'
|
||||
import Heading from '../heading'
|
||||
import Icon from '../icon'
|
||||
import Text from '../text'
|
||||
import SettingSwitch from '../setting_switch'
|
||||
|
||||
const messages = defineMessages({
|
||||
title: { id: 'search_filters', defaultMessage: 'Search Filters' },
|
||||
onlyVerified: { id: 'notification_only_verified', defaultMessage: 'Only Verified Users' },
|
||||
})
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
settings: state.getIn(['search', 'filter']),
|
||||
})
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
onChange(path, value) {
|
||||
dispatch(setFilter(path, value, true))
|
||||
},
|
||||
})
|
||||
|
||||
export default
|
||||
@injectIntl
|
||||
@connect(mapStateToProps, mapDispatchToProps)
|
||||
class SearchFilterPanel extends ImmutablePureComponent {
|
||||
|
||||
static propTypes = {
|
||||
intl: PropTypes.object.isRequired,
|
||||
onChange: PropTypes.func.isRequired,
|
||||
settings: ImmutablePropTypes.map.isRequired,
|
||||
}
|
||||
|
||||
componentWillUnmount () {
|
||||
//reset
|
||||
this.props.onChange('onlyVerified', false, false)
|
||||
}
|
||||
|
||||
render() {
|
||||
const { intl } = this.props
|
||||
|
||||
// verified or not
|
||||
const {
|
||||
intl,
|
||||
onChange,
|
||||
settings,
|
||||
} = this.props
|
||||
|
||||
return (
|
||||
<PanelLayout title={intl.formatMessage(messages.title)}>
|
||||
|
||||
<SettingSwitch
|
||||
prefix='search'
|
||||
settings={settings}
|
||||
settingPath={'onlyVerified'}
|
||||
onChange={onChange}
|
||||
label={intl.formatMessage(messages.onlyVerified)}
|
||||
/>
|
||||
</PanelLayout>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
SEARCH_FETCH_FAIL,
|
||||
SEARCH_FETCH_SUCCESS,
|
||||
SEARCH_SHOW,
|
||||
SEARCH_FILTER_SET,
|
||||
} from '../actions/search';
|
||||
import {
|
||||
COMPOSE_MENTION,
|
||||
@@ -19,6 +20,9 @@ const initialState = ImmutableMap({
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
results: ImmutableMap(),
|
||||
filter: ImmutableMap({
|
||||
onlyVerified: false,
|
||||
}),
|
||||
});
|
||||
|
||||
export default function search(state = initialState, action) {
|
||||
@@ -59,6 +63,11 @@ export default function search(state = initialState, action) {
|
||||
hashtags: fromJS(action.results.hashtags),
|
||||
groups: fromJS(action.results.groups),
|
||||
})).set('submitted', true).set('isLoading', false).set('isError', false);
|
||||
case SEARCH_FILTER_SET:
|
||||
return state.withMutations((mutable) => {
|
||||
mutable.set('items', ImmutableList()).set('hasMore', true)
|
||||
mutable.setIn(['filter', action.path], action.value)
|
||||
})
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user