2023-05-24 00:15:17 +09:00
|
|
|
import { Map as ImmutableMap } from 'immutable';
|
2022-05-16 18:18:35 +09:00
|
|
|
import { connect } from 'react-redux';
|
2023-05-24 00:15:17 +09:00
|
|
|
import { createSelector } from 'reselect';
|
|
|
|
|
2022-05-16 18:18:35 +09:00
|
|
|
import { changeComposeLanguage } from 'mastodon/actions/compose';
|
|
|
|
import { useLanguage } from 'mastodon/actions/languages';
|
2023-05-24 00:15:17 +09:00
|
|
|
|
|
|
|
import LanguageDropdown from '../components/language_dropdown';
|
2022-05-16 18:18:35 +09:00
|
|
|
|
|
|
|
const getFrequentlyUsedLanguages = createSelector([
|
|
|
|
state => state.getIn(['settings', 'frequentlyUsedLanguages'], ImmutableMap()),
|
|
|
|
], languageCounters => (
|
|
|
|
languageCounters.keySeq()
|
|
|
|
.sort((a, b) => languageCounters.get(a) - languageCounters.get(b))
|
|
|
|
.reverse()
|
|
|
|
.toArray()
|
|
|
|
));
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
frequentlyUsedLanguages: getFrequentlyUsedLanguages(state),
|
|
|
|
value: state.getIn(['compose', 'language']),
|
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
|
|
|
|
onChange (value) {
|
|
|
|
dispatch(changeComposeLanguage(value));
|
|
|
|
},
|
|
|
|
|
|
|
|
onClose (value) {
|
2023-05-09 10:09:11 +09:00
|
|
|
// eslint-disable-next-line react-hooks/rules-of-hooks -- this is not a react hook
|
2022-05-16 18:18:35 +09:00
|
|
|
dispatch(useLanguage(value));
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(LanguageDropdown);
|