2024-01-08 21:57:40 +11:00
|
|
|
import { createSelector } from '@reduxjs/toolkit';
|
2023-05-24 01:15:17 +10:00
|
|
|
import { Map as ImmutableMap } from 'immutable';
|
2022-05-16 19:18:35 +10:00
|
|
|
import { connect } from 'react-redux';
|
2024-01-08 21:57:40 +11:00
|
|
|
|
2023-05-24 01:15:17 +10:00
|
|
|
|
2022-05-16 19:18:35 +10:00
|
|
|
import { changeComposeLanguage } from 'mastodon/actions/compose';
|
2023-05-24 01:15:17 +10:00
|
|
|
|
|
|
|
import LanguageDropdown from '../components/language_dropdown';
|
2022-05-16 19:18:35 +10: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));
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(LanguageDropdown);
|