Make CreateRoom remember what the values of its fields were. Remove some fairly pointless atoms
This commit is contained in:
parent
47f4c0dfff
commit
aa1b763518
10 changed files with 55 additions and 203 deletions
|
@ -23,23 +23,19 @@ module.exports = {
|
|||
// Specifying a homeserver will make magical things happen when you,
|
||||
// e.g. start typing in the room alias box.
|
||||
homeserver: React.PropTypes.string,
|
||||
default_alias: React.PropTypes.string
|
||||
alias: React.PropTypes.string,
|
||||
onChange: React.PropTypes.func,
|
||||
},
|
||||
|
||||
getDefaultProps: function() {
|
||||
return {
|
||||
default_alias: '',
|
||||
onChange: function() {},
|
||||
alias: '',
|
||||
};
|
||||
},
|
||||
|
||||
getInitialState: function() {
|
||||
return {
|
||||
room_alias: this.props.default_alias,
|
||||
}
|
||||
},
|
||||
|
||||
getAliasLocalpart: function() {
|
||||
var room_alias = this.state.room_alias;
|
||||
var room_alias = this.props.alias;
|
||||
|
||||
if (room_alias && this.props.homeserver) {
|
||||
var suffix = ":" + this.props.homeserver;
|
||||
|
|
|
@ -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;
|
||||
},
|
||||
};
|
|
@ -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;
|
||||
},
|
||||
};
|
|
@ -20,38 +20,26 @@ var React = require('react');
|
|||
|
||||
module.exports = {
|
||||
propTypes: {
|
||||
initially_selected: React.PropTypes.arrayOf(React.PropTypes.string),
|
||||
onChange: React.PropTypes.func,
|
||||
selected_users: React.PropTypes.arrayOf(React.PropTypes.string),
|
||||
},
|
||||
|
||||
getDefaultProps: function() {
|
||||
return {
|
||||
initially_selected: [],
|
||||
onChange: function() {},
|
||||
selected: [],
|
||||
};
|
||||
},
|
||||
|
||||
getInitialState: function() {
|
||||
return {
|
||||
selected_users: this.props.initially_selected,
|
||||
}
|
||||
},
|
||||
|
||||
addUser: function(user_id) {
|
||||
if (this.state.selected_users.indexOf(user_id == -1)) {
|
||||
this.setState({
|
||||
selected_users: this.state.selected_users.concat([user_id]),
|
||||
});
|
||||
if (this.props.selected_users.indexOf(user_id == -1)) {
|
||||
this.props.onChange(this.props.selected_users.concat([user_id]));
|
||||
}
|
||||
},
|
||||
|
||||
removeUser: function(user_id) {
|
||||
this.setState({
|
||||
selected_users: this.state.selected_users.filter(function(e) {
|
||||
return e != user_id;
|
||||
}),
|
||||
});
|
||||
this.props.onChange(this.state.selected_users.filter(function(e) {
|
||||
return e != user_id;
|
||||
}));
|
||||
},
|
||||
|
||||
getUserIds: function() {
|
||||
return this.state.selected_users;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -44,21 +44,22 @@ module.exports = {
|
|||
error_string: "",
|
||||
is_private: true,
|
||||
share_history: false,
|
||||
default_preset: PresetValues.PrivateChat
|
||||
default_preset: PresetValues.PrivateChat,
|
||||
topic: '',
|
||||
room_name: '',
|
||||
invited_users: [],
|
||||
};
|
||||
},
|
||||
|
||||
onCreateRoom: function() {
|
||||
var options = {};
|
||||
|
||||
var room_name = this.getName();
|
||||
if (room_name) {
|
||||
options.name = room_name;
|
||||
if (this.state.room_name) {
|
||||
options.name = this.state.room_name;
|
||||
}
|
||||
|
||||
var room_topic = this.getTopic();
|
||||
if (room_name) {
|
||||
options.topic = room_topic;
|
||||
if (this.state.topic) {
|
||||
options.topic = this.state.topic;
|
||||
}
|
||||
|
||||
var preset = this.getPreset();
|
||||
|
@ -83,10 +84,7 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
|
||||
var invited_users = this.getInvitedUsers();
|
||||
if (invited_users) {
|
||||
options.invite = invited_users;
|
||||
}
|
||||
options.invite = this.state.invited_users;
|
||||
|
||||
var alias = this.getAliasLocalpart();
|
||||
if (alias) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue