-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add static content intl(locale) support #912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add static content intl(locale) support #912
Conversation
|
Hi @awesomejerry You can look at I know I should rewrite content fetching too and I probably do this soon but for now I will do not merge this. Anyway Thanks! And ping me in week if nothing happens here 😃 |
|
The main reason I wrote FYI, I'm gonna make |
|
Hi @langpavel , I've updated the PR to redux style. Please check it. Thanks! |
langpavel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest you some changes but it is great job!
Thanks @awesomejerry
src/actions/content.js
Outdated
| /* eslint-disable import/prefer-default-export */ | ||
|
|
||
| import { | ||
| GET_LOCALE_CONTENT, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FETCH_CONTENT_START
src/actions/content.js
Outdated
|
|
||
| import { | ||
| GET_LOCALE_CONTENT, | ||
| GET_LOCALE_CONTENT_SUCCESS, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FETCH_CONTENT_SUCCESS
src/actions/content.js
Outdated
| import { | ||
| GET_LOCALE_CONTENT, | ||
| GET_LOCALE_CONTENT_SUCCESS, | ||
| GET_LOCALE_CONTENT_ERROR, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FETCH_CONTENT_ERROR
src/actions/content.js
Outdated
| export function getLocaleContent(path, locale) { | ||
| return async (dispatch, getState, { graphqlRequest }) => { | ||
| dispatch({ | ||
| type: GET_LOCALE_CONTENT, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FETCH_CONTENT_START- add more data to payload, path, locale
- you can make locale optional witch default value from
getState().intl.locale
src/actions/content.js
Outdated
| } | ||
| `; | ||
|
|
||
| export function getLocaleContent(path, locale) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use object for passing in arguments
export function getLocaleContent({ path, locale })
src/constants/index.js
Outdated
| export const SET_LOCALE_START = 'SET_LOCALE_START'; | ||
| export const SET_LOCALE_SUCCESS = 'SET_LOCALE_SUCCESS'; | ||
| export const SET_LOCALE_ERROR = 'SET_LOCALE_ERROR'; | ||
| export const GET_LOCALE_CONTENT = 'GET_LOCALE_CONTENT'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FETCH_CONTENT_START note it is very good practice to use suffixes consistently, see for example react-redux-loading-bar
| return { | ||
| ...state, | ||
| isFetching: true, | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const key = `${action.payload.locale}:${action.payload.path}`;
return {
...state,
[key]: {
...(state[key]),
isFetching: true,
},
}key should be extracted to standalone function based on action.payload
| ...state, | ||
| isFetching: false, | ||
| data: action.payload.data, | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return {
...state,
[key]: {
isFetching: false,
...action.payload
},
};| const mapState = (state) => ({ | ||
| locale: state.intl.locale, | ||
| data: state.content.data, | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const mapState = (state, props) => {
const locale = state.intl.locale;
const content = state.content[`${locale}:${props.path}`];
return {
locale: state.intl.locale,
...content
};
};|
Thanks for the code reviews and suggestions! They're quite helpful. |
|
Thanks @awesomejerry |
related to #684, #686
support: