Skip to content

Commit

Permalink
Merge pull request #22 from visakhvjn/18-make-a-login-page
Browse files Browse the repository at this point in the history
18 make a login page
  • Loading branch information
visakhvjn authored May 25, 2024
2 parents 0ec2f5b + 7378bf3 commit 5d967fb
Show file tree
Hide file tree
Showing 20 changed files with 471 additions and 48 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-hooks/exhaustive-deps': 'off',
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
Expand Down
42 changes: 42 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"react-router-dom": "^6.23.1",
"tailwindcss": "^3.4.3",
"typescript": "^5.2.2",
"vite": "^5.2.0"
Expand Down
46 changes: 27 additions & 19 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
import "./App.css";
import BrainIcon from './assets/brain_ai.svg';
// import BrainIcon from './assets/brain_ai.svg';
import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom";
import { Categories, Login, NotFound, Trivia } from "./pages";
import { useAuth0 } from "@auth0/auth0-react";
import { Loader } from "./components";

import { Coin, Header, Hero, Logo, Trivia } from "./components/index";
// import { Coin, Header, Hero, Logo, Trivia } from "./components/index";

function App() {
const { isLoading, isAuthenticated } = useAuth0();

return (
<div className="flex flex-col w-full items-center justify-center text-black">
<Header>
<div className="flex justify-between w-full">
<Logo />
<Coin />
</div>
</Header>
<Hero>
<div className="flex items-center">
<img className="border border-black rounded-full p-4" src={BrainIcon} />
<span className="text-shadow-md text-6xl font-bold">&nbsp;trivia.ai</span>
</div>
</Hero>
<div className="flex">
<Trivia />
</div>
</div>
<>
{isLoading && <Loader />}
{!isLoading && (
<BrowserRouter>
<Routes>
<Route path="/" element={<Login />} />
<Route
path="/categories"
element={isAuthenticated ? <Categories /> : <Navigate to="/" />}
/>
<Route
path="/trivia"
element={isAuthenticated ? <Trivia /> : <Navigate to="/" />}
/>
<Route path="*" index element={<NotFound />} />
</Routes>
</BrowserRouter>
)}
</>
);
}

Expand Down
3 changes: 3 additions & 0 deletions src/assets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import BrainIcon from './brain_ai.svg';

export { BrainIcon };
37 changes: 37 additions & 0 deletions src/components/app-header/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from "react";
import Header from "../header";
import { BrainIcon } from "../../assets";
import Auth0LogoutButton from "../auth0-logout-button";
import { useNavigate } from "react-router-dom";

const AppHeader: React.FC = () => {
const navigate = useNavigate();

const onLogout = () => {
localStorage.clear();
navigate("/");
};

return (
<Header>
<div className="flex justify-between w-full">
<div className="flex space-x-2 items-center justify-center">
<img
onClick={() => navigate("/categories")}
className="border border-black rounded-full p-1 h-10 cursor-pointer"
src={BrainIcon}
/>
<div className="flex flex-col text-left">
<span className="text-shadow-md font-bold">trivia.ai</span>
<span className="text-xs">Endless Knowledge</span>
</div>
</div>
<div>
<Auth0LogoutButton onLogout={onLogout} />
</div>
</div>
</Header>
);
};

export default AppHeader;
8 changes: 6 additions & 2 deletions src/components/auth0-login-button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ const Auth0LoginButton: React.FC<Auth0LoginButtonProps> = ({ onLogin }) => {

return (
<div>
<button disabled={isAuthenticated} onClick={handleLogin}>
Login
<button
className="px-4 bg-white text-black border border-black py-1 hover:bg-black hover:text-white"
disabled={isAuthenticated}
onClick={handleLogin}
>
Login via Google
</button>
</div>
);
Expand Down
6 changes: 5 additions & 1 deletion src/components/auth0-logout-button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ const Auth0LogoutButton: React.FC<Auth0LogoutButtonProps> = ({ onLogout }) => {

return (
<div>
<button disabled={!isAuthenticated} onClick={handleLogout}>
<button
disabled={!isAuthenticated}
onClick={handleLogout}
className="px-4 bg-white text-black border border-black py-1 hover:bg-black hover:text-white"
>
Logout
</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { PropsWithChildren } from "react";

const Header: React.FC<PropsWithChildren> = ({ children }) => {
return (
<div className="absolute top-0 left-0 w-full items-center flex p-1">
<div className="absolute top-0 left-0 w-full items-center flex p-4">
{children}
</div>
);
Expand Down
4 changes: 3 additions & 1 deletion src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import AppHeader from "./app-header";
import Auth0LoginButton from "./auth0-login-button";
import Auth0LogoutButton from "./auth0-logout-button";
import Coin from "./coin";
Expand All @@ -7,4 +8,5 @@ import Loader from "./loader";
import Logo from "./logo";
import Trivia from "./trivia";

export { Auth0LoginButton, Hero, Auth0LogoutButton, Trivia, Loader, Header, Coin, Logo };

export { Auth0LoginButton, Hero, Auth0LogoutButton, Trivia, Loader, Header, Coin, Logo, AppHeader };
2 changes: 1 addition & 1 deletion src/components/loader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Loader: React.FC = () => {
<div className="flex flex-col items-center justify-center h-full mt-20 p-20">
<div className="w-12 h-12 border-t-4 border-secondary dark:border-primary rounded-full animate-spin"></div>
<p className="text-secondary dark:text-primary font-semibold mt-10">
Getting the Next Question
Sit Tight! Loading
</p>
</div>
</>
Expand Down
14 changes: 13 additions & 1 deletion src/components/logo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import React from "react";
import { BrainIcon } from "../../assets";

const Logo: React.FC = () => {
return <div></div>;
return (
<div className="flex flex-col items-center">
<img className="border border-black rounded-full p-4" src={BrainIcon} />
<br />
<div className="flex flex-col">
<span className="text-shadow-md text-6xl font-bold">
&nbsp;trivia.ai
</span>
<span>Discover Smart, Fun, Endless Knowledge</span>
</div>
</div>
);
};

export default Logo;
10 changes: 5 additions & 5 deletions src/components/trivia/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react-hooks/exhaustive-deps */
import React, { useEffect, useState } from "react";
import { getTriviaFromGemini } from "../../services/gemini";
import Loader from "../loader";
Expand Down Expand Up @@ -71,15 +70,16 @@ const Trivia: React.FC = () => {
onClick={() => onOptionClick(index)}
key={index}
disabled={isAttempted}
className={`p-4 text-white ${!isAttempted && "bg-black"} ${isAttempted &&
className={`p-4 text-white ${!isAttempted && "bg-black"} ${
isAttempted &&
(index === clickedOptionIndex
? clickedOptionIndex === correctOptionIndex
? "bg-green-500"
: "bg-red-500"
: index === correctOptionIndex
? "bg-green-500"
: "")
}`}
? "bg-green-500"
: "")
}`}
>
{option}
</button>
Expand Down
14 changes: 1 addition & 13 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ body {
min-width: 320px;
min-height: 100vh;
background-color: white;
color: black;
}

h1 {
Expand All @@ -42,22 +43,12 @@ h1 {

button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}

@media (prefers-color-scheme: light) {
:root {
Expand All @@ -67,7 +58,4 @@ button:focus-visible {
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}
Loading

0 comments on commit 5d967fb

Please sign in to comment.