Skip to content
This repository was archived by the owner on Oct 30, 2025. It is now read-only.

Commit 9799b68

Browse files
authored
Merge pull request #93 from RonLek/remove_communities
[IMPROVEMENT] Remove communities for channel creation
2 parents 4b2d4c4 + 777ef24 commit 9799b68

11 files changed

Lines changed: 136 additions & 481 deletions

File tree

client/src/components/ChannelInfo/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export default function ChannelInfo(props) {
6969
url: `${githubApiDomain}/repos/${repository}/issues`,
7070
headers: headers,
7171
});
72-
// GitHub treats both PRs and issues as issues except that PRs can be
72+
// GitHub treats both PRs and issues as issues except that PRs can be
7373
// distinguished by the presence of a pull_request key
7474
setIssuesCount(
7575
ghIssuesResponse.data.filter((issue) => !issue.pull_request).length
@@ -84,9 +84,12 @@ export default function ChannelInfo(props) {
8484
}, [props.location.pathname]);
8585

8686
const [activeTab, setActiveTab] = useState(0);
87-
const repoURL = `https://github.com/${props.location.pathname
88-
.split("/")[2]
89-
.replace("_", "/")}`;
87+
// Covers case where pathname is /channel
88+
const repoURL = `https://github.com/${
89+
props.location.pathname.split("/")[2]
90+
? props.location.pathname.split("/")[2].replace("_", "/")
91+
: ""
92+
}`;
9093

