From 745d102ee222738bd673c9c20d08597d50588b44 Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 8 Sep 2019 17:14:48 +0200 Subject: [PATCH] Client - store language w/ redux --- fittrackee_client/src/actions/index.js | 5 +++ .../components/NavBar/LanguageDropdown.jsx | 31 +++++++++++-------- fittrackee_client/src/reducers/index.js | 8 +++++ fittrackee_client/src/reducers/initial.js | 1 + 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/fittrackee_client/src/actions/index.js b/fittrackee_client/src/actions/index.js index 89473d32..30802ffe 100644 --- a/fittrackee_client/src/actions/index.js +++ b/fittrackee_client/src/actions/index.js @@ -12,6 +12,11 @@ export const setError = message => ({ message, }) +export const setLanguage = language => ({ + type: 'SET_LANGUAGE', + language, +}) + export const setLoading = loading => ({ type: 'SET_LOADING', loading, diff --git a/fittrackee_client/src/components/NavBar/LanguageDropdown.jsx b/fittrackee_client/src/components/NavBar/LanguageDropdown.jsx index df6bae6a..1655c3d5 100644 --- a/fittrackee_client/src/components/NavBar/LanguageDropdown.jsx +++ b/fittrackee_client/src/components/NavBar/LanguageDropdown.jsx @@ -1,8 +1,10 @@ import React, { Component } from 'react' import i18next from 'i18next' +import { connect } from 'react-redux' import { ReactComponent as EnFlag } from '../../images/flags/en.svg' import { ReactComponent as FrFlag } from '../../images/flags/fr.svg' +import { setLanguage } from '../../actions/index' const languages = [ { @@ -22,16 +24,6 @@ class Dropdown extends Component { super(props) this.state = { isOpen: false, - selected: 'en', - } - } - - selectLanguage(name) { - if (name !== this.state.selected) { - i18next.changeLanguage(name) - this.setState({ - selected: name, - }) } } @@ -42,7 +34,8 @@ class Dropdown extends Component { } render() { - const { isOpen, selected } = this.state + const { isOpen } = this.state + const { language: selected, onUpdateLanguage } = this.props return (
this.toggleDropdown()}>