Make CreateRoom remember what the values of its fields were. Remove some fairly pointless atoms

pull/1/head
Erik Johnston 2015-07-16 17:20:03 +01:00
parent 47f4c0dfff
commit aa1b763518
10 changed files with 55 additions and 203 deletions

View File

@ -25,7 +25,7 @@ module.exports = React.createClass({
mixins: [RoomAliasController], mixins: [RoomAliasController],
onValueChanged: function(ev) { onValueChanged: function(ev) {
this.setState({room_alias: ev.target.value}) this.props.onChange(ev.target.value);
}, },
onFocus: function(ev) { onFocus: function(ev) {
@ -72,7 +72,8 @@ module.exports = React.createClass({
render: function() { render: function() {
return ( return (
<input type="text" className="mx_RoomAlias" placeholder="Alias (optional)" <input type="text" className="mx_RoomAlias" placeholder="Alias (optional)"
onChange={this.onValueChanged} onFocus={this.onFocus} onBlur={this.onBlur}/> onChange={this.onValueChanged} onFocus={this.onFocus} onBlur={this.onBlur}
value={this.props.alias}/>
); );
} }
}); });

View File

@ -1,36 +0,0 @@
/*
Copyright 2015 OpenMarket Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
'use strict';
var React = require('react');
var RoomNameTextboxController = require("../../../../../src/controllers/atoms/create_room/RoomNameTextbox");
module.exports = React.createClass({
displayName: 'RoomNameTextbox',
mixins: [RoomNameTextboxController],
onValueChanged: function(ev) {
this.setState({room_name: ev.target.value})
},
render: function() {
return (
<input type="text" className="mx_RoomNameTextbox" placeholder="Name" onChange={this.onValueChanged}/>
);
}
});

View File

@ -1,37 +0,0 @@
/*
Copyright 2015 OpenMarket Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
'use strict';
var React = require('react');
var RoomTopicController = require("../../../../../src/controllers/atoms/create_room/RoomTopic");
module.exports = React.createClass({
displayName: 'RoomTopic',
mixins: [RoomTopicController],
onValueChanged: function(ev) {
this.setState({room_topic: ev.target.value})
},
render: function() {
return (
<textarea className="mx_RoomTopic" placeholder="Description" onChange={this.onValueChanged}>
</textarea>
);
}
});

View File

@ -32,7 +32,7 @@ module.exports = React.createClass({
return ( return (
<div> <div>
<ul className="mx_UserSelector_UserIdList" ref="list"> <ul className="mx_UserSelector_UserIdList" ref="list">
{this.state.selected_users.map(function(user_id, i) { {this.props.selected_users.map(function(user_id, i) {
return <li key={user_id}>{user_id}</li> return <li key={user_id}>{user_id}</li>
})} })}
</ul> </ul>

View File

@ -97,6 +97,30 @@ module.exports = React.createClass({
}); });
}, },
onTopicChange: function(ev) {
this.setState({
topic: ev.target.value,
});
},
onNameChange: function(ev) {
this.setState({
room_name: ev.target.value,
});
},
onInviteChanged: function(invited_users) {
this.setState({
invited_users: invited_users,
});
},
onAliasChanged: function(alias) {
this.setState({
alias: alias
})
},
render: function() { render: function() {
var curr_phase = this.state.phase; var curr_phase = this.state.phase;
if (curr_phase == this.phases.CREATING) { if (curr_phase == this.phases.CREATING) {
@ -114,10 +138,10 @@ module.exports = React.createClass({
} }
return ( return (
<div className="mx_CreateRoom"> <div className="mx_CreateRoom">
<RoomNameTextbox ref="name_textbox" /> <br /> <input type="text" ref="room_name" value={this.state.room_name} onChange={this.onNameChange} placeholder="Name"/> <br />
<RoomTopic ref="topic"/> <br /> <textarea ref="topic" value={this.state.topic} onChange={this.onTopicChange} placeholder="Description"/> <br />
<RoomAlias ref="alias"/> <br /> <RoomAlias ref="alias" alias={this.state.alias} onChange={this.onAliasChanged}/> <br />
<UserSelector ref="user_selector"/> <br /> <UserSelector ref="user_selector" selected_users={this.state.invited_users} onChange={this.onInviteChanged}/> <br />
<Presets ref="presets" onChange={this.onPresetChanged} preset={this.state.preset}/> <br /> <Presets ref="presets" onChange={this.onPresetChanged} preset={this.state.preset}/> <br />
<label><input type="checkbox" ref="is_private" checked={this.state.is_private} onChange={this.onPrivateChanged}/> Make this room private</label> <label><input type="checkbox" ref="is_private" checked={this.state.is_private} onChange={this.onPrivateChanged}/> Make this room private</label>
<label><input type="checkbox" ref="share_history" checked={this.state.share_history} onChange={this.onShareHistoryChanged}/> Share message history with new users</label> <label><input type="checkbox" ref="share_history" checked={this.state.share_history} onChange={this.onShareHistoryChanged}/> Share message history with new users</label>

View File

@ -23,23 +23,19 @@ module.exports = {
// Specifying a homeserver will make magical things happen when you, // Specifying a homeserver will make magical things happen when you,
// e.g. start typing in the room alias box. // e.g. start typing in the room alias box.
homeserver: React.PropTypes.string, homeserver: React.PropTypes.string,
default_alias: React.PropTypes.string alias: React.PropTypes.string,
onChange: React.PropTypes.func,
}, },
getDefaultProps: function() { getDefaultProps: function() {
return { return {
default_alias: '', onChange: function() {},
alias: '',
}; };
}, },
getInitialState: function() {
return {
room_alias: this.props.default_alias,
}
},
getAliasLocalpart: function() { getAliasLocalpart: function() {
var room_alias = this.state.room_alias; var room_alias = this.props.alias;
if (room_alias && this.props.homeserver) { if (room_alias && this.props.homeserver) {
var suffix = ":" + this.props.homeserver; var suffix = ":" + this.props.homeserver;

View File

@ -1,41 +0,0 @@
/*
Copyright 2015 OpenMarket Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
'use strict';
var React = require('react');
module.exports = {
propTypes: {
default_name: React.PropTypes.string
},
getDefaultProps: function() {
return {
default_name: '',
};
},
getInitialState: function() {
return {
room_name: this.props.default_name,
}
},
getName: function() {
return this.state.room_name;
},
};

View File

@ -1,41 +0,0 @@
/*
Copyright 2015 OpenMarket Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
'use strict';
var React = require('react');
module.exports = {
propTypes: {
default_topic: React.PropTypes.string
},
getDefaultProps: function() {
return {
default_topic: '',
};
},
getInitialState: function() {
return {
room_topic: this.props.default_topic,
}
},
getTopic: function() {
return this.state.room_topic;
},
};

View File

@ -20,38 +20,26 @@ var React = require('react');
module.exports = { module.exports = {
propTypes: { propTypes: {
initially_selected: React.PropTypes.arrayOf(React.PropTypes.string), onChange: React.PropTypes.func,
selected_users: React.PropTypes.arrayOf(React.PropTypes.string),
}, },
getDefaultProps: function() { getDefaultProps: function() {
return { return {
initially_selected: [], onChange: function() {},
selected: [],
}; };
}, },
getInitialState: function() {
return {
selected_users: this.props.initially_selected,
}
},
addUser: function(user_id) { addUser: function(user_id) {
if (this.state.selected_users.indexOf(user_id == -1)) { if (this.props.selected_users.indexOf(user_id == -1)) {
this.setState({ this.props.onChange(this.props.selected_users.concat([user_id]));
selected_users: this.state.selected_users.concat([user_id]),
});
} }
}, },
removeUser: function(user_id) { removeUser: function(user_id) {
this.setState({ this.props.onChange(this.state.selected_users.filter(function(e) {
selected_users: this.state.selected_users.filter(function(e) { return e != user_id;
return e != user_id; }));
}),
});
}, },
getUserIds: function() {
return this.state.selected_users;
}
}; };

View File

@ -44,21 +44,22 @@ module.exports = {
error_string: "", error_string: "",
is_private: true, is_private: true,
share_history: false, share_history: false,
default_preset: PresetValues.PrivateChat default_preset: PresetValues.PrivateChat,
topic: '',
room_name: '',
invited_users: [],
}; };
}, },
onCreateRoom: function() { onCreateRoom: function() {
var options = {}; var options = {};
var room_name = this.getName(); if (this.state.room_name) {
if (room_name) { options.name = this.state.room_name;
options.name = room_name;
} }
var room_topic = this.getTopic(); if (this.state.topic) {
if (room_name) { options.topic = this.state.topic;
options.topic = room_topic;
} }
var preset = this.getPreset(); var preset = this.getPreset();
@ -83,10 +84,7 @@ module.exports = {
} }
} }
var invited_users = this.getInvitedUsers(); options.invite = this.state.invited_users;
if (invited_users) {
options.invite = invited_users;
}
var alias = this.getAliasLocalpart(); var alias = this.getAliasLocalpart();
if (alias) { if (alias) {