Skip to content

Commit 237463f

Browse files
authored
Merge pull request #97 from CS3219-AY2425S1/jamie/cs3-25
Implement Unauthenticated Homepage
2 parents 05d523b + 24d6cac commit 237463f

File tree

11 files changed

+436
-16
lines changed

11 files changed

+436
-16
lines changed

frontend/package-lock.json

Lines changed: 257 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"react-modal": "^3.16.1",
3838
"react-pro-sidebar": "^1.1.0",
3939
"react-spinners": "^0.14.1",
40+
"react-syntax-highlighter": "^15.5.0",
4041
"sweetalert2": "^11.14.1",
4142
"tailwind-merge": "^2.5.2",
4243
"tailwindcss-animate": "^1.0.7",
@@ -48,6 +49,7 @@
4849
"@types/react": "^18",
4950
"@types/react-dom": "^18",
5051
"@types/react-modal": "^3.16.3",
52+
"@types/react-syntax-highlighter": "^15.5.13",
5153
"eslint": "^8",
5254
"eslint-config-next": "14.2.11",
5355
"postcss": "^8",

frontend/public/google_icon.svg

Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"use client";
2+
3+
import { useAuth } from "@/components/auth/AuthContext";
4+
import { useState, useEffect } from "react";
5+
import LandingPage from "@/app/(home)/components/landing-page/LandingPage";
6+
import LeetcodeDashboard from "./LeetcodeDashboard";
7+
8+
const Home = () => {
9+
const { token } = useAuth();
10+
const [loading, setLoading] = useState(true);
11+
12+
// Simulate token fetching or resolving logic
13+
useEffect(() => {
14+
if (token !== undefined) {
15+
setLoading(false);
16+
}
17+
}, [token]);
18+
19+
if (loading) {
20+
return null;
21+
}
22+
23+
return token ? <LeetcodeDashboard /> : <LandingPage />;
24+
};
25+
26+
export default Home;

frontend/src/app/(auth)/page.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
2+
import { darcula } from 'react-syntax-highlighter/dist/esm/styles/prism';
3+
4+
const CodeSnippetHighlight = () => {
5+
const code = `class Solution:
6+
def twoSum(self, nums: List[int], target: int) -> List[int]:
7+
idxDict = {}
8+
for i, num in enumerate(nums):
9+
idxDict[num] = i
10+
11+
for i, num in enumerate(nums):
12+
diff = target - num
13+
if diff in idxDict and i != idxDict[diff]:
14+
return [i, idxDict[diff]]`;
15+
return (
16+
<SyntaxHighlighter language="python" style={darcula}>
17+
{code}
18+
</SyntaxHighlighter>
19+
);
20+
};
21+
22+
export default CodeSnippetHighlight;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Image from "next/image";
2+
import Link from "next/link";
3+
4+
const GoogleIcon = () => {
5+
const iconSize = 24;
6+
return (
7+
<div className="inline-block">
8+
<Link href="/">
9+
<Image
10+
alt="Google Icon"
11+
src="google_icon.svg"
12+
width={iconSize}
13+
height={iconSize}
14+
/>
15+
</Link>
16+
</div>
17+
);
18+
};
19+
20+
export default GoogleIcon;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import CodeSnippet from "@/app/(home)/components/code-snippet/CodeSnippetHighlight";
2+
import { Button } from "@/components/ui/button";
3+
import { Card, CardContent } from "@/components/ui/card";
4+
import GoogleIcon from "@/app/(home)/components/icon/GoogleIcon";
5+
import { useAuth } from "@/components/auth/AuthContext";
6+
import { useGoogleLogin } from "@react-oauth/google";
7+
import { useRouter } from "next/navigation";
8+
9+
const LandingPage = () => {
10+
const { login, token } = useAuth();
11+
const router = useRouter();
12+
13+
const googleLogin = useGoogleLogin({
14+
onSuccess: (response) => {
15+
login(response);
16+
router.push("/leetcode-dashboard"); // Redirect to dashboard after successful login
17+
},
18+
onError: (error) => {
19+
console.error("Login Failed:", error);
20+
},
21+
});
22+
23+
// Trigger OAuth pop up only if user is not authenticated (token is not present)
24+
const handleLogin = () => {
25+
if (token) {
26+
router.push("/leetcode-dashboard");
27+
} else {
28+
googleLogin();
29+
}
30+
}
31+
32+
return (
33+
<div className="flex items-center justify-center min-h-[90vh]">
34+
<div className="flex justify-between max-w-[90vw]">
35+
<div className="flex-1 pr-10 h-full">
36+
<h1 className="text-6xl font-extrabold text-white pb-8">
37+
Collaborative Coding, Competitive Results.
38+
</h1>
39+
<p className="font-normal text-white pb-8">
40+
Join PeerPrep to sharpen your skills through real-time problem-solving, and prepare to outshine in every interview.
41+
Created for CS3219 Software Engineering Principles AY24/25 by Group 15.
42+
</p>
43+
<div className="pt-8">
44+
<Button className="font-semibold w-full" onClick={() => handleLogin()}>
45+
<GoogleIcon/>
46+
<span className="pl-2">Get Started with Google</span>
47+
</Button>
48+
</div>
49+
</div>
50+
<div className="flex-1 h-full">
51+
<Card className="bg-primary-1000 border-none pt-2 pb-2 max-w-[90vw] h-full drop-shadow">
52+
<CardContent className="h-full">
53+
<CodeSnippet />
54+
</CardContent>
55+
</Card>
56+
</div>
57+
</div>
58+
</div>
59+
);
60+
};
61+
62+
export default LandingPage;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from "react";
2+
import Link from "next/link";
3+
import Header from "@/components/ui/Header";
4+
5+
const Navbar = () => {
6+
const isActive = (path: string) => window.location.pathname === path;
7+
return (
8+
<nav className="flex justify-between items-center p-4 bg-gray-900">
9+
<div className="flex-shrink-0">
10+
<Header />
11+
</div>
12+
13+
<div className="flex space-x-6">
14+
<Link href="/home" className={`text-primary-300 hover:underline ${isActive("/") ? "opacity-100" : "opacity-50 hover:opacity-100"}`}>
15+
Home
16+
</Link>
17+
<Link href="" className={`text-primary-300 hover:underline ${isActive("/about") ? "opacity-100" : "opacity-50 hover:opacity-100"}`}>
18+
About Us
19+
</Link>
20+
<Link href="https://github.com/CS3219-AY2425S1/cs3219-ay2425s1-project-g15" className="text-primary-300 opacity-50 hover:underline hover:opacity-100">
21+
Our Codebase
22+
</Link>
23+
</div>
24+
</nav>
25+
);
26+
};
27+
28+
export default Navbar;

frontend/src/app/(home)/page.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"use client";
2+
3+
import Navbar from "@/app/(home)/components/navbar/Navbar";
4+
import LandingPage from "@/app/(home)/components/landing-page/LandingPage";
5+
6+
const Home = () => {
7+
return (
8+
<>
9+
<Navbar />
10+
<LandingPage />
11+
</>
12+
);
13+
};
14+
15+
export default Home;

0 commit comments

Comments
 (0)