-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: can create and join channels (#23)
- Loading branch information
name
committed
Dec 14, 2022
1 parent
249dcea
commit a2c4a6f
Showing
10 changed files
with
131 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,77 @@ | ||
import Button from '@mui/material/Button'; | ||
import TextField from '@mui/material/TextField'; | ||
import Dialog from '@mui/material/Dialog'; | ||
import DialogActions from '@mui/material/DialogActions'; | ||
import DialogContent from '@mui/material/DialogContent'; | ||
import DialogContentText from '@mui/material/DialogContentText'; | ||
import DialogTitle from '@mui/material/DialogTitle'; | ||
import CheckBox from '@mui/material/CheckBox'; | ||
import FormControlLabel from '@mui/material/FormControlLabel'; | ||
import { useState } from 'react'; | ||
import axios from 'axios'; | ||
|
||
export default function CreateChannelDialog({ open, onClose, onSubmit }) { | ||
const [name, setName] = useState<string>(''); | ||
const [description, setDescription] = useState<string>(''); | ||
const [password, setPassword] = useState<string>(''); | ||
const [isPrivate, setIsPrivate] = useState<boolean>(false); | ||
|
||
function submit() { | ||
axios | ||
.post( | ||
"/server/api/channel", | ||
{ | ||
channelName: name, | ||
description, | ||
password, | ||
isPublic: !isPrivate | ||
}, | ||
) | ||
.then((response) => onSubmit()) | ||
.catch((error) => { | ||
}); | ||
onClose(); | ||
} | ||
|
||
export default function CreateChannelDialog({ open, onClose }) { | ||
return ( | ||
<Dialog onClose={onClose} open={open}> | ||
<Dialog open={open} onClose={onClose} fullWidth> | ||
<DialogTitle>Create new channel</DialogTitle> | ||
<DialogContent> | ||
<TextField | ||
autoFocus | ||
margin="dense" | ||
label="Channel name" | ||
fullWidth | ||
required | ||
onChange={(event) => setName(event.target.value)} | ||
/> | ||
<TextField | ||
margin="dense" | ||
label="Channel description" | ||
fullWidth | ||
multiline | ||
rows={8} | ||
onChange={(event) => setDescription(event.target.value)} | ||
/> | ||
<TextField | ||
margin="dense" | ||
label="Channel password" | ||
fullWidth | ||
name="password" | ||
onChange={(event) => setPassword(event.target.value)} | ||
/> | ||
<FormControlLabel | ||
label="Set private" | ||
control={<CheckBox onChange={() => { | ||
console.log('CheckBox onChange'); | ||
setIsPrivate(!isPrivate); | ||
}} />} | ||
/> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={onClose}>Cancel</Button> | ||
<Button onClick={submit}>Create</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Button from '@mui/material/Button'; | ||
import TextField from '@mui/material/TextField'; | ||
import Dialog from '@mui/material/Dialog'; | ||
import DialogTitle from '@mui/material/DialogTitle'; | ||
import DialogContent from '@mui/material/DialogContent'; | ||
import DialogActions from '@mui/material/DialogActions'; | ||
import { useState } from 'react'; | ||
|
||
export default function PasswordDialog({ open, onClose, onSubmit }) { | ||
const [password, setPassword] = useState(''); | ||
|
||
return ( | ||
<Dialog open={open} onClose={onClose}> | ||
<DialogTitle> | ||
Enter password | ||
</DialogTitle> | ||
<DialogContent> | ||
<TextField | ||
autoFocus | ||
margin="dense" | ||
label="password" | ||
fullWidth | ||
variant="standard" | ||
onChange={(event) => setPassword(event.target.value)} | ||
/> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={onClose}>Cancel</Button> | ||
<Button onClick={() => onSubmit(password)}>Enter</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters