From bb511abc03bb66848947e37a999502b813c77269 Mon Sep 17 00:00:00 2001 From: 8cy <50817549+8cy@users.noreply.github.com> Date: Thu, 23 Jul 2020 23:24:17 -0700 Subject: goodbye old uwufier :cry: --- client/src/components/App.js | 61 +++++++++++++++++++ .../manageserver/ManageServerSettings.js | 71 ++++++++++++++++++++++ client/src/components/navigation/NavigationBar.js | 50 +++++++++++++++ client/src/components/selection/ServerCard.js | 37 +++++++++++ 4 files changed, 219 insertions(+) create mode 100644 client/src/components/App.js create mode 100644 client/src/components/manageserver/ManageServerSettings.js create mode 100644 client/src/components/navigation/NavigationBar.js create mode 100644 client/src/components/selection/ServerCard.js (limited to 'client/src/components') diff --git a/client/src/components/App.js b/client/src/components/App.js new file mode 100644 index 0000000..270e199 --- /dev/null +++ b/client/src/components/App.js @@ -0,0 +1,61 @@ +import React, { Component } from 'react'; +import { BrowserRouter as Router, Route } from 'react-router-dom'; +import fetch from 'node-fetch'; + +import NavigationBar from './navigation/NavigationBar'; +import ServerSelection from '../pages/ServerSelection'; +import ManageServer from '../pages/ManageServer'; + +export default class App extends Component { + state = { + loading: true, + user: null + } + + componentDidMount() { + fetch('http://localhost:8088/oauth/details', { + credentials: 'include' + }) + .then(res => res.json()) + .then(res => { + if (!res) return this.setState({ loading: false }); + this.setState({ + loading: false, + user: res + }) + }) + .catch(() => this.setState({ loading: false })); + } + + render() { + if (this.state.loading) { + return( + + + Loading... + + + ); + } else if (!this.state.user) { + window.location.replace('http://localhost:8088/oauth/login'); // OAuth2... + return (); + } else { + return( + + + + + + + + } /> + } /> + + + + + + ); + } + } +} \ No newline at end of file diff --git a/client/src/components/manageserver/ManageServerSettings.js b/client/src/components/manageserver/ManageServerSettings.js new file mode 100644 index 0000000..66a5fe5 --- /dev/null +++ b/client/src/components/manageserver/ManageServerSettings.js @@ -0,0 +1,71 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { MDBCard, MDBCardHeader, MDBCardBody, MDBInput, MDBAlert, MDBBtn } from 'mdbreact'; +import fetch from 'node-fetch'; + +export default class ManageServerSettings extends Component { + state = { + error: null, + success: false, + disabled: false + } + + handleSave() { + this.setState({ + error: null, + success: false, + disabled: true + }); + + fetch(`http://localhost:8088/v1/post/guild-name/${this.props.guild}`, { + method: 'POST', + credentials: 'include', + headers: { + 'Authorization': process.env.REACT_APP_AUTHORIZATION, + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + name: this.props.data.name + }) + }) + .then(res => res.json()) + .then(res => { + if (res.message) return this.setState({ error: res.message, disabled: false }); + + this.setState({ success: true }); + }) + .catch(err => { + console.log(err); + this.setState({ error: 'An unknown error occured' }); + }); + } + + render() { + return( + + + + Server Settings + + + {this.state.error && + {this.state.error} + } + {this.state.success && + Updated server settings successfully + } + + + Save + + + + ) + } +} + +ManageServerSettings.propTypes = { + data: PropTypes.object, + handleInput: PropTypes.func, + guild: PropTypes.string +} \ No newline at end of file diff --git a/client/src/components/navigation/NavigationBar.js b/client/src/components/navigation/NavigationBar.js new file mode 100644 index 0000000..3962aae --- /dev/null +++ b/client/src/components/navigation/NavigationBar.js @@ -0,0 +1,50 @@ +import React, { Component } from 'react'; +import { + MDBNavbar, MDBNavbarBrand, MDBNavbarNav, MDBNavItem, MDBNavLink, MDBNavbarToggler, MDBCollapse, MDBIcon, + MDBDropdown, MDBDropdownToggle, MDBDropdownMenu, MDBDropdownItem, MDBCol +} from 'mdbreact' +import PropTypes from 'prop-types'; + +export default class NavigationBar extends Component { + state = { + isOpen: false + }; + + toggleCollapse() { + this.setState({ isOpen: !this.state.isOpen }); + } + + render() { + return( + + + Bot Dashboard + + + + + + Server Selection + + + + + + + + + + {`Logout (${this.props.user.username})`} + + + + + + + ); + } +} + +NavigationBar.propTypes = { + user: PropTypes.object +} \ No newline at end of file diff --git a/client/src/components/selection/ServerCard.js b/client/src/components/selection/ServerCard.js new file mode 100644 index 0000000..93c7ad6 --- /dev/null +++ b/client/src/components/selection/ServerCard.js @@ -0,0 +1,37 @@ +import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; +import PropTypes from 'prop-types'; +import { MDBBtn, MDBCard, MDBCardBody, MDBCardTitle, MDBCol } from 'mdbreact'; + +export default class ServerCard extends Component { + render() { + return( + + + + + + + {this.props.guild.name} + + Manage + + + + + + ) + } +} + +ServerCard.propTypes = { + guild: PropTypes.object +} \ No newline at end of file -- cgit v1.2.3