Added search filter for isVerified accounts

• Added:
- search filter for isVerified accounts

• Todo:
- Implement in account search query
This commit is contained in:
mgabdev 2020-08-06 23:05:02 -05:00
parent 0c2b6fb112
commit 516b7852b8
6 changed files with 66 additions and 18 deletions

View File

@ -22,6 +22,6 @@ class Api::V1::SearchController < Api::BaseController
end
def search_params
params.permit(:type, :offset, :min_id, :max_id, :account_id)
params.permit(:type, :onlyVerified, :offset, :min_id, :max_id, :account_id)
end
end

View File

@ -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())
}
}

View File

@ -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>
)
}

View File

@ -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;
}

View File

@ -7,6 +7,7 @@ class AccountSearchService < BaseService
@query = query.strip
@limit = options[:limit].to_i
@offset = options[:offset].to_i
@onlyVerified = options[:onlyVerified] || false
@options = options
@account = account
@ -84,11 +85,11 @@ class AccountSearchService < BaseService
end
def advanced_search_results
Account.advanced_search_for(terms_for_query, account, limit, options[:following], offset)
Account.advanced_search_for(terms_for_query, account, limit, options[:following], offset, onlyVerified: @onlyVerified)
end
def simple_search_results
Account.search_for(terms_for_query, limit, offset)
Account.search_for(terms_for_query, limit, offset, onlyVerified: @onlyVerified)
end
def terms_for_query

View File

@ -8,6 +8,7 @@ class SearchService < BaseService
@limit = limit.to_i
@offset = options[:type].blank? ? 0 : options[:offset].to_i
@resolve = options[:resolve] || false
@onlyVerified = options[:onlyVerified] || false
default_results.tap do |results|
next if @query.blank? || @limit.zero?
@ -31,7 +32,8 @@ class SearchService < BaseService
@account,
limit: @limit,
resolve: @resolve,
offset: @offset
offset: @offset,
onlyVerified: @onlyVerified
)
end