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 {
language: PropTypes.string.isRequired,
intl: PropTypes.object.isRequired,
instances: PropTypes.arrayOf(PropTypes.object).isRequired,
languages: PropTypes.arrayOf(PropTypes.object).isRequired,
};
componentDidMount () {
......@@ -70,7 +71,7 @@ class Wizard extends React.PureComponent {
}
render () {
const { instances, category, language, intl } = this.props;
const { instances, category, language, languages, intl } = this.props;
const content = instances.length > 0 ? (
<div>
......@@ -135,31 +136,11 @@ class Wizard extends React.PureComponent {
name="language"
options={[
{ value: '', text: intl.formatMessage(messages.all_languages) },
//{ value: 'ar', text: 'العربية' },
{ value: 'ca', text: 'Català' },
//{ value: 'cs', text: 'Čeština' },
//{ value: 'cy', text: 'Cymraeg' },
{ 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: '中文' },
...languages.map(x => ({
value: x.locale,
text: x.servers_count ? <span><bdi>{x.language}</bdi> ({x.servers_count})</span> : <bdi>x.language</bdi>,
})),
]}
caretIcon={caretIcon}
selectedValue={language}
......
import Wizard from './Wizard';
import { connect } from 'react-redux';
import { fetchInstances, changeFilterCategory, changeFilterLanguage } from './actions';
import { fetchInstances, changeFilterCategory, changeFilterLanguage, fetchLanguages } from './actions';
const mapStateToProps = state => ({
instances: state.instances,
languages: state.languages,
category: state.filter.category,
language: state.filter.language,
});
......@@ -12,11 +13,13 @@ const mapDispatchToProps = dispatch => ({
onMount: () => {
dispatch(fetchInstances());
dispatch(fetchLanguages());
},
onChangeCategory: value => {
dispatch(changeFilterCategory(value));
dispatch(fetchInstances());
dispatch(fetchLanguages());
},
onChangeLanguage: value => {
......
......@@ -4,6 +4,7 @@ export const INSTANCES_FETCH_SUCCESS = 'INSTANCES_FETCH_SUCCESS';
export const LOCALE_CHANGE = 'LOCALE_CHANGE';
export const FILTER_LANGUAGE_CHANGE = 'FILTER_LANGUAGE_CHANGE';
export const FILTER_CATEGORY_CHANGE = 'FILTER_CATEGORY_CHANGE';
export const LANGUAGES_FETCH_SUCCESS = 'LANGUAGES_FETCH_SUCCESS';
export function fetchInstances() {
return (dispatch, getState) => {
......@@ -50,3 +51,24 @@ export function changeFilterLanguage(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 {
LOCALE_CHANGE,
FILTER_CATEGORY_CHANGE,
FILTER_LANGUAGE_CHANGE,
LANGUAGES_FETCH_SUCCESS,
} from './actions';
const supportedLocales = [
......@@ -24,6 +25,34 @@ const supportedLocales = [
'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 lang = navigator.language.split('-')[0];
......@@ -40,6 +69,7 @@ const initialState = {
locale: initialLocale(),
instances: [],
languages: defaultLanguages,
filter: {
category: 'general',
......@@ -66,6 +96,8 @@ export default function reducer(state = initialState, action) {
return { ...state, filter: { ...state.filter, category: action.data } };
case FILTER_LANGUAGE_CHANGE:
return { ...state, filter: { ...state.filter, language: action.data } };
case LANGUAGES_FETCH_SUCCESS:
return { ...state, languages: action.data };
default:
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