2024-01-24 08:03:30 +01:00
|
|
|
import { createSelector } from '@reduxjs/toolkit';
|
2016-11-13 13:04:18 +01:00
|
|
|
import { connect } from 'react-redux';
|
2023-05-23 17:15:17 +02:00
|
|
|
|
2016-11-13 13:04:18 +01:00
|
|
|
import {
|
|
|
|
changeSearch,
|
2017-03-31 19:59:54 +02:00
|
|
|
clearSearch,
|
|
|
|
submitSearch,
|
2017-05-20 17:31:47 +02:00
|
|
|
showSearch,
|
2023-04-01 09:59:10 +02:00
|
|
|
openURL,
|
|
|
|
clickSearchResult,
|
|
|
|
forgetSearchResult,
|
|
|
|
} from 'mastodon/actions/search';
|
2023-05-23 17:15:17 +02:00
|
|
|
|
2016-11-13 13:04:18 +01:00
|
|
|
import Search from '../components/search';
|
|
|
|
|
2024-01-24 08:03:30 +01:00
|
|
|
const getRecentSearches = createSelector(
|
|
|
|
state => state.getIn(['search', 'recent']),
|
|
|
|
recent => recent.reverse(),
|
|
|
|
);
|
|
|
|
|
2016-11-13 13:04:18 +01:00
|
|
|
const mapStateToProps = state => ({
|
2017-03-31 22:44:12 +02:00
|
|
|
value: state.getIn(['search', 'value']),
|
2017-05-20 17:31:47 +02:00
|
|
|
submitted: state.getIn(['search', 'submitted']),
|
2024-01-24 08:03:30 +01:00
|
|
|
recent: getRecentSearches(state),
|
2016-11-13 13:04:18 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
|
|
|
|
onChange (value) {
|
|
|
|
dispatch(changeSearch(value));
|
|
|
|
},
|
|
|
|
|
|
|
|
onClear () {
|
2017-03-31 19:59:54 +02:00
|
|
|
dispatch(clearSearch());
|
2016-11-13 13:04:18 +01:00
|
|
|
},
|
|
|
|
|
2023-04-01 09:59:10 +02:00
|
|
|
onSubmit (type) {
|
|
|
|
dispatch(submitSearch(type));
|
2016-11-13 13:04:18 +01:00
|
|
|
},
|
|
|
|
|
2017-03-31 19:59:54 +02:00
|
|
|
onShow () {
|
|
|
|
dispatch(showSearch());
|
2017-05-20 17:31:47 +02:00
|
|
|
},
|
2016-11-13 13:04:18 +01:00
|
|
|
|
2023-04-25 06:33:21 +02:00
|
|
|
onOpenURL (q, routerHistory) {
|
|
|
|
dispatch(openURL(q, routerHistory));
|
2023-04-01 09:59:10 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
onClickSearchResult (q, type) {
|
|
|
|
dispatch(clickSearchResult(q, type));
|
|
|
|
},
|
|
|
|
|
|
|
|
onForgetSearchResult (q) {
|
|
|
|
dispatch(forgetSearchResult(q));
|
|
|
|
},
|
|
|
|
|
2016-11-13 13:04:18 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Search);
|