diff options
Diffstat (limited to 'app/features/settings/middleware.js')
-rw-r--r-- | app/features/settings/middleware.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/app/features/settings/middleware.js b/app/features/settings/middleware.js new file mode 100644 index 0000000..0d6e489 --- /dev/null +++ b/app/features/settings/middleware.js @@ -0,0 +1,24 @@ +// @flow + +import { getAvatarURL } from '../utils'; +import { SET_EMAIL, SET_NAME } from './actionTypes'; +import { setAvatarURL } from './actions'; + +export default (store: Object) => (next: Function) => (action: Object) => { + const result = next(action); + const state = store.getState(); + + switch (action.type) { + case SET_EMAIL: + case SET_NAME: { + const avatarURL = getAvatarURL({ + email: state.settings.email, + id: state.settings.name + }); + + store.dispatch(setAvatarURL(avatarURL)); + } + } + + return result; +}; |