Skip to content

add clearProfile action and reducer for clear all profile info #21

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

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions __tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Object {
"addSkillInit": [Function],
"addWebLinkDone": [Function],
"addWebLinkInit": [Function],
"clearProfile": [Function],
"deletePhotoDone": [Function],
"deletePhotoInit": [Function],
"deleteWebLinkDone": [Function],
Expand Down
1 change: 1 addition & 0 deletions __tests__/actions/__snapshots__/profile.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Object {
"addSkillInit": [Function],
"addWebLinkDone": [Function],
"addWebLinkInit": [Function],
"clearProfile": [Function],
"deletePhotoDone": [Function],
"deletePhotoInit": [Function],
"deleteWebLinkDone": [Function],
Expand Down
12 changes: 12 additions & 0 deletions docs/actions.profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Actions for interactions with profile details API.

* [actions.profile](#module_actions.profile)
* [.loadProfile(handle)](#module_actions.profile.loadProfile) ⇒ <code>Action</code>
* [.clearProfile()](#module_actions.profile.clearProfile) ⇒ <code>Action</code>
* [.getAchievementsInit()](#module_actions.profile.getAchievementsInit) ⇒ <code>Action</code>
* [.getAchievementsDone(handle)](#module_actions.profile.getAchievementsDone) ⇒ <code>Action</code>
* [.getExternalAccountsInit()](#module_actions.profile.getExternalAccountsInit) ⇒ <code>Action</code>
Expand Down Expand Up @@ -67,6 +68,17 @@ Creates and action that loads user profile.
| --- | --- | --- |
| handle | <code>String</code> | User handle. |

<a name="module_actions.profile.clearProfile"></a>

### actions.profile.clearProfile() ⇒ <code>Action</code>
Creates and action that clear user profile.

**Kind**: static method of [<code>actions.profile</code>](#module_actions.profile)
**Todo**

- [ ] This action does not follow the pattern with init/done pairs of
actions. Should be improved.

<a name="module_actions.profile.getAchievementsInit"></a>

### actions.profile.getAchievementsInit() ⇒ <code>Action</code>
Expand Down
9 changes: 9 additions & 0 deletions src/actions/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ function loadProfile(handle) {
return handle;
}

/**
* @static
* @desc Creates and action that clear user profile.
* @todo This action does not follow the pattern with init/done pairs of
* actions. Should be improved.
*/
function clearProfile() {}

/**
* @static
* @desc Creates an action that signals beginning of user achievements loading.
Expand Down Expand Up @@ -415,6 +423,7 @@ function updatePasswordDone(profile, tokenV3, newPassword, oldPassword) {
export default createActions({
PROFILE: {
LOAD_PROFILE: loadProfile,
CLEAR_PROFILE: clearProfile,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just use Lodash's noop instead of an empty method?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me try

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ThomasKranitsas you mean _.noop ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah noop work, updated the code, pls check

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GET_ACHIEVEMENTS_INIT: getAchievementsInit,
GET_ACHIEVEMENTS_DONE: getAchievementsDone,
GET_EXTERNAL_ACCOUNTS_INIT: getExternalAccountsInit,
Expand Down
3 changes: 3 additions & 0 deletions src/reducers/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@ function onUpdatePasswordDone(state, { payload, error }) {
function create(initialState) {
const a = actions.profile;
return handleActions({
[a.clearProfile]: state => ({
...state, achievements: null, country: '', info: null, skills: null, stats: null,
}),
[a.loadProfile]: (state, action) => ({ ...state, profileForHandle: action.payload }),
[a.getAchievementsInit]: state => state,
[a.getAchievementsDone]: onGetAchievementsDone,
Expand Down