Skip to content

Commit

Permalink
Further improvements to structure
Browse files Browse the repository at this point in the history
  • Loading branch information
anweisen committed Nov 20, 2021
1 parent 519ac9d commit a2a685b
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 11 deletions.
22 changes: 17 additions & 5 deletions src/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import axios, {Method} from "axios";
import axios from "axios";

const API_VERSION = 1;

type Auth = {
method: string;
token: string;
}
type HttpMethod =
| 'get'
| 'delete'
| 'head'
| 'options'
| 'post'
| 'put'
| 'patch'
| 'purge'
| 'link'
| 'unlink';
type Route = {
path: string;
method: Method;
method: HttpMethod;
}
export module Routes {
export const UPGRADE_WEBSOCKET: Route = { path: "/upgrade", method: "get" };
Expand All @@ -35,7 +46,7 @@ export class CloudAPI {
return this.auth.method + " " + this.auth.token;
}

initSocket(socket: WebSocket) {
initSocket(socket: WebSocket): void {
this.socket = socket;

this.socket.onmessage = (event) => {
Expand All @@ -58,12 +69,13 @@ export class CloudAPI {
}

public async makeRequest(route: Route): Promise<any> {
const target = this.useUrl(route);
const endpoint = this.useUrl(route);

return axios(target, {
return axios(endpoint, {
headers: {
Authorization: this.getAuth()
},
timeout: 3500,
method: route.method
}).then(value => value.data);
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export default function Login({ setCookies }) {
<div className={"form-container"}>
<div className={"form"}>
<h1>Login</h1>
{/*<h1>•┃ Login ┃•</h1>*/}
{/*<h1>•» Login «•</h1>*/}
<LoginSelect method={method} setMethod={setMethod} hooks={hooks} />
<div className={"button"} onClick={event => {
event.preventDefault();
Expand Down
4 changes: 2 additions & 2 deletions src/components/Login.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@

.form {
display: table;
padding: 50px;
width: 70%;
padding: 50px 0;
width: 60%;
text-align: center;

h1 {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Nav.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MdHome, MdPeople, MdStorage, MdOutlineLogout } from "react-icons/md";
import { MdHome, MdPeople, MdStorage, MdOutlineLogout } from "react-icons/all";

import NavEntry from "./dashboard/NavEntry";

Expand Down
5 changes: 3 additions & 2 deletions src/components/dashboard/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CloudAPI, Routes as ApiRoutes } from "../../api/api";

import Nav from "../Nav";
import Overview from "./content/Overview";
import Players from "./content/Players";
import Loader from "../Loader";

import "./Dashboard.scss";
Expand Down Expand Up @@ -36,8 +37,8 @@ export default function Dashboard({ cookies }) {

<div className={"content"}>
<Routes>
<Route path={"/"} element={<Overview api={connection} />} />
<Route path={"player"} />
<Route path={"/"} element={<Overview api={connection} />} />
<Route path={"player"} element={<Players api={connection} />} />
</Routes>
</div>
</>
Expand Down
2 changes: 1 addition & 1 deletion src/components/dashboard/content/Overview.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from "react";
import { MdPeopleOutline } from "react-icons/md";
import { MdPeopleOutline } from "react-icons/all";

import Loader from "../../Loader";

Expand Down
23 changes: 23 additions & 0 deletions src/components/dashboard/content/Players.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ImHammer2 } from "react-icons/all";
import { useEffect, useState } from "react";

import Loader from "../../Loader";

export default function Players({ api }) {
const [ players, setPlayers ] = useState();

useEffect(() => {
if (players != null) return;
api.fetchPlayers().then(players => setPlayers(players));
});

return (
<div className={"Players Dashboard-Component"}>
{ players == null
? <Loader/>
: <>
</>
}
</div>
);
}

0 comments on commit a2a685b

Please sign in to comment.