File tree Expand file tree Collapse file tree 15 files changed +239
-24
lines changed Expand file tree Collapse file tree 15 files changed +239
-24
lines changed Original file line number Diff line number Diff line change 1414 "react-app-rewired" : " ^2.1.5" ,
1515 "react-dom" : " ^16.12.0" ,
1616 "react-intl" : " ^3.11.0" ,
17- "react-scripts" : " 3.3.0"
17+ "react-redux" : " ^7.1.3" ,
18+ "react-scripts" : " 3.3.0" ,
19+ "redux" : " ^4.0.5" ,
20+ "redux-thunk" : " ^2.3.0"
1821 },
1922 "scripts" : {
2023 "start" : " react-app-rewired start" ,
3639 " last 1 firefox version" ,
3740 " last 1 safari version"
3841 ]
42+ },
43+ "devDependencies" : {
44+ "redux-devtools-extension" : " ^2.13.8"
3945 }
4046}
Original file line number Diff line number Diff line change 11import React from 'react' ;
2+ import { connect } from 'react-redux' ;
23import { useRoutes } from 'hookrouter' ;
34import { IntlProvider } from 'react-intl' ;
4- import messages_en from './translations/en.json' ;
5- import messages_vi from './translations/vi.json' ;
5+ import en from './translations/en.json' ;
6+ import vi from './translations/vi.json' ;
67import routes from './router' ;
78import NoPageFound from './pages/NoPageFound/NoPageFound' ;
89import './App.scss' ;
910
10- const messages = {
11- en : messages_en ,
12- vi : messages_vi
13- } ;
14-
15- const language = 'en' ;
11+ const messages = { en, vi } ;
1612
17- const App = ( ) => {
13+ const App = props => {
1814 console . log ( 'This console will be remove in Production mode' ) ;
1915 const routeResult = useRoutes ( routes ) ;
16+ const language = props . languageTrans ;
2017
2118 return (
2219 < IntlProvider locale = { language } messages = { messages [ language ] } >
@@ -25,4 +22,9 @@ const App = () => {
2522 ) ;
2623} ;
2724
28- export default App ;
25+ export default connect (
26+ state => ( {
27+ languageTrans : state . system . languageTrans
28+ } ) ,
29+ { }
30+ ) ( App ) ;
Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+ import { connect } from 'react-redux' ;
3+ import { actionChangeLanguage } from '../../system/systemAction' ;
4+ import './ChangeLanguage.scss' ;
5+
6+ const ChangeLanguage = props => {
7+ const handleClick = lang => ( ) => {
8+ props . actionChangeLanguage ( lang ) ;
9+ } ;
10+
11+ return (
12+ < div className = "change-language-container" >
13+ < span
14+ className = { `item left ${ props . languageTrans === 'en' ? 'active' : '' } ` }
15+ onClick = { handleClick ( 'en' ) }
16+ >
17+ EN
18+ </ span >
19+ < span
20+ className = { `item right ${ props . languageTrans === 'vi' ? 'active' : '' } ` }
21+ onClick = { handleClick ( 'vi' ) }
22+ >
23+ VI
24+ </ span >
25+ </ div >
26+ ) ;
27+ } ;
28+
29+ export default connect (
30+ state => ( {
31+ languageTrans : state . system . languageTrans
32+ } ) ,
33+ {
34+ actionChangeLanguage
35+ }
36+ ) ( ChangeLanguage ) ;
Original file line number Diff line number Diff line change 1+ @import " ../../scss/variables.scss" ;
2+
3+ .change-language-container {
4+ display : inline-block ;
5+ .item {
6+ line-height : 1 ;
7+ padding : 0 ;
8+ font-weight : 600 ;
9+ cursor : default ;
10+ & :not (.active ):hover {
11+ cursor : pointer ;
12+ }
13+ & .active {
14+ color : $primaryColor ;
15+ }
16+ & .left {
17+ padding-right : 15px ;
18+ border-right : 1px solid #999 ;
19+ }
20+ & .right {
21+ padding-left : 15px ;
22+ }
23+ }
24+ }
Original file line number Diff line number Diff line change 11import React from 'react' ;
22import { A } from 'hookrouter' ;
3+ import { FormattedMessage } from 'react-intl' ;
4+ import ChangeLanguage from '../ChangeLanguage/ChangeLanguage' ;
35import './Navigation.scss' ;
46
57const Navigation = ( ) => {
68 return (
79 < div className = "navigation-container" >
8- < ul >
9- < li > < A href = "/" > Home</ A > </ li >
10- < li > < A href = "/terms" > Terms of Use</ A > </ li >
11- < li > < A href = "/privacy" > Privacy Policy</ A > </ li >
12- < li > < A href = "/blog/1" > Blog 1</ A > </ li >
13- < li > < A href = "/blog/2" > Blog 2</ A > </ li >
10+ < ul className = "left" >
11+ < li >
12+ < A href = "/" >
13+ < FormattedMessage id = "IDS_HOME_PAGE" />
14+ </ A >
15+ </ li >
16+ < li >
17+ < A href = "/terms" >
18+ < FormattedMessage id = "IDS_TERMS_OF_USE" />
19+ </ A >
20+ </ li >
21+ < li >
22+ < A href = "/privacy" >
23+ < FormattedMessage id = "IDS_PRIVACY_POLICY" />
24+ </ A >
25+ </ li >
26+ < li >
27+ < A href = "/blog/1" >
28+ < FormattedMessage
29+ id = "IDS_BLOG_PAGE_WITH_ID"
30+ values = { { blogId : 1 } }
31+ />
32+ </ A >
33+ </ li >
34+ < li >
35+ < A href = "/blog/2" >
36+ < FormattedMessage
37+ id = "IDS_BLOG_PAGE_WITH_ID"
38+ values = { { blogId : 2 } }
39+ />
40+ </ A >
41+ </ li >
1442 </ ul >
43+ < ChangeLanguage />
1544 </ div >
1645 ) ;
1746} ;
Original file line number Diff line number Diff line change 1- @import " ../../scss/variables.scss" ;
1+ @import ' ../../scss/variables.scss' ;
22
33.navigation-container {
4+ display : flex ;
5+ justify-content : space-between ;
6+ align-items : center ;
47 ul {
58 li {
69 a {
Original file line number Diff line number Diff line change 1+ export const systemActions = {
2+ CHANGE_LANGUAGE : 'CHANGE_LANGUAGE'
3+ } ;
Original file line number Diff line number Diff line change 11import React from 'react' ;
2- import ReactDOM from 'react-dom' ;
2+ import { render } from 'react-dom' ;
3+ import { Provider } from 'react-redux' ;
4+ import configureStore from './store/configureStore' ;
35import './index.scss' ;
46import App from './App' ;
57import * as serviceWorker from './serviceWorker' ;
68
7- ReactDOM . render ( < App /> , document . getElementById ( 'root' ) ) ;
9+ const store = configureStore ( ) ;
10+
11+ render (
12+ < Provider store = { store } >
13+ < App />
14+ </ Provider > ,
15+ document . getElementById ( 'root' )
16+ ) ;
817
918// If you want your app to work offline and load faster, you can change
1019// unregister() to register() below. Note this comes with some pitfalls.
Original file line number Diff line number Diff line change 1+ import { combineReducers } from 'redux' ;
2+ import system from '../system/systemReducer' ;
3+
4+ export default combineReducers ( {
5+ system
6+ } ) ;
Original file line number Diff line number Diff line change 1+ import { applyMiddleware , createStore } from 'redux' ;
2+ import { composeWithDevTools } from 'redux-devtools-extension'
3+ import thunkMiddleware from 'redux-thunk' ;
4+ import combineReducers from './combineReducers' ;
5+
6+ const loggerMiddleware = store => next => action => {
7+ console . group ( action . type ) ;
8+ console . log ( 'prev state' , store . getState ( ) ) ;
9+ let result = next ( action ) ;
10+ console . log ( 'next state' , store . getState ( ) ) ;
11+ console . groupEnd ( ) ;
12+ return result ;
13+ } ;
14+
15+ const configureStore = preloadedState => {
16+ const middlewares = [ ] ;
17+ if ( process . env . NODE_ENV === 'development' ) {
18+ middlewares . push ( loggerMiddleware )
19+ }
20+ middlewares . push ( thunkMiddleware ) ;
21+
22+ const middlewareEnhancer = applyMiddleware ( ...middlewares ) ;
23+ const enhancers = [ middlewareEnhancer ] ;
24+ const composedEnhancers = composeWithDevTools ( ...enhancers ) ;
25+ return createStore ( combineReducers , preloadedState , composedEnhancers ) ;
26+ } ;
27+
28+ export default configureStore ;
You can’t perform that action at this time.
0 commit comments