Add way to specify address during public space creation
This commit is contained in:
parent
b2b95257a8
commit
8c34a8461e
3 changed files with 40 additions and 9 deletions
|
@ -16,7 +16,7 @@ limitations under the License.
|
||||||
|
|
||||||
.mx_SpaceBasicSettings {
|
.mx_SpaceBasicSettings {
|
||||||
.mx_Field {
|
.mx_Field {
|
||||||
margin: 32px 0;
|
margin: 24px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mx_SpaceBasicSettings_avatarContainer {
|
.mx_SpaceBasicSettings_avatarContainer {
|
||||||
|
|
|
@ -33,6 +33,7 @@ import {USER_LABS_TAB} from "../dialogs/UserSettingsDialog";
|
||||||
import Field from "../elements/Field";
|
import Field from "../elements/Field";
|
||||||
import withValidation from "../elements/Validation";
|
import withValidation from "../elements/Validation";
|
||||||
import {SpaceFeedbackPrompt} from "../../structures/SpaceRoomView";
|
import {SpaceFeedbackPrompt} from "../../structures/SpaceRoomView";
|
||||||
|
import RoomAliasField from "../elements/RoomAliasField";
|
||||||
|
|
||||||
const SpaceCreateMenuType = ({ title, description, className, onClick }) => {
|
const SpaceCreateMenuType = ({ title, description, className, onClick }) => {
|
||||||
return (
|
return (
|
||||||
|
@ -58,6 +59,11 @@ const spaceNameValidator = withValidation({
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const nameToAlias = (name: string, domain: string): string => {
|
||||||
|
const localpart = name.trim().toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9_-]+/gi, "");
|
||||||
|
return `#${localpart}:${domain}`;
|
||||||
|
};
|
||||||
|
|
||||||
const SpaceCreateMenu = ({ onFinished }) => {
|
const SpaceCreateMenu = ({ onFinished }) => {
|
||||||
const cli = useContext(MatrixClientContext);
|
const cli = useContext(MatrixClientContext);
|
||||||
const [visibility, setVisibility] = useState<Visibility>(null);
|
const [visibility, setVisibility] = useState<Visibility>(null);
|
||||||
|
@ -65,6 +71,8 @@ const SpaceCreateMenu = ({ onFinished }) => {
|
||||||
|
|
||||||
const [name, setName] = useState("");
|
const [name, setName] = useState("");
|
||||||
const spaceNameField = useRef<Field>();
|
const spaceNameField = useRef<Field>();
|
||||||
|
const [alias, setAlias] = useState("");
|
||||||
|
const spaceAliasField = useRef<RoomAliasField>();
|
||||||
const [avatar, setAvatar] = useState<File>(null);
|
const [avatar, setAvatar] = useState<File>(null);
|
||||||
const [topic, setTopic] = useState<string>("");
|
const [topic, setTopic] = useState<string>("");
|
||||||
|
|
||||||
|
@ -80,6 +88,13 @@ const SpaceCreateMenu = ({ onFinished }) => {
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// validate the space name alias field but do not require it
|
||||||
|
if (visibility === Visibility.Public && !await spaceAliasField.current.validate({ allowEmpty: true })) {
|
||||||
|
spaceAliasField.current.focus();
|
||||||
|
spaceAliasField.current.validate({ allowEmpty: true, focused: true });
|
||||||
|
setBusy(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const initialState: IStateEvent[] = [
|
const initialState: IStateEvent[] = [
|
||||||
{
|
{
|
||||||
|
@ -97,12 +112,6 @@ const SpaceCreateMenu = ({ onFinished }) => {
|
||||||
content: { url },
|
content: { url },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (topic) {
|
|
||||||
initialState.push({
|
|
||||||
type: EventType.RoomTopic,
|
|
||||||
content: { topic },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await createRoom({
|
await createRoom({
|
||||||
|
@ -110,7 +119,6 @@ const SpaceCreateMenu = ({ onFinished }) => {
|
||||||
preset: visibility === Visibility.Public ? Preset.PublicChat : Preset.PrivateChat,
|
preset: visibility === Visibility.Public ? Preset.PublicChat : Preset.PrivateChat,
|
||||||
name,
|
name,
|
||||||
creation_content: {
|
creation_content: {
|
||||||
// Based on MSC1840
|
|
||||||
[RoomCreateTypeField]: RoomType.Space,
|
[RoomCreateTypeField]: RoomType.Space,
|
||||||
},
|
},
|
||||||
initial_state: initialState,
|
initial_state: initialState,
|
||||||
|
@ -119,6 +127,8 @@ const SpaceCreateMenu = ({ onFinished }) => {
|
||||||
events_default: 100,
|
events_default: 100,
|
||||||
...Visibility.Public ? { invite: 0 } : {},
|
...Visibility.Public ? { invite: 0 } : {},
|
||||||
},
|
},
|
||||||
|
room_alias_name: alias ? alias.substr(1, alias.indexOf(":") - 1) : undefined,
|
||||||
|
topic,
|
||||||
},
|
},
|
||||||
spinner: false,
|
spinner: false,
|
||||||
encryption: false,
|
encryption: false,
|
||||||
|
@ -157,6 +167,7 @@ const SpaceCreateMenu = ({ onFinished }) => {
|
||||||
<SpaceFeedbackPrompt onClick={onFinished} />
|
<SpaceFeedbackPrompt onClick={onFinished} />
|
||||||
</React.Fragment>;
|
</React.Fragment>;
|
||||||
} else {
|
} else {
|
||||||
|
const domain = cli.getDomain();
|
||||||
body = <React.Fragment>
|
body = <React.Fragment>
|
||||||
<AccessibleTooltipButton
|
<AccessibleTooltipButton
|
||||||
className="mx_SpaceCreateMenu_back"
|
className="mx_SpaceCreateMenu_back"
|
||||||
|
@ -185,12 +196,30 @@ const SpaceCreateMenu = ({ onFinished }) => {
|
||||||
label={_t("Name")}
|
label={_t("Name")}
|
||||||
autoFocus={true}
|
autoFocus={true}
|
||||||
value={name}
|
value={name}
|
||||||
onChange={ev => setName(ev.target.value)}
|
onChange={ev => {
|
||||||
|
const newName = ev.target.value;
|
||||||
|
if (!alias || alias === nameToAlias(name, domain)) {
|
||||||
|
setAlias(nameToAlias(newName, domain));
|
||||||
|
}
|
||||||
|
setName(newName);
|
||||||
|
}}
|
||||||
ref={spaceNameField}
|
ref={spaceNameField}
|
||||||
onValidate={spaceNameValidator}
|
onValidate={spaceNameValidator}
|
||||||
disabled={busy}
|
disabled={busy}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{ visibility === Visibility.Public
|
||||||
|
? <RoomAliasField
|
||||||
|
ref={spaceAliasField}
|
||||||
|
onChange={setAlias}
|
||||||
|
domain={domain}
|
||||||
|
value={alias}
|
||||||
|
placeholder={name ? nameToAlias(name, domain) : _t("e.g. my-space")}
|
||||||
|
label={_t("Address")}
|
||||||
|
/>
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
|
||||||
<Field
|
<Field
|
||||||
name="spaceTopic"
|
name="spaceTopic"
|
||||||
element="textarea"
|
element="textarea"
|
||||||
|
|
|
@ -1016,6 +1016,8 @@
|
||||||
"Your private space": "Your private space",
|
"Your private space": "Your private space",
|
||||||
"Add some details to help people recognise it.": "Add some details to help people recognise it.",
|
"Add some details to help people recognise it.": "Add some details to help people recognise it.",
|
||||||
"You can change these anytime.": "You can change these anytime.",
|
"You can change these anytime.": "You can change these anytime.",
|
||||||
|
"e.g. my-space": "e.g. my-space",
|
||||||
|
"Address": "Address",
|
||||||
"Creating...": "Creating...",
|
"Creating...": "Creating...",
|
||||||
"Create": "Create",
|
"Create": "Create",
|
||||||
"Expand space panel": "Expand space panel",
|
"Expand space panel": "Expand space panel",
|
||||||
|
|
Loading…
Reference in a new issue