mirror of
https://github.com/urbit/shrub.git
synced 2024-12-19 00:13:12 +03:00
chat-js: on selecting a group from search, set id of chat to that name and disable form
This commit is contained in:
parent
41f1cb67ca
commit
2cae31783e
File diff suppressed because one or more lines are too long
@ -12,10 +12,8 @@ export class NewScreen extends Component {
|
|||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
idName: '',
|
idName: '',
|
||||||
invites: {
|
groups: [],
|
||||||
groups: [],
|
ships: [],
|
||||||
ships: []
|
|
||||||
},
|
|
||||||
security: 'village',
|
security: 'village',
|
||||||
idError: false,
|
idError: false,
|
||||||
inviteError: false,
|
inviteError: false,
|
||||||
@ -23,6 +21,7 @@ export class NewScreen extends Component {
|
|||||||
createGroup: true
|
createGroup: true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.idName = React.createRef();
|
||||||
this.idChange = this.idChange.bind(this);
|
this.idChange = this.idChange.bind(this);
|
||||||
this.securityChange = this.securityChange.bind(this);
|
this.securityChange = this.securityChange.bind(this);
|
||||||
this.allowHistoryChange = this.allowHistoryChange.bind(this);
|
this.allowHistoryChange = this.allowHistoryChange.bind(this);
|
||||||
@ -48,7 +47,20 @@ export class NewScreen extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setInvite(value) {
|
setInvite(value) {
|
||||||
this.setState({invites: value});
|
if (value.groups.length > 0) {
|
||||||
|
let idName = value.groups[0].split('/')[2];
|
||||||
|
this.idName.current.value = idName;
|
||||||
|
this.setState({
|
||||||
|
idName,
|
||||||
|
groups: value.groups,
|
||||||
|
ships: value.ships
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.setState({
|
||||||
|
groups: value.groups,
|
||||||
|
ships: value.ships
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
securityChange(event) {
|
securityChange(event) {
|
||||||
@ -107,21 +119,13 @@ export class NewScreen extends Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let aud = [];
|
|
||||||
let isValid = true;
|
let isValid = true;
|
||||||
if ((state.invites.groups.length > 0) || (state.invites.ships.length > 0)) {
|
let aud = state.ships.map(mem => `~${deSig(mem.trim())}`);
|
||||||
if (state.invites.groups.length > 0) {
|
aud.forEach((mem) => {
|
||||||
aud = props.groups[state.invites.groups].values();
|
if (!urbitOb.isValidPatp(mem)) {
|
||||||
|
isValid = false;
|
||||||
}
|
}
|
||||||
else {
|
});
|
||||||
aud = state.invites.ships.map(mem => `~${deSig(mem.trim())}`);
|
|
||||||
}
|
|
||||||
aud.forEach((mem) => {
|
|
||||||
if (!urbitOb.isValidPatp(mem)) {
|
|
||||||
isValid = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isValid) {
|
if (!isValid) {
|
||||||
this.setState({
|
this.setState({
|
||||||
@ -139,17 +143,15 @@ export class NewScreen extends Component {
|
|||||||
this.setState({
|
this.setState({
|
||||||
error: false,
|
error: false,
|
||||||
success: true,
|
success: true,
|
||||||
invites: {
|
group: [],
|
||||||
groups: [],
|
ships: []
|
||||||
ships: []
|
|
||||||
}
|
|
||||||
}, () => {
|
}, () => {
|
||||||
props.setSpinner(true);
|
props.setSpinner(true);
|
||||||
// if we want a "proper group" that can be managed from the contacts UI,
|
// if we want a "proper group" that can be managed from the contacts UI,
|
||||||
// we make a path of the form /~zod/cool-group
|
// we make a path of the form /~zod/cool-group
|
||||||
// if not, we make a path of the form /~/~zod/free-chat
|
// if not, we make a path of the form /~/~zod/free-chat
|
||||||
let chatPath = `/~${window.ship}${station}`;
|
let chatPath = `/~${window.ship}${station}`;
|
||||||
if (!state.createGroup || state.invites.groups.length > 0) {
|
if (!state.createGroup || state.groups.length === 0) {
|
||||||
chatPath = '/~' + chatPath;
|
chatPath = '/~' + chatPath;
|
||||||
}
|
}
|
||||||
props.api.chatView.create(
|
props.api.chatView.create(
|
||||||
@ -159,23 +161,30 @@ export class NewScreen extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let inviteSwitchClasses = (this.state.security === "village")
|
const { props, state } = this;
|
||||||
|
let inviteSwitchClasses = (state.security === "village")
|
||||||
? "relative checked bg-green2 br3 h1 toggle v-mid z-0"
|
? "relative checked bg-green2 br3 h1 toggle v-mid z-0"
|
||||||
: "relative bg-gray4 bg-gray1-d br3 h1 toggle v-mid z-0";
|
: "relative bg-gray4 bg-gray1-d br3 h1 toggle v-mid z-0";
|
||||||
if (this.state.createGroup) {
|
if (state.createGroup) {
|
||||||
inviteSwitchClasses = inviteSwitchClasses + " o-50";
|
inviteSwitchClasses = inviteSwitchClasses + " o-50";
|
||||||
}
|
}
|
||||||
|
|
||||||
let createGroupClasses = this.state.createGroup
|
let createGroupClasses = state.createGroup
|
||||||
? "relative checked bg-green2 br3 h1 toggle v-mid z-0"
|
? "relative checked bg-green2 br3 h1 toggle v-mid z-0"
|
||||||
: "relative bg-gray4 bg-gray1-d br3 h1 toggle v-mid z-0";
|
: "relative bg-gray4 bg-gray1-d br3 h1 toggle v-mid z-0";
|
||||||
|
|
||||||
let createClasses = !!this.state.idName
|
let createClasses = !!state.idName
|
||||||
? "pointer db f9 green2 bg-gray0-d ba pv3 ph4 b--green2"
|
? "pointer db f9 green2 bg-gray0-d ba pv3 ph4 b--green2"
|
||||||
: "pointer db f9 gray2 ba bg-gray0-d pa2 pv3 ph4 b--gray3";
|
: "pointer db f9 gray2 ba bg-gray0-d pa2 pv3 ph4 b--gray3";
|
||||||
|
|
||||||
|
let idClasses =
|
||||||
|
"f7 ba b--gray3 b--gray2-d bg-gray0-d white-d pa3 db w-100 ";
|
||||||
|
if (state.groups.length > 0) {
|
||||||
|
idClasses = idClasses + " o-40";
|
||||||
|
}
|
||||||
|
|
||||||
let idErrElem = (<span />);
|
let idErrElem = (<span />);
|
||||||
if (this.state.idError) {
|
if (state.idError) {
|
||||||
idErrElem = (
|
idErrElem = (
|
||||||
<span className="f9 inter red2 db pt2">
|
<span className="f9 inter red2 db pt2">
|
||||||
Chat must have a valid name.
|
Chat must have a valid name.
|
||||||
@ -184,7 +193,7 @@ export class NewScreen extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let createGroupToggle = <div/>
|
let createGroupToggle = <div/>
|
||||||
if (this.state.invites.groups.length === 0) {
|
if (state.groups.length === 0) {
|
||||||
createGroupToggle = (
|
createGroupToggle = (
|
||||||
<div className="mv7">
|
<div className="mv7">
|
||||||
<input
|
<input
|
||||||
@ -217,13 +226,15 @@ export class NewScreen extends Component {
|
|||||||
Lowercase alphanumeric characters, dashes, and slashes only
|
Lowercase alphanumeric characters, dashes, and slashes only
|
||||||
</p>
|
</p>
|
||||||
<textarea
|
<textarea
|
||||||
className="f7 ba b--gray3 b--gray2-d bg-gray0-d white-d pa3 db w-100"
|
className={idClasses}
|
||||||
placeholder="secret-chat"
|
placeholder="secret-chat"
|
||||||
rows={1}
|
rows={1}
|
||||||
style={{
|
style={{
|
||||||
resize: "none"
|
resize: "none"
|
||||||
}}
|
}}
|
||||||
onChange={this.idChange}
|
onChange={this.idChange}
|
||||||
|
ref={this.idName}
|
||||||
|
disabled={(state.groups.length > 0) ? "disabled" : false}
|
||||||
/>
|
/>
|
||||||
{idErrElem}
|
{idErrElem}
|
||||||
<p className="f8 mt4 lh-copy db">
|
<p className="f8 mt4 lh-copy db">
|
||||||
@ -234,8 +245,11 @@ export class NewScreen extends Component {
|
|||||||
Selected entities will be able to post to chat
|
Selected entities will be able to post to chat
|
||||||
</p>
|
</p>
|
||||||
<InviteSearch
|
<InviteSearch
|
||||||
groups={this.props.groups}
|
groups={props.groups}
|
||||||
invites={this.state.invites}
|
invites={{
|
||||||
|
groups: state.groups,
|
||||||
|
ships: state.ships
|
||||||
|
}}
|
||||||
setInvite={this.setInvite}
|
setInvite={this.setInvite}
|
||||||
/>
|
/>
|
||||||
{createGroupToggle}
|
{createGroupToggle}
|
||||||
|
Loading…
Reference in New Issue
Block a user