diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 8ad5b44762..7148848af1 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -660,7 +660,7 @@ module.exports = React.createClass({ right_panel = break; case this.PageTypes.UserSettings: - page_element = + page_element = right_panel = break; case this.PageTypes.CreateRoom: diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index 59187bb69f..aa46a7770c 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -17,19 +17,24 @@ var React = require('react'); var sdk = require('../../index'); var MatrixClientPeg = require("../../MatrixClientPeg"); var Modal = require('../../Modal'); +var dis = require('matrix-react-sdk/lib/dispatcher') var q = require('q'); var version = require('../../../package.json').version; +var UserSettingsStore = require('matrix-react-sdk/lib/UserSettingsStore'); module.exports = React.createClass({ displayName: 'UserSettings', + Phases: { Loading: "loading", + Saving: "saving", Display: "display", }, getInitialState: function() { return { avatarUrl: null, + displayName: null, threePids: [], clientVersion: version, phase: this.Phases.Loading, @@ -38,23 +43,113 @@ module.exports = React.createClass({ componentWillMount: function() { var self = this; - var cli = MatrixClientPeg.get(); - var profile_d = cli.getProfileInfo(cli.credentials.userId); - var threepid_d = cli.getThreePids(); + var profilePromise = UserSettingsStore.loadProfileInfo(); + var threepidPromise = UserSettingsStore.loadThreePids(); - q.all([profile_d, threepid_d]).then( + q.all([profilePromise, threepidPromise]).then( function(resps) { self.setState({ avatarUrl: resps[0].avatar_url, + displayName: resps[0].displayname, threepids: resps[1].threepids, phase: self.Phases.Display, }); + + // keep a copy of the original state in order to track changes + self.setState({ + originalState: self.state + }); }, - function(err) { console.err(err); } + function(error) { + var ErrorDialog = sdk.getComponent("organisms.ErrorDialog"); + Modal.createDialog(ErrorDialog, { + title: "Can't load user settings", + description: error.toString() + }); + } ); }, + componentDidMount: function() { + this.dispatcherRef = dis.register(this.onAction); + }, + + componentWillUnmount: function() { + dis.unregister(this.dispatcherRef); + }, + + onSaveClicked: function(ev) { + var self = this; + var savePromises = []; + + // XXX: this is managed in ChangeAvatar.js, although could be moved out here in order + // to allow for the change to be staged alongside the rest of the form. + // + // if (this.state.originalState.avatarUrl !== this.state.avatarUrl) { + // savePromises.push( UserSettingsStore.saveAvatarUrl(this.state.avatarUrl) ); + // } + + if (this.state.originalState.displayName !== this.state.displayName) { + savePromises.push( UserSettingsStore.saveDisplayName(this.state.displayName) ); + } + + if (this.state.originalState.threepids.length !== this.state.threepids.length || + this.state.originalState.threepids.every(function(element, index) { + return element === this.state.threepids[index]; + })) + { + savePromises.push( UserSettingsStore.saveThreePids(this.state.threepids) ); + } + + self.setState({ + phase: self.Phases.Saving, + }); + + q.all(savePromises).then( + function(resps) { + self.setState({ + phase: self.Phases.Display, + }); + self.onClose(); + }, + function(error) { + self.setState({ + phase: self.Phases.Display, + }); + var ErrorDialog = sdk.getComponent("organisms.ErrorDialog"); + Modal.createDialog(ErrorDialog, { + title: "Can't save user settings", + description: error.toString() + }); + } + ); + }, + + onClose: function(ev) { + // XXX: use browser history instead to find the previous room? + if (this.props.roomId) { + dis.dispatch({ + action: 'view_room', + room_id: this.props.roomId, + }); + } + else { + dis.dispatch({ + action: 'view_indexed_room', + roomIndex: 0, + }); + } + }, + + onAction: function(payload) { + if (payload.action === "notifier_enabled") { + this.setState({ + enableNotifications : UserSettingsStore.getEnableNotifications() + }); + } + }, + editAvatar: function() { var url = MatrixClientPeg.get().mxcUrlToHttp(this.state.avatarUrl); var ChangeAvatar = sdk.getComponent('settings.ChangeAvatar'); @@ -69,17 +164,8 @@ module.exports = React.createClass({ this.avatarDialog = Modal.createDialogWithElement(avatarDialog); }, - addEmail: function() { - - }, - - editDisplayName: function() { - this.refs.displayname.edit(); - }, - - changePassword: function() { - var ChangePassword = sdk.getComponent('settings.ChangePassword'); - Modal.createDialog(ChangePassword); + onAvatarDialogCancel: function() { + this.avatarDialog.close(); }, onLogoutClicked: function(ev) { @@ -91,72 +177,116 @@ module.exports = React.createClass({ this.logoutModal.closeDialog(); }, - onAvatarDialogCancel: function() { - this.avatarDialog.close(); + onDisplayNameChange: function(event) { + this.setState({ displayName: event.target.value }); + }, + + onEnableNotificationsChange: function(event) { + // don't bother waiting for Save to be clicked, as that'd be silly + UserSettingsStore.setEnableNotifications( this.refs.enableNotifications.value ); + this.setState({ + enableNotifications : UserSettingsStore.getEnableNotifications() + }); }, render: function() { - var Loader = sdk.getComponent("elements.Spinner"); - if (this.state.phase === this.Phases.Loading) { - return - } - else if (this.state.phase === this.Phases.Display) { - var ChangeDisplayName = sdk.getComponent('settings.ChangeDisplayName'); - var EnableNotificationsButton = sdk.getComponent('settings.EnableNotificationsButton'); - return ( -
-
-

User Settings

-
-
-
-
- Profile Photo -
-
- Edit + var Loader = sdk.getComponent("atoms.Spinner"); + var saving; + switch (this.state.phase) { + case this.Phases.Loading: + return + case this.Phases.Saving: + saving = + case this.Phases.Display: + var RoomHeader = sdk.getComponent('molecules.RoomHeader'); + return ( +
+ + +

Profile

+ +
+
+
+
+ +
+
+ +
+
+ + {this.state.threepids.map(function(val) { + var id = "email-" + val.address; + return ( +
+
+ +
+
+ +
+
+ ); + })} + +
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+ +
+ +
+
-
- -
- Edit +
+
Log out
+
+ +

Notifications

+ +
+
+
+
+ +
+
+ +
+
-
- {this.state.threepids.map(function(val) { - return
{val.address}
; - })} +

Advanced

+ +
+
+ Version {this.state.clientVersion} +
-
- Add email +
+
{ saving }
+
Save and close
-
- -
-

Global Settings

-
-
-
- Change Password -
-
- Version {this.state.clientVersion} -
-
- -
-
- -
-
-
-
- ); + ); } } }); diff --git a/src/components/views/rooms/RoomHeader.js b/src/components/views/rooms/RoomHeader.js index 068dff85d6..bc5c70ce08 100644 --- a/src/components/views/rooms/RoomHeader.js +++ b/src/components/views/rooms/RoomHeader.js @@ -73,10 +73,15 @@ module.exports = React.createClass({ var header; if (this.props.simpleHeader) { + var cancel; + if (this.props.onCancelClick) { + cancel = Close + } header =
{ this.props.simpleHeader } + { cancel }
}