9194
const handleChange = (event, newValue) => {
9295
setActiveTab(newValue);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.create-channel-wrapper {
2+
justify-content: center;
3+
display: flex;
4+
}
5+
6+
.create-dialog-description {
7+
margin-top: 0px;
8+
color: #8e9299;
9+
}
10+
11+
.create-button {
12+
margin-bottom: 10px !important;
13+
}
14+
15+
.form-switch {
16+
display: flex;
17+
flex-direction: row;
18+
justify-content: space-between;
19+
}
20+
21+
.form-control-label {
22+
margin-right: 0px !important;
23+
}
24+
25+
.repository-select-label {
26+
margin-top: 0px;
27+
}

client/src/components/CreateChannel/index.js

Lines changed: 70 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ import {
1313
} from "@material-ui/core";
1414
import RCSwitch from "../RCSwitch";
1515
import Cookies from "js-cookie";
16-
import jwt_decode from "jwt-decode";
1716
import {
1817
githubPrivateRepoAccessClientID,
1918
rcApiDomain,
2019
rc4gitDomain,
2120
} from "../../utils/constants";
2221
import EmbedBadgeDialog from "../EmbedBadgeDialog";
2322

23+
import "./index.css";
24+
2425
const Transition = React.forwardRef(function Transition(props, ref) {
2526
return <Slide direction="up" ref={ref} {...props} />;
2627
});
@@ -32,12 +33,9 @@ export default class CreateChannel extends Component {
3233
repositories: [],
3334
publicRepositories: [],
3435
privateRepositories: [],
35-
username: jwt_decode(Cookies.get("rc4git_token")).username.slice(0, -7),
36-
community: null,
3736
includePrivateRepositories: false,
3837
publicChannel: true,
3938
loading: false,
40-
communities: [],
4139
channel: null,
4240
showEmbedBadgeDialog: false,
4341
room: null,
@@ -50,31 +48,7 @@ export default class CreateChannel extends Component {
5048
}
5149

5250
handleClickChannelDialog = async () => {
53-
const { publicRepositories, privateRepositories, username } = this.state;
54-
const { organizations, rooms } = this.props;
55-
let communityChannels = [],
56-
communityMember = [];
57-
58-
communityChannels = rooms
59-
.filter((room) => {
60-
return room.name.endsWith("_community");
61-
})
62-
.map((communityRoom) =>
63-
communityRoom.name.slice(0, communityRoom.name.length - 10)
64-
);
65-
66-
//Add organizations and username to communityMember
67-
communityMember.push(username);
68-
communityMember = communityMember.concat(
69-
organizations.map((organization) => organization.value)
70-
);
71-
72-
//Intersect communityMembers and communityChannels and set as communities
73-
this.setState({
74-
communities: communityMember.filter((value) =>
75-
communityChannels.includes(value)
76-
),
77-
});
51+
const { publicRepositories, privateRepositories } = this.state;
7852

7953
//Fetch public repositories
8054
const publicRepoResponse = await axios({
@@ -116,8 +90,8 @@ export default class CreateChannel extends Component {
11690
this.setState({ ...this.state, [event.target.name]: event.target.checked });
11791
if (event.target.checked) {
11892
if (!Cookies.get("gh_private_repo_token")) {
119-
Cookies.set("gh_upgrade_prev_path", window.location.pathname)
120-
window.location.href = `https://github.com/login/oauth/authorize?scope=repo&client_id=${githubPrivateRepoAccessClientID}`
93+
Cookies.set("gh_upgrade_prev_path", window.location.pathname);
94+
window.location.href = `https://github.com/login/oauth/authorize?scope=repo&client_id=${githubPrivateRepoAccessClientID}`;
12195
}
12296
this.setState({
12397
repositories: publicRepositories.concat(privateRepositories),
@@ -128,11 +102,10 @@ export default class CreateChannel extends Component {
128102
};
129103

130104
handleCreateChannel = async () => {
131-
const { channel, community, publicChannel } = this.state;
105+
const { channel, publicChannel } = this.state;
132106
const { setSnackbar, addRoom } = this.props;
133-
const authToken = Cookies.get("gh_private_repo_token")
134-
? Cookies.get("gh_private_repo_token")
135-
: Cookies.get("gh_login_token");
107+
const authToken =
108+
Cookies.get("gh_private_repo_token") || Cookies.get("gh_login_token");
136109
let collaborators = [],
137110
description = "";
138111
this.setState({ loading: true });
@@ -142,7 +115,7 @@ export default class CreateChannel extends Component {
142115
if (Cookies.get("gh_private_repo_token")) {
143116
const ghCollaboratorsResponse = await axios({
144117
method: "get",
145-
url: `https://api.github.com/repos/${community}/${channel}/collaborators`,
118+
url: `https://api.github.com/repos/${channel}/collaborators`,
146119
headers: {
147120
accept: "application/json",
148121
Authorization: `token ${authToken}`,
@@ -158,7 +131,7 @@ export default class CreateChannel extends Component {
158131

159132
const ghRepoResponse = await axios({
160133
method: "get",
161-
url: `https://api.github.com/repos/${community}/${channel}`,
134+
url: `https://api.github.com/repos/${channel}`,
162135
headers: {
163136
accept: "application/json",
164137
Authorization: `token ${authToken}`,
@@ -175,19 +148,19 @@ export default class CreateChannel extends Component {
175148
data: {
176149
rc_token: Cookies.get("rc_token"),
177150
rc_uid: Cookies.get("rc_uid"),
178-
channel: `${community}_${channel}`,
151+
channel: channel.replace("/", "_"),
179152
members: collaborators,
180-
topic: `GitHub: https://github.com/${community}/${channel}`,
153+
topic: `GitHub: https://github.com/${channel}`,
181154
type: publicChannel ? "c" : "p",
182155
},
183156
});
184157
if (rcCreateChannelResponse.data.data.success) {
185158
let room = rcCreateChannelResponse.data.data.channel;
186-
//Add embeddable code for channel to description
159+
//Add embeddable code for room to description
187160
description = description.concat(`
188161
189162
-----
190-
Embed this channel
163+
Embed this room
191164
<pre><code>&lt;a&nbsp;href=&quot;${rc4gitDomain}/channel/${room.name}&quot;&gt;
192165
&lt;img&nbsp;src=&quot;${rcApiDomain}/images/join-chat.svg&quot;/&gt;
193166
&lt;/a&gt;</code></pre>
@@ -207,7 +180,7 @@ Embed this channel
207180
});
208181

209182
addRoom(room);
210-
setSnackbar(true, "success", "Channel created successfully!");
183+
setSnackbar(true, "success", "Room created successfully!");
211184
this.setState({
212185
loading: false,
213186
room: room,
@@ -216,12 +189,12 @@ Embed this channel
216189
});
217190
} else {
218191
this.setState({ loading: false });
219-
setSnackbar(true, "error", "Error Creating Channel!");
192+
setSnackbar(true, "error", "Error Creating Room!");
220193
}
221194
} catch (error) {
222195
console.log(error);
223196
this.setState({ loading: false });
224-
setSnackbar(true, "error", "Error Creating Channel!");
197+
setSnackbar(true, "error", "Error Creating Room!");
225198
}
226199
};
227200

@@ -230,8 +203,6 @@ Embed this channel
230203
repositories,
231204
publicChannel,
232205
includePrivateRepositories,
233-
community,
234-
communities,
235206
channel,
236207
loading,
237208
room,
@@ -241,8 +212,7 @@ Embed this channel
241212
const { setSnackbar, handleEndCreateChannel } = this.props;
242213

243214
return (
244-
<div style={{ justifyContent: "center", display: "flex" }}>
245-
215+
<div className="create-channel-wrapper">
246216
<Dialog
247217
open={openCreateChannelDialog}
248218
keepMounted
@@ -253,104 +223,90 @@ Embed this channel
253223
maxWidth="sm"
254224
fullWidth={true}
255225
>
256-
<DialogTitle>Create a New Channel</DialogTitle>
226+
<DialogTitle >Create Room</DialogTitle>
257227
<DialogContent>
258-
<p style={{ color: "#c0c2c6" }}>
259-
Channels are where your teams communicate.
228+
<p className="create-dialog-description">
229+
Rooms are where your teams communicate.
260230
</p>
261231
<div>
262232
<br />
263-
<p>Select a community</p>
233+
<p className="repository-select-label">Select Repository</p>
264234
<Autocomplete
265235
id="combo-box-repo"
266-
options={communities}
267-
style={{ width: 300 }}
236+
fullWidth
237+
options={repositories.sort()}
238+
renderOption={(option) => option.split("/")[1]}
239+
getOptionLabel={(option) => option}
240+
groupBy={(option) => option.split("/")[0]}
268241
onChange={(event, value) => {
269-
this.setState({ community: value });
242+
this.setState({ channel: value });
270243
}}
271244
renderInput={(params) => (
272-
<TextField {...params} label="Community" variant="outlined" />
245+
<TextField
246+
{...params}
247+
label="Repositories"
248+
variant="outlined"
249+
/>
273250
)}
274251
/>
275252
<br />
253+
{channel && (
254+
<>
255+
<p className="create-dialog-description">
256+
Your room would be created as{" "}
257+
<strong>{channel.replace("/", "_")}</strong>
258+
</p>
259+
</>
260+
)}
276261
<br />
262+
<div className="form-switch">
263+
<p>Show All Repositories</p>
277264
<FormControlLabel
265+
className="form-control-label"
278266
control={
279267
<RCSwitch
280-
checked={publicChannel}
281-
onChange={() =>
282-
this.setState({ publicChannel: !publicChannel })
283-
}
284-
name="publicChannel"
268+
checked={this.state.includePrivateRepositories}
269+
onChange={this.handleAllRepositories}
270+
name="includePrivateRepositories"
285271
/>
286272
}
287-
label="Public Channel"
288273
/>
289-
<p style={{ color: "#c0c2c6" }}>
290-
{publicChannel
291-
? "Everyone can access this channel."
292-
: "Just invited people can access this channel."}
274+
</div>
275+
276+
<p className="create-dialog-description">
277+
{includePrivateRepositories ? "Both public and private " : "Only public "}
278+
repositories are visible.
293279
</p>
294280
<br />
281+
<div className="form-switch">
282+
283+
<p>
284+
Public Room
285+
</p>
295286
<FormControlLabel
287+
className="form-control-label"
296288
control={
297289
<RCSwitch
298-
checked={this.state.includePrivateRepositories}
299-
onChange={this.handleAllRepositories}
300-
name="includePrivateRepositories"
290+
checked={publicChannel}
291+
onChange={() =>
292+
this.setState({ publicChannel: !publicChannel })
293+
}
294+
name="publicChannel"
295+
301296
/>
302297
}
303-
label="Show All Repositories"
304298
/>
305-
<p style={{ color: "#c0c2c6" }}>
306-
Show public {includePrivateRepositories ? "and private " : ""}
307-
repositories.
299+
</div>
300+
<p className="create-dialog-description">
301+
{publicChannel
302+
? "Everyone can access this room."
303+
: "Just invited people can access this room."}
308304
</p>
309305
<br />
310-
<p>Select a repository</p>
311-
<Autocomplete
312-
id="combo-box-repo"
313-
options={
314-
community
315-
? repositories
316-
.filter((repository) =>
317-
repository.startsWith(community.concat("/"))
318-
)
319-
.map((repository) =>
320-
repository.slice(
321-
community.length + 1,
322-
repository.length
323-
)
324-
)
325-
.sort()
326-
: []
327-
}
328-
style={{ width: 300 }}
329-
onChange={(event, value) => {
330-
this.setState({ channel: value });
331-
}}
332-
renderInput={(params) => (
333-
<TextField
334-
{...params}
335-
label="Repositories"
336-
variant="outlined"
337-
/>
338-
)}
339-
/>
340-
<br />
341-
{channel && (
342-
<>
343-
<p style={{ color: "#8e9299" }}>
344-
Your channel would be created as{" "}
345-
<strong>{community.concat(`_${channel}`)}</strong>
346-
</p>
347-
</>
348-
)}
349-
<br />
350306
<Button
307+
className="create-button"
351308
disabled={!channel || loading}
352309
onClick={this.handleCreateChannel}
353-
style={{ marginBottom: "10px" }}
354310
variant="contained"
355311
color="primary"
356312
startIcon={
@@ -365,7 +321,6 @@ Embed this channel
365321
{showEmbedBadgeDialog && (
366322
<EmbedBadgeDialog
367323
channelURL={`${rc4gitDomain}/channel/${room.name}`}
368-
createType="channel"
369324
setSnackbar={setSnackbar}
370325
endCreate={handleEndCreateChannel}
371326
/>

client/src/components/CreateCommunity/index.css

Whitespace-only changes.

0 commit comments

Comments
 (0)