Skip to content

Commit

Permalink
Frontend: Fixed flicker and redirection (#149)
Browse files Browse the repository at this point in the history
Navigate to login page when user not logged in and added warning message

Fixes: #142
  • Loading branch information
Spikoftw authored Jun 26, 2024
1 parent edfab64 commit ab4243f
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions frontend/src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import '../index.css';
import { useModal } from '../library/modal/ModalContext';
import { useState } from 'react';
import { useToast } from '../library/toast/toast-context';
import { useAuth } from '../contexts/AuthContext';

function JoinGameModalContent() {
const [gameCode, setGameCode] = useState<string>('');
Expand Down Expand Up @@ -50,14 +51,27 @@ function JoinGameModalContent() {
</>
);
}

function Home() {
const modal = useModal();
const navigate = useNavigate();
const { isLoggedIn } = useAuth();
const { open } = useToast();

const CreateGame = () => {
// Logic to create a game
console.log('Create Game');
navigate('/game?type=create');
if (isLoggedIn()) {
// Logic to create a game
console.log('Create Game');
navigate('/game?type=create');
} else {
open({
message: 'You need to log in to create a game',
duration: 3000,
position: 'top-center',
color: 'warning',
});
navigate('/login');
}
};

const JoinGame = () => {
Expand Down

0 comments on commit ab4243f

Please sign in to comment.