2020-01-08 07:18:08 +00:00
|
|
|
import React, {useState} from 'react';
|
2020-01-07 20:19:11 +00:00
|
|
|
import './App.scss';
|
2020-01-07 21:03:59 +00:00
|
|
|
import config from './config';
|
2020-01-07 20:19:11 +00:00
|
|
|
|
2020-01-08 19:38:09 +00:00
|
|
|
import { Switch, Route } from 'react-router-dom';
|
|
|
|
|
2020-01-08 07:18:08 +00:00
|
|
|
import socketIOClient from 'socket.io-client';
|
2020-01-09 01:17:10 +00:00
|
|
|
|
|
|
|
import Account from './pages/Account/Account';
|
|
|
|
import Game from './pages/Game/Game';
|
|
|
|
import Home from './pages/Home/Home';
|
|
|
|
import News from './pages/News/News';
|
|
|
|
import Room from './pages/Room/Room';
|
|
|
|
|
2020-01-08 07:18:08 +00:00
|
|
|
export const socket = socketIOClient(config.apiAddress);
|
|
|
|
|
2020-01-07 20:19:11 +00:00
|
|
|
function App() {
|
2020-01-08 07:18:08 +00:00
|
|
|
const [fetchData, setFetchData] = useState();
|
|
|
|
const [socketData, setSocketData] = useState();
|
|
|
|
fetch(config.apiAddress).then(res => res.text()).then(data => setFetchData(data));
|
|
|
|
socket.emit('connect');
|
|
|
|
socket.on('connected', data => setSocketData(data.message));
|
2020-01-07 20:19:11 +00:00
|
|
|
return (
|
|
|
|
<div className="App">
|
|
|
|
<h1>React Boilerplate</h1>
|
2020-01-08 07:18:08 +00:00
|
|
|
{fetchData ? <p>{fetchData}</p> : <></>}
|
|
|
|
{socketData ? <p>{socketData}</p> : <></>}
|
2020-01-08 19:38:09 +00:00
|
|
|
<Switch>
|
|
|
|
|
2020-01-09 01:17:10 +00:00
|
|
|
<Route path="/account">
|
|
|
|
<Account />
|
|
|
|
</Route>
|
|
|
|
|
|
|
|
<Route path="/rooms">
|
|
|
|
<Room />
|
2020-01-08 19:38:09 +00:00
|
|
|
</Route>
|
|
|
|
|
2020-01-09 01:17:10 +00:00
|
|
|
<Route path="/games">
|
|
|
|
<Game />
|
|
|
|
</Route>
|
|
|
|
|
|
|
|
<Route path="/news">
|
|
|
|
<News />
|
|
|
|
</Route>
|
|
|
|
|
|
|
|
<Route path="/">
|
|
|
|
{/* Add ternary for login */}
|
|
|
|
<Home />
|
2020-01-08 19:38:09 +00:00
|
|
|
</Route>
|
|
|
|
|
|
|
|
</Switch>
|
2020-01-07 20:19:11 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|