diff --git a/packages/server/packages/play-node-go/play-node-go/src/App.js b/packages/server/packages/play-node-go/play-node-go/src/App.js index d960d6c..0ead4f4 100644 --- a/packages/server/packages/play-node-go/play-node-go/src/App.js +++ b/packages/server/packages/play-node-go/play-node-go/src/App.js @@ -6,12 +6,17 @@ import { Switch, Route, BrowserRouter as Router } from 'react-router-dom'; import socketIOClient from 'socket.io-client'; +import Sidebar from './components/Sidebar/Sidebar'; + 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'; +import { stateReducer } from './reducers/stateReducer'; +import { initState } from './reducers/init/stateReducer.init'; + export const socket = socketIOClient(config.apiAddress); @@ -20,6 +25,12 @@ function App() { const [socketData, setSocketData] = useState(); const [error, setError] = useState([]); + const [ state, dispatch ] = useReducer( + stateReducer, + {}, + initState + ); + useEffect(() => { fetch(config.apiAddress) .then(res => res.text()) @@ -41,27 +52,33 @@ function App() { {fetchData ?

{fetchData}

: <>} {socketData ?

{socketData}

: <>} {error ? error.map(err =>

{err}

): <>} + - + + - + + - + + - + + + {/* Add ternary for login */} - + diff --git a/packages/server/packages/play-node-go/play-node-go/src/components/Sidebar/Sidebar.js b/packages/server/packages/play-node-go/play-node-go/src/components/Sidebar/Sidebar.js new file mode 100644 index 0000000..30b3df1 --- /dev/null +++ b/packages/server/packages/play-node-go/play-node-go/src/components/Sidebar/Sidebar.js @@ -0,0 +1,36 @@ +import React, { useState } from 'react'; +import './Sidebar.scss'; + +import AccountSidebar from '../../pages/Account/AccountSidebar'; +import GameSidebar from '../../pages/Game/GameSidebar'; +import HomeSidebar from '../../pages/Home/HomeSidebar'; +import NewsSidebar from '../../pages/News/NewsSidebar'; +import RoomSidebar from '../../pages/Room/RoomSidebar'; + +const Sidebar = (props) => { + + const displayComponent = props =>{ + switch (props.page) { + case 'account': + return + case 'game': + return + case 'home': + return + case 'news': + return + case 'room': + return + default: + return <> + } + } + + return ( + + ); +} + +export default Sidebar; \ No newline at end of file diff --git a/packages/server/packages/play-node-go/play-node-go/src/components/Sidebar/Sidebar.scss b/packages/server/packages/play-node-go/play-node-go/src/components/Sidebar/Sidebar.scss new file mode 100644 index 0000000..e69de29 diff --git a/packages/server/packages/play-node-go/play-node-go/src/components/Sidebar/Sidebar.test.js b/packages/server/packages/play-node-go/play-node-go/src/components/Sidebar/Sidebar.test.js new file mode 100644 index 0000000..c153236 --- /dev/null +++ b/packages/server/packages/play-node-go/play-node-go/src/components/Sidebar/Sidebar.test.js @@ -0,0 +1,9 @@ +import React from 'react'; +import { render } from '@testing-library/react'; +import Sidebar from './Sidebar'; + +test('renders Sidebar without crashing', () => { + const { getByTestId } = render(); + const SidebarDiv = getByTestId('Sidebar'); + expect(SidebarDiv).toBeInTheDocument(); +}); diff --git a/packages/server/packages/play-node-go/play-node-go/src/components/Signup/Signup.js b/packages/server/packages/play-node-go/play-node-go/src/components/Signup/Signup.js index f5e5d04..b1bccb8 100644 --- a/packages/server/packages/play-node-go/play-node-go/src/components/Signup/Signup.js +++ b/packages/server/packages/play-node-go/play-node-go/src/components/Signup/Signup.js @@ -2,15 +2,44 @@ import React, { useState } from 'react'; import './Signup.scss'; const Signup = () => { - const [username, setUsername] = useState(''); - const [password, setPassword] = useState(''); - const [passwordConfirm, setPasswordConfirm] = useState(''); + const [ username, setUsername ] = useState(''); + const [ password, setPassword ] = useState(''); + const [ confirmPassword, setConfirmPassword ] = useState(''); return (
- +
+ + + setUsername(e.target.value)} + default="username" + /> + + + setPassword(e.target.value)} + default="" + /> + + + setConfirmPassword(e.target.value)} + default="" + /> + +
); } - + export default Signup; \ No newline at end of file diff --git a/packages/server/packages/play-node-go/play-node-go/src/pages/Account/AccountSidebar.js b/packages/server/packages/play-node-go/play-node-go/src/pages/Account/AccountSidebar.js new file mode 100644 index 0000000..61f0db1 --- /dev/null +++ b/packages/server/packages/play-node-go/play-node-go/src/pages/Account/AccountSidebar.js @@ -0,0 +1,10 @@ +import React from 'react'; + +const AccountSidebar = () => { + return ( + <> + + ); +} + +export default AccountSidebar; \ No newline at end of file diff --git a/packages/server/packages/play-node-go/play-node-go/src/pages/Game/GameSidebar.js b/packages/server/packages/play-node-go/play-node-go/src/pages/Game/GameSidebar.js new file mode 100644 index 0000000..a0d38fa --- /dev/null +++ b/packages/server/packages/play-node-go/play-node-go/src/pages/Game/GameSidebar.js @@ -0,0 +1,10 @@ +import React from 'react'; + +const GameSidebar = () => { + return ( + <> + + ); +} + +export default GameSidebar; \ No newline at end of file diff --git a/packages/server/packages/play-node-go/play-node-go/src/pages/Home/HomeSidebar.js b/packages/server/packages/play-node-go/play-node-go/src/pages/Home/HomeSidebar.js new file mode 100644 index 0000000..cad7d11 --- /dev/null +++ b/packages/server/packages/play-node-go/play-node-go/src/pages/Home/HomeSidebar.js @@ -0,0 +1,21 @@ +import React, { useState } from 'react'; + +import Signup from '../../components/Signup/Signup'; +import Login from '../../components/Login/Login'; + +const HomeSidebar = (props) => { + const [ showForm, setShowForm ] = useState(''); + + return ( + + ); +} + +export default HomeSidebar; \ No newline at end of file diff --git a/packages/server/packages/play-node-go/play-node-go/src/pages/News/NewsSidebar.js b/packages/server/packages/play-node-go/play-node-go/src/pages/News/NewsSidebar.js new file mode 100644 index 0000000..c438677 --- /dev/null +++ b/packages/server/packages/play-node-go/play-node-go/src/pages/News/NewsSidebar.js @@ -0,0 +1,10 @@ +import React from 'react'; + +const NewsSidebar = () => { + return ( + <> + + ); +} + +export default NewsSidebar; \ No newline at end of file diff --git a/packages/server/packages/play-node-go/play-node-go/src/pages/Room/RoomSidebar.js b/packages/server/packages/play-node-go/play-node-go/src/pages/Room/RoomSidebar.js new file mode 100644 index 0000000..f35348b --- /dev/null +++ b/packages/server/packages/play-node-go/play-node-go/src/pages/Room/RoomSidebar.js @@ -0,0 +1,10 @@ +import React from 'react'; + +const RoomSidebar = () => { + return ( + <> + + ); +} + +export default RoomSidebar; \ No newline at end of file diff --git a/packages/server/packages/play-node-go/play-node-go/src/reducers/init/stateReducer.init.js b/packages/server/packages/play-node-go/play-node-go/src/reducers/init/stateReducer.init.js new file mode 100644 index 0000000..cdaa3e9 --- /dev/null +++ b/packages/server/packages/play-node-go/play-node-go/src/reducers/init/stateReducer.init.js @@ -0,0 +1,9 @@ +//@ flow + +import type { state } from '../stateReducer'; + +export const initState = (): state => { + return { + user: null + }; +} \ No newline at end of file diff --git a/packages/server/packages/play-node-go/play-node-go/src/reducers/stateReducer.js b/packages/server/packages/play-node-go/play-node-go/src/reducers/stateReducer.js new file mode 100644 index 0000000..b405a93 --- /dev/null +++ b/packages/server/packages/play-node-go/play-node-go/src/reducers/stateReducer.js @@ -0,0 +1,18 @@ +// @flow +import { initState } from './init/stateReducer.init'; + +export type state = { + user: {} +} + +type action = { + type: string +} + +export const stateReducer = (state: state, action: action): state => { + switch (action.type) { + case 'INIT': return initState(); + + default: return state; + } +} \ No newline at end of file diff --git a/packages/server/packages/play-node-go/play-node-go/src/reducers/stateReducer.test.js b/packages/server/packages/play-node-go/play-node-go/src/reducers/stateReducer.test.js new file mode 100644 index 0000000..a4920d8 --- /dev/null +++ b/packages/server/packages/play-node-go/play-node-go/src/reducers/stateReducer.test.js @@ -0,0 +1,8 @@ +import {stateReducer} from './stateReducer'; + +it('default returns state unaltered', () => { + const state = {data: 'example'}; + const action = {type: ''}; + expect(stateReducer(state, action)).toBe(state); +}); +