Commit a37e32e1 authored by Eugen Rochko's avatar Eugen Rochko

Add server counters to list of languages

parent ec8d5883
...@@ -42,6 +42,7 @@ class Wizard extends React.PureComponent { ...@@ -42,6 +42,7 @@ class Wizard extends React.PureComponent {
language: PropTypes.string.isRequired, language: PropTypes.string.isRequired,
intl: PropTypes.object.isRequired, intl: PropTypes.object.isRequired,
instances: PropTypes.arrayOf(PropTypes.object).isRequired, instances: PropTypes.arrayOf(PropTypes.object).isRequired,
languages: PropTypes.arrayOf(PropTypes.object).isRequired,
}; };
componentDidMount () { componentDidMount () {
...@@ -70,7 +71,7 @@ class Wizard extends React.PureComponent { ...@@ -70,7 +71,7 @@ class Wizard extends React.PureComponent {
} }
render () { render () {
const { instances, category, language, intl } = this.props; const { instances, category, language, languages, intl } = this.props;
const content = instances.length > 0 ? ( const content = instances.length > 0 ? (
<div> <div>
...@@ -135,31 +136,11 @@ class Wizard extends React.PureComponent { ...@@ -135,31 +136,11 @@ class Wizard extends React.PureComponent {
name="language" name="language"
options={[ options={[
{ value: '', text: intl.formatMessage(messages.all_languages) }, { value: '', text: intl.formatMessage(messages.all_languages) },
//{ value: 'ar', text: 'العربية' },
{ value: 'ca', text: 'Català' }, ...languages.map(x => ({
//{ value: 'cs', text: 'Čeština' }, value: x.locale,
//{ value: 'cy', text: 'Cymraeg' }, text: x.servers_count ? <span><bdi>{x.language}</bdi> ({x.servers_count})</span> : <bdi>x.language</bdi>,
{ value: 'de', text: 'Deutsch' }, })),
{ value: 'en', text: 'English' },
//{ value: 'es', text: 'Español' },
{ value: 'eu', text: 'Euskara' },
{ value: 'fi', text: 'Suomi' },
{ value: 'fr', text: 'Français' },
{ value: 'he', text: 'עברית' },
{ value: 'it', text: 'Italiano' },
{ value: 'ja', text: '日本語' },
{ value: 'ko', text: '한국어' },
//{ value: 'nl', text: 'Nederlands' },
{ value: 'no', text: 'Norsk' },
{ value: 'pl', text: 'Polski' },
{ value: 'pt', text: 'Português' },
//{ value: 'ru', text: 'Русский' },
{ value: 'sk', text: 'Slovenčina' },
//{ value: 'sq', text: 'Shqip' },
{ value: 'sv', text: 'Svenska' },
//{ value: 'tr', text: 'Türkçe' },
{ value: 'uk', text: 'Українська' },
{ value: 'zh', text: '中文' },
]} ]}
caretIcon={caretIcon} caretIcon={caretIcon}
selectedValue={language} selectedValue={language}
......
import Wizard from './Wizard'; import Wizard from './Wizard';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { fetchInstances, changeFilterCategory, changeFilterLanguage } from './actions'; import { fetchInstances, changeFilterCategory, changeFilterLanguage, fetchLanguages } from './actions';
const mapStateToProps = state => ({ const mapStateToProps = state => ({
instances: state.instances, instances: state.instances,
languages: state.languages,
category: state.filter.category, category: state.filter.category,
language: state.filter.language, language: state.filter.language,
}); });
...@@ -12,11 +13,13 @@ const mapDispatchToProps = dispatch => ({ ...@@ -12,11 +13,13 @@ const mapDispatchToProps = dispatch => ({
onMount: () => { onMount: () => {
dispatch(fetchInstances()); dispatch(fetchInstances());
dispatch(fetchLanguages());
}, },
onChangeCategory: value => { onChangeCategory: value => {
dispatch(changeFilterCategory(value)); dispatch(changeFilterCategory(value));
dispatch(fetchInstances()); dispatch(fetchInstances());
dispatch(fetchLanguages());
}, },
onChangeLanguage: value => { onChangeLanguage: value => {
......
...@@ -4,6 +4,7 @@ export const INSTANCES_FETCH_SUCCESS = 'INSTANCES_FETCH_SUCCESS'; ...@@ -4,6 +4,7 @@ export const INSTANCES_FETCH_SUCCESS = 'INSTANCES_FETCH_SUCCESS';
export const LOCALE_CHANGE = 'LOCALE_CHANGE'; export const LOCALE_CHANGE = 'LOCALE_CHANGE';
export const FILTER_LANGUAGE_CHANGE = 'FILTER_LANGUAGE_CHANGE'; export const FILTER_LANGUAGE_CHANGE = 'FILTER_LANGUAGE_CHANGE';
export const FILTER_CATEGORY_CHANGE = 'FILTER_CATEGORY_CHANGE'; export const FILTER_CATEGORY_CHANGE = 'FILTER_CATEGORY_CHANGE';
export const LANGUAGES_FETCH_SUCCESS = 'LANGUAGES_FETCH_SUCCESS';
export function fetchInstances() { export function fetchInstances() {
return (dispatch, getState) => { return (dispatch, getState) => {
...@@ -50,3 +51,24 @@ export function changeFilterLanguage(data) { ...@@ -50,3 +51,24 @@ export function changeFilterLanguage(data) {
data, data,
}; };
}; };
export function fetchLanguages() {
return (dispatch, getState) => {
const { category } = getState().filter;
const params = {};
if (category !== '') {
params.category = category.split('-')[0];
}
axios.get('https://api.joinmastodon.org/languages', { params })
.then(({ data }) => dispatch(fetchLanguagesSuccess(data)));
};
};
export function fetchLanguagesSuccess(data) {
return {
type: LANGUAGES_FETCH_SUCCESS,
data,
};
};
...@@ -3,6 +3,7 @@ import { ...@@ -3,6 +3,7 @@ import {
LOCALE_CHANGE, LOCALE_CHANGE,
FILTER_CATEGORY_CHANGE, FILTER_CATEGORY_CHANGE,
FILTER_LANGUAGE_CHANGE, FILTER_LANGUAGE_CHANGE,
LANGUAGES_FETCH_SUCCESS,
} from './actions'; } from './actions';
const supportedLocales = [ const supportedLocales = [
...@@ -24,6 +25,34 @@ const supportedLocales = [ ...@@ -24,6 +25,34 @@ const supportedLocales = [
'zh-TW', 'zh-TW',
]; ];
const defaultLanguages = [
{ locale: 'ar', language: 'العربية' },
{ locale: 'ca', language: 'Català' },
{ locale: 'cs', language: 'Čeština' },
{ locale: 'cy', language: 'Cymraeg' },
{ locale: 'de', language: 'Deutsch' },
{ locale: 'en', language: 'English' },
{ locale: 'es', language: 'Español' },
{ locale: 'eu', language: 'Euskara' },
{ locale: 'fi', language: 'Suomi' },
{ locale: 'fr', language: 'Français' },
{ locale: 'he', language: 'עברית' },
{ locale: 'it', language: 'Italiano' },
{ locale: 'ja', language: '日本語' },
{ locale: 'ko', language: '한국어' },
{ locale: 'nl', language: 'Nederlands' },
{ locale: 'no', language: 'Norsk' },
{ locale: 'pl', language: 'Polski' },
{ locale: 'pt', language: 'Português' },
{ locale: 'ru', language: 'Русский' },
{ locale: 'sk', language: 'Slovenčina' },
{ locale: 'sq', language: 'Shqip' },
{ locale: 'sv', language: 'Svenska' },
{ locale: 'tr', language: 'Türkçe' },
{ locale: 'uk', language: 'Українська' },
{ locale: 'zh', language: '中文' },
];
const initialLocale = () => { const initialLocale = () => {
const lang = navigator.language.split('-')[0]; const lang = navigator.language.split('-')[0];
...@@ -40,6 +69,7 @@ const initialState = { ...@@ -40,6 +69,7 @@ const initialState = {
locale: initialLocale(), locale: initialLocale(),
instances: [], instances: [],
languages: defaultLanguages,
filter: { filter: {
category: 'general', category: 'general',
...@@ -66,6 +96,8 @@ export default function reducer(state = initialState, action) { ...@@ -66,6 +96,8 @@ export default function reducer(state = initialState, action) {
return { ...state, filter: { ...state.filter, category: action.data } }; return { ...state, filter: { ...state.filter, category: action.data } };
case FILTER_LANGUAGE_CHANGE: case FILTER_LANGUAGE_CHANGE:
return { ...state, filter: { ...state.filter, language: action.data } }; return { ...state, filter: { ...state.filter, language: action.data } };
case LANGUAGES_FETCH_SUCCESS:
return { ...state, languages: action.data };
default: default:
return state; return state;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment