Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit d203e8f

Browse files
authored
Merge pull request #5923 from matrix-org/t3chguy/fix/16628
Space creation prompt user to add existing rooms for "Just Me" spaces
2 parents 4554124 + 9f8955f commit d203e8f

File tree

5 files changed

+245
-146
lines changed

5 files changed

+245
-146
lines changed

res/css/structures/_SpaceRoomView.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ $SpaceRoomViewInnerWidth: 428px;
8181
color: $secondary-fg-color;
8282
margin-top: 12px;
8383
margin-bottom: 24px;
84+
max-width: $SpaceRoomViewInnerWidth;
85+
}
86+
87+
.mx_AddExistingToSpace {
88+
max-width: $SpaceRoomViewInnerWidth;
89+
90+
.mx_AddExistingToSpace_content {
91+
height: calc(100vh - 360px);
92+
max-height: 400px;
93+
}
8494
}
8595

8696
.mx_SpaceRoomView_buttons {

res/css/views/dialogs/_AddExistingToSpaceDialog.scss

Lines changed: 62 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,66 @@ limitations under the License.
2121
}
2222
}
2323

24+
.mx_AddExistingToSpace {
25+
.mx_SearchBox {
26+
// To match the space around the title
27+
margin: 0 0 15px 0;
28+
flex-grow: 0;
29+
}
30+
31+
.mx_AddExistingToSpace_content {
32+
flex-grow: 1;
33+
}
34+
35+
.mx_AddExistingToSpace_noResults {
36+
display: block;
37+
margin-top: 24px;
38+
}
39+
40+
.mx_AddExistingToSpace_section {
41+
&:not(:first-child) {
42+
margin-top: 24px;
43+
}
44+
45+
> h3 {
46+
margin: 0;
47+
color: $secondary-fg-color;
48+
font-size: $font-12px;
49+
font-weight: $font-semi-bold;
50+
line-height: $font-15px;
51+
}
52+
53+
.mx_AddExistingToSpace_entry {
54+
display: flex;
55+
margin-top: 12px;
56+
57+
.mx_BaseAvatar {
58+
margin-right: 12px;
59+
}
60+
61+
.mx_AddExistingToSpace_entry_name {
62+
font-size: $font-15px;
63+
line-height: 30px;
64+
flex-grow: 1;
65+
overflow: hidden;
66+
white-space: nowrap;
67+
text-overflow: ellipsis;
68+
margin-right: 12px;
69+
}
70+
71+
.mx_Checkbox {
72+
align-items: center;
73+
}
74+
}
75+
}
76+
77+
.mx_AddExistingToSpace_section_spaces {
78+
.mx_BaseAvatar_image {
79+
border-radius: 8px;
80+
}
81+
}
82+
}
83+
2484
.mx_AddExistingToSpaceDialog {
2585
width: 480px;
2686
color: $primary-fg-color;
@@ -100,12 +160,6 @@ limitations under the License.
100160
}
101161
}
102162

103-
.mx_SearchBox {
104-
// To match the space around the title
105-
margin: 0 0 15px 0;
106-
flex-grow: 0;
107-
}
108-
109163
.mx_AddExistingToSpaceDialog_errorText {
110164
font-weight: $font-semi-bold;
111165
font-size: $font-12px;
@@ -114,56 +168,8 @@ limitations under the License.
114168
margin-bottom: 28px;
115169
}
116170

117-
.mx_AddExistingToSpaceDialog_content {
118-
flex-grow: 1;
119-
120-
.mx_AddExistingToSpaceDialog_noResults {
121-
display: block;
122-
margin-top: 24px;
123-
}
124-
}
125-
126-
.mx_AddExistingToSpaceDialog_section {
127-
&:not(:first-child) {
128-
margin-top: 24px;
129-
}
130-
131-
> h3 {
132-
margin: 0;
133-
color: $secondary-fg-color;
134-
font-size: $font-12px;
135-
font-weight: $font-semi-bold;
136-
line-height: $font-15px;
137-
}
138-
139-
.mx_AddExistingToSpaceDialog_entry {
140-
display: flex;
141-
margin-top: 12px;
142-
143-
.mx_BaseAvatar {
144-
margin-right: 12px;
145-
}
146-
147-
.mx_AddExistingToSpaceDialog_entry_name {
148-
font-size: $font-15px;
149-
line-height: 30px;
150-
flex-grow: 1;
151-
overflow: hidden;
152-
white-space: nowrap;
153-
text-overflow: ellipsis;
154-
margin-right: 12px;
155-
}
156-
157-
.mx_Checkbox {
158-
align-items: center;
159-
}
160-
}
161-
}
162-
163-
.mx_AddExistingToSpaceDialog_section_spaces {
164-
.mx_BaseAvatar_image {
165-
border-radius: 8px;
166-
}
171+
.mx_AddExistingToSpace {
172+
display: contents;
167173
}
168174

169175
.mx_AddExistingToSpaceDialog_footer {

src/components/structures/SpaceRoomView.tsx

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ import MemberAvatar from "../views/avatars/MemberAvatar";
5151
import {useStateToggle} from "../../hooks/useStateToggle";
5252
import SpaceStore from "../../stores/SpaceStore";
5353
import FacePile from "../views/elements/FacePile";
54+
import {AddExistingToSpace} from "../views/dialogs/AddExistingToSpaceDialog";
55+
import {allSettled} from "../../utils/promise";
56+
import {calculateRoomVia} from "../../utils/permalinks/Permalinks";
5457

5558
interface IProps {
5659
space: Room;
@@ -354,7 +357,7 @@ const SpaceSetupFirstRooms = ({ space, title, description, onFinished }) => {
354357
let buttonLabel = _t("Skip for now");
355358
if (roomNames.some(name => name.trim())) {
356359
onClick = onNextClick;
357-
buttonLabel = busy ? _t("Creating rooms...") : _t("Continue")
360+
buttonLabel = busy ? _t("Creating rooms...") : _t("Continue");
358361
}
359362

360363
return <div>
@@ -376,6 +379,65 @@ const SpaceSetupFirstRooms = ({ space, title, description, onFinished }) => {
376379
</div>;
377380
};
378381

382+
const SpaceAddExistingRooms = ({ space, onFinished }) => {
383+
const [selectedToAdd, setSelectedToAdd] = useState(new Set<Room>());
384+
385+
const [busy, setBusy] = useState(false);
386+
const [error, setError] = useState("");
387+
388+
let onClick = onFinished;
389+
let buttonLabel = _t("Skip for now");
390+
if (selectedToAdd.size > 0) {
391+
onClick = async () => {
392+
// TODO rate limiting
393+
setBusy(true);
394+
try {
395+
await allSettled(Array.from(selectedToAdd).map((room) =>
396+
SpaceStore.instance.addRoomToSpace(space, room.roomId, calculateRoomVia(room))));
397+
onFinished(true);
398+
} catch (e) {
399+
console.error("Failed to add rooms to space", e);
400+
setError(_t("Failed to add rooms to space"));
401+
}
402+
setBusy(false);
403+
};
404+
buttonLabel = busy ? _t("Adding...") : _t("Add");
405+
}
406+
407+
return <div>
408+
<h1>{ _t("What do you want to organise?") }</h1>
409+
<div className="mx_SpaceRoomView_description">
410+
{ _t("Pick rooms or conversations to add. This is just a space for you, " +
411+
"no one will be informed. You can add more later.") }
412+
</div>
413+
414+
{ error && <div className="mx_SpaceRoomView_errorText">{ error }</div> }
415+
416+
<AddExistingToSpace
417+
space={space}
418+
selected={selectedToAdd}
419+
onChange={(checked, room) => {
420+
if (checked) {
421+
selectedToAdd.add(room);
422+
} else {
423+
selectedToAdd.delete(room);
424+
}
425+
setSelectedToAdd(new Set(selectedToAdd));
426+
}}
427+
/>
428+
429+
<div className="mx_SpaceRoomView_buttons">
430+
<AccessibleButton
431+
kind="primary"
432+
disabled={busy}
433+
onClick={onClick}
434+
>
435+
{ buttonLabel }
436+
</AccessibleButton>
437+
</div>
438+
</div>;
439+
};
440+
379441
const SpaceSetupPublicShare = ({ space, onFinished }) => {
380442
return <div className="mx_SpaceRoomView_publicShare">
381443
<h1>{ _t("Share %(name)s", { name: space.name }) }</h1>
@@ -659,7 +721,7 @@ export default class SpaceRoomView extends React.PureComponent<IProps, IState> {
659721
return <SpaceSetupPrivateScope
660722
space={this.props.space}
661723
onFinished={(invite: boolean) => {
662-
this.setState({ phase: invite ? Phase.PrivateInvite : Phase.PrivateCreateRooms });
724+
this.setState({ phase: invite ? Phase.PrivateInvite : Phase.PrivateExistingRooms });
663725
}}
664726
/>;
665727
case Phase.PrivateInvite:
@@ -675,6 +737,11 @@ export default class SpaceRoomView extends React.PureComponent<IProps, IState> {
675737
"You can add more later too, including already existing ones.")}
676738
onFinished={() => this.setState({ phase: Phase.Landing })}
677739
/>;
740+
case Phase.PrivateExistingRooms:
741+
return <SpaceAddExistingRooms
742+
space={this.props.space}
743+
onFinished={() => this.setState({ phase: Phase.Landing })}
744+
/>;
678745
}
679746
}
680747

0 commit comments

Comments
 (0)