Skip to content

Commit

Permalink
Merge pull request #216 from RobzLegz/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
RobzLegz authored Oct 29, 2021
2 parents 280aa1d + 193ef30 commit fe52e89
Show file tree
Hide file tree
Showing 11 changed files with 421 additions and 26 deletions.
40 changes: 40 additions & 0 deletions components/containers/menu/MenuContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useRouter } from 'next/dist/client/router';
import React from 'react'
import { useDispatch, useSelector } from 'react-redux';
import { setNotification } from '../../../redux/slices/notificationSlice';
import { selectUser } from '../../../redux/slices/userSlice';

function MenuContainer() {
const userInfo = useSelector(selectUser);

const dispatch = useDispatch();
const router = useRouter();

return (
<div className="menu__container">
<h1>MATHROOM</h1>

<div className="menu__container__options">
<button className="button button__play" onClick={() => {if(!userInfo.loggedIn || !userInfo.token){return dispatch(setNotification({type: "error", message: "You must be logged in to play games!"}))}router.push("/rooms")}}>Play</button>
<button className="button" onClick={() => router.push("/instructions")}>Instructions</button>
{!userInfo.loggedIn || !userInfo.token && (<button className="button" onClick={() => router.push("/auth/login")}>Authorize</button>)}
</div>

<div className="menu__container__decorations">
<img className="image image1" src="/svg/sandClock.svg" alt="sand clock ticking in blue color slightly rotated to right side" />
<img className="image image2" src="/svg/clock.svg" alt="clock with two arrows in red color slightly rotated to left side" />
<img className="image image3" src="/svg/timer.svg" alt="purple timer ticking" />
<div className="line line1"></div>
<div className="line line2"></div>
<div className="line line3"></div>
<div className="line line4"></div>
<div className="line line5"></div>
<div className="line line6"></div>
<div className="line line7"></div>
<div className="line line8"></div>
</div>
</div>
)
}

export default MenuContainer
2 changes: 1 addition & 1 deletion components/containers/rooms/RoomContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const RoomContainer: React.FC = () => {
return (
<div className="roomPage__container">
<header className="roomPage__container__header">
<button className="roomPage__container__header__back" onClick={() => router.push("/")}>Back</button>
<button className="roomPage__container__header__back" onClick={() => router.push("/menu")}>Back</button>
<div className="roomPage__container__header__title">
<h2>Join room</h2>
</div>
Expand Down
25 changes: 2 additions & 23 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,14 @@
import { useRouter } from "next/dist/client/router";
import Head from "next/head"
import { useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import Notification from "../components/notifications/Notification";
import { getSocket, selectSocket, setSocket } from "../redux/slices/socketSlice";
import { selectUser } from "../redux/slices/userSlice";
import { checkForLogin } from "../requests/auth/requests";

export default function Home() {
const userInfo = useSelector(selectUser);
const socketInfo = useSelector(selectSocket);
const dispatch = useDispatch();
const router = useRouter();

useEffect(() => {
const socket = getSocket();

if(!socketInfo.connected || !socket){
dispatch(setSocket(true));
}
}, [socketInfo.connected]);

useEffect(() => {
if(!userInfo.loggedIn || !userInfo.token){
const token = window.localStorage.getItem("refreshtoken");

if(token){
checkForLogin(dispatch, router);
}
}
}, [userInfo.loggedIn, dispatch, userInfo.token, router]);
router.push("/menu");
}, []);

return (
<div>
Expand Down
14 changes: 14 additions & 0 deletions pages/instructions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Head from "next/head"
import Notification from "../components/notifications/Notification";

export default function Instructions() {
return (
<div>
<Head>
<title>MathRoom | Instructions</title>
</Head>

<Notification />
</div>
)
}
46 changes: 46 additions & 0 deletions pages/menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { useRouter } from "next/dist/client/router";
import Head from "next/head"
import { useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import MenuContainer from "../components/containers/menu/MenuContainer";
import Notification from "../components/notifications/Notification";
import { getSocket, selectSocket, setSocket } from "../redux/slices/socketSlice";
import { selectUser } from "../redux/slices/userSlice";
import { checkForLogin } from "../requests/auth/requests";

export default function Menu() {
const userInfo = useSelector(selectUser);
const socketInfo = useSelector(selectSocket);
const dispatch = useDispatch();
const router = useRouter();

useEffect(() => {
const socket = getSocket();

if(!socketInfo.connected || !socket){
dispatch(setSocket(true));
}
}, [socketInfo.connected]);

useEffect(() => {
if(!userInfo.loggedIn || !userInfo.token){
const token = window.localStorage.getItem("refreshtoken");

if(token){
checkForLogin(dispatch, router);
}
}
}, [userInfo.loggedIn, dispatch, userInfo.token, router]);

return (
<div className="menu">
<Head>
<title>MathRoom | Menu</title>
</Head>

<Notification />

<MenuContainer />
</div>
)
}
13 changes: 13 additions & 0 deletions public/svg/clock.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions public/svg/sandClock.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions public/svg/timer.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
@import "./notifications/notifications.scss";

@import "./rooms/index.scss";
@import "./auth/auth.scss";
@import "./auth/auth.scss";
@import "./menu/menu.scss";
Loading

1 comment on commit fe52e89

@vercel
Copy link

@vercel vercel bot commented on fe52e89 Oct 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.