-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added redux for state management (#16)
- Loading branch information
1 parent
ae74ab9
commit 5983156
Showing
14 changed files
with
156 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { SET_LOCALE } from '../constants/actions'; | ||
|
||
export const setLocale = value => dispatch => { | ||
dispatch({ type: SET_LOCALE, payload: value }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
import React, {Component} from 'react'; | ||
import React, { Component } from 'react'; | ||
import { Provider } from 'react-redux'; | ||
|
||
import { PersistGate } from 'redux-persist/integration/react'; | ||
|
||
import Router from './router'; | ||
import { store, persistor } from './store'; | ||
|
||
export default class Chatwoot extends Component { | ||
render() { | ||
return <Router />; | ||
return ( | ||
<Provider store={store}> | ||
<PersistGate loading={null} persistor={persistor}> | ||
<Router /> | ||
</PersistGate> | ||
</Provider> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const SET_LOCALE = 'SET_LOCALE'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { combineReducers } from 'redux'; | ||
import locale from './locale'; | ||
|
||
const rootReducer = combineReducers({ | ||
locale, | ||
}); | ||
|
||
export default (state, action) => rootReducer(state, action); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const initialState = { | ||
value: 'en', | ||
isLocaleSet: false, | ||
}; | ||
export default (state = initialState, action) => { | ||
switch (action.type) { | ||
case 'SET_LOCALE': | ||
return { | ||
...state, | ||
value: action.payload, | ||
isLocaleSet: true, | ||
}; | ||
|
||
default: | ||
return state; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React, { Component } from 'react'; | ||
import { View, Text } from 'react-native'; | ||
import styles from './HomeScreen.style'; | ||
|
||
class HomeScreen extends Component { | ||
render() { | ||
return ( | ||
<View style={styles.mainView}> | ||
<Text>Chatwoot</Text> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
export default HomeScreen; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { StyleSheet } from 'react-native'; | ||
export default StyleSheet.create({ | ||
mainView: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import AsyncStorage from '@react-native-community/async-storage'; | ||
import { createStore, applyMiddleware } from 'redux'; | ||
import { createLogger } from 'redux-logger'; | ||
import { persistStore, persistReducer } from 'redux-persist'; | ||
|
||
import rootReducer from './reducer'; | ||
// Middleware: Redux Persist Config | ||
const persistConfig = { | ||
key: 'root', | ||
storage: AsyncStorage, | ||
whitelist: [], | ||
blacklist: [], | ||
}; | ||
// Middleware: Redux Persist Persisted Reducer | ||
const persistedReducer = persistReducer(persistConfig, rootReducer); | ||
// Redux: Store | ||
const store = createStore(persistedReducer, applyMiddleware(createLogger())); | ||
// Middleware: Redux Persist Persister | ||
let persistor = persistStore(store); | ||
|
||
export { store, persistor }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters