import React, {useState, useEffect} from 'react';
import {
Paper,
IconButton,
Menu,
MenuItem,
Typography,
Grid,
Box,
Link,
Dialog,
DialogTitle,
DialogContent,
DialogContentText,
TextField,
DialogActions,
Button,
FormControl,
InputLabel,
Select,
} from "@material-ui/core";
import { MoreVert as MoreIcon } from "@material-ui/icons";
import {useHistory} from "react-router-dom";
import classnames from "classnames";
// styles
import useStyles from "./styles";
import Widget from "../../components/Widget";
import SqueakThreadItem from "../../components/SqueakThreadItem";
import {
createPeerRequest,
} from "../../squeakclient/requests"
export default function CreatePeerDialog({
open,
handleClose,
...props
}) {
var classes = useStyles();
const history = useHistory();
var [peerName, setpeerName] = useState('');
var [host, setHost] = useState('');
var [port, setPort] = useState('');
const resetFields = () => {
setpeerName('');
setHost('');
setPort('');
};
const handleChangePeerName = (event) => {
setpeerName(event.target.value);
};
const handleChangeHost = (event) => {
setHost(event.target.value);
};
const handleChangePort = (event) => {
setPort(event.target.value);
};
const createPeer = (peerName, host, port) => {
createPeerRequest(peerName, host, port, (response) => {
goToPeerPage(response.getPeerId());
});
};
const goToPeerPage = (peerId) => {
history.push("/app/peer/" + peerId);
};
function handleSubmit(event) {
event.preventDefault();
console.log( 'peerName:', peerName);
console.log( 'host:', host);
console.log( 'port:', port);
if (!host) {
alert('Host cannot be empty.');
return;
}
if (!port) {
alert('Port cannot be empty.');
return;
}
createPeer(peerName, host, port);
handleClose();
}
function CreatePeerNameInput() {
return (
)
}
function CreateHostInput() {
return (
)
}
function CreatePortInput() {
return (
)
}
function CancelButton() {
return (
)
}
function CreatePeerButton() {
return (
)
}
return (
)
}