Skip to content
This repository has been archived by the owner on Oct 1, 2019. It is now read-only.

Commit

Permalink
Allow anonymous users to set preferences
Browse files Browse the repository at this point in the history
Support saving the sidebar's autocollapsing status by anonymous users
  • Loading branch information
artkravchenko committed Nov 7, 2017
1 parent 45d4116 commit 767847e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/components/sidebar/desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class SidebarDesktop extends React.PureComponent {
static propTypes = {
autocollapsible: PropTypes.bool,
collapsed: PropTypes.bool,
current_user: PropTypes.shape()
current_user: PropTypes.shape(),
is_logged_in: PropTypes.bool
};

static defaultProps = {
Expand Down Expand Up @@ -149,11 +150,10 @@ class SidebarDesktop extends React.PureComponent {
() => {
const client = new ApiClient(API_HOST);
const triggers = new ActionsTrigger(client, this.props.dispatch);
triggers.updateUserInfo({
more: {
sidebar: { collapsed: this.state.collapsed }
}
});
triggers.updateUserInfo(
{ more: { sidebar: { collapsed: this.state.collapsed } } },
this.props.is_logged_in
);
}
);
};
Expand Down
7 changes: 4 additions & 3 deletions src/selectors/currentUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ function selectCurrentUser(state) {
const currentUser = state.get('current_user');

return currentUser.withMutations(function (currentUser) {
currentUser.set('user', state.getIn(['users', currentUser.get('id')]));
currentUser.set('likes', state.getIn(['likes', currentUser.get('id')]) || i.List());
currentUser.set('favourites', state.getIn(['favourites', currentUser.get('id')]) || i.List());
const id = currentUser.get('id') || 'null';
currentUser.set('user', state.getIn(['users', id]));
currentUser.set('likes', state.getIn(['likes', id]) || i.List());
currentUser.set('favourites', state.getIn(['favourites', id]) || i.List());
});
}

Expand Down
8 changes: 7 additions & 1 deletion src/triggers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,13 @@ export class ActionsTrigger {
return status;
};

updateUserInfo = async (user) => {
updateUserInfo = async (user, isLoggedIn = true) => {
if (!isLoggedIn) {
this.dispatch(a.messages.addMessage('Saved successfully'));
this.dispatch(a.users.addUser({ id: null, ...user }));
return true;
}

let status = false;
try {
const res = await this.client.updateUser(user);
Expand Down

0 comments on commit 767847e

Please sign in to comment.