first commit

This commit is contained in:
Jeannette Chin committed 2026-10-04 14:02:29 +01:00
commit 8863184a41
42 files changed
+3660

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
## Getting Started
First, run the development server:
```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
## Learn More
To learn more about Next.js, take a look at the following resources:
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
## Deploy on Vercel
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
+11
View File
@@ -0,0 +1,11 @@
const AuthLayout = ({ children }: { children: React.ReactNode }) => {
return (
<div className="min-h-[calc(100vh-8rem)] flex items-center justify-center p-4">
<div className="card w-full max-w-md bg-base-200 shadow-xl">
<div className="card-body">{children}</div>
</div>
</div>
);
};
export default AuthLayout;
+48
View File
@@ -0,0 +1,48 @@
"use client";
import Link from "next/link";
const CustomLoginForm = () => {
return (
<>
<form className="mt-4">
{" "}
<div className="form-control">
<label className="label">
<span className="label-text">Email</span>
</label>
<input
type="email"
placeholder="you@example.com"
className="input input-bordered w-full"
required
/>
</div>
<div className="form-control mt-4">
<label className="label">
<span className="label-text">Password</span>
</label>
<input
type="password"
placeholder="••••••••"
className="input input-bordered w-full"
required
/>
</div>
<div className="form-control mt-6">
<button type="submit" className="btn btn-primary w-full">
Sign In
</button>
</div>
</form>
<div className="divider">OR</div>
<p className="text-center">
Don&apos;t have an account?{" "}
<Link href="/register" className="link link-primary">
Sign up
</Link>
</p>
</>
);
};
export default CustomLoginForm;
+26
View File
@@ -0,0 +1,26 @@
const SigninButton = ({
text,
style,
callback,
formAction
}: {
text: string;
style: string;
callback?: () => void;
formAction?: any;
}) => {
return (
<div className="form-control mt-6">
<button
type="submit"
formAction={formAction}
className={style}
onClick={callback}
>
{text}
</button>
</div>
);
};
export default SigninButton;
+38
View File
@@ -0,0 +1,38 @@
"use client";
import CustomLoginForm from "./CustomLoginForm";
import SigninButton from "./SigninButton";
import { useState } from "react";
import { handleGoogleLogin } from "@/app/actions/GoogleAction";
const LoginPage = () => {
const [elogin, setElogin] = useState(false);
const ShowEmailLogin = () => {
setElogin(!elogin);
};
return (
<>
<h2 className="card-title text-2xl justify-center w-full">
Please Sign In
</h2>
<form className="mt-4">
<SigninButton
text="Google"
style="btn btn-primary w-full"
formAction={handleGoogleLogin}
/>
</form>
<div className="mt-4">
<SigninButton
text="Email"
style="btn btn-primary w-full"
callback={ShowEmailLogin}
/>
</div>
<div className="mt-4">{elogin ? <CustomLoginForm /> : ""}</div>
</>
);
};
export default LoginPage;
+75
View File
@@ -0,0 +1,75 @@
"use client";
import Link from "next/link";
const RegisterPage = () => {
return (
<>
<h2 className="card-title text-2xl justify-center">Create Account</h2>
<form className="mt-4">
<div className="form-control">
<label className="label">
<span className="label-text">Name</span>
</label>
<input
type="text"
placeholder="Your name"
className="input input-bordered w-full"
required
/>
</div>
<div className="form-control mt-4">
<label className="label">
<span className="label-text">Email</span>
</label>
<input
type="email"
placeholder="you@example.com"
className="input input-bordered w-full"
required
/>
</div>
<div className="form-control mt-4">
<label className="label">
<span className="label-text">Password</span>
</label>
<input
type="password"
placeholder="••••••••"
className="input input-bordered w-full"
required
minLength={6}
/>
</div>
<div className="form-control mt-4">
<label className="label">
<span className="label-text">Confirm Password</span>
</label>
<input
type="password"
placeholder="••••••••"
className="input input-bordered w-full"
required
/>
</div>
<div className="form-control mt-6">
<button type="submit" className="btn btn-primary w-full">
Create Account
</button>
</div>
</form>
<div className="divider">OR</div>
<p className="text-center">
Already have an account?{" "}
<Link href="/login" className="link link-primary">
Sign in
</Link>
</p>
</>
);
};
export default RegisterPage;
+18
View File
@@ -0,0 +1,18 @@
"use client";
import { useRef } from "react";
import { Provider } from "react-redux";
import { makeStore, AppStore } from "../lib/store";
export default function PeopleProvider({
children,
}: {
children: React.ReactNode;
}) {
const storeRef = useRef<AppStore>(undefined);
if (!storeRef.current) {
// Create the store instance the first time this renders
storeRef.current = makeStore();
}
return <Provider store={storeRef.current}>{children}</Provider>;
}
+17
View File
@@ -0,0 +1,17 @@
"use server";
import { auth, signIn, signOut } from "@/auth";
export async function handleGoogleLogin() {
console.log(`google action`);
await signIn("google", { redirectTo: "/" });
}
export async function checkGoogleSession() {
const session = await auth();
return session;
}
export async function handleGoogleSignout() {
await signOut({ redirectTo: "/login" });
}
+2
View File
@@ -0,0 +1,2 @@
import { handlers } from "@/auth"; // Referring to the auth.ts we just created
export const { GET, POST } = handlers;
+117
View File
@@ -0,0 +1,117 @@
"use client";
import { Links } from "./navbarData";
import Link from "next/link";
import { usePathname } from "next/navigation"; // for checking active links
import { useAuth } from "../hooks/useAuth";
const NavBar = () => {
const pathname = usePathname();
const { isAuthenticated, user, logout, isLoading } = useAuth();
console.log(`isAuthenticated ... ${isAuthenticated}`);
return (
<nav className="navbar bg-base-100 shadow-sm">
<div className="navbar-start">
<div className="dropdown">
<div tabIndex={0} role="button" className="btn btn-ghost lg:hidden">
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-5 w-5"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
{" "}
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M4 6h16M4 12h8m-8 6h16"
/>{" "}
</svg>
</div>
<ul
tabIndex={-1}
className="menu menu-sm dropdown-content bg-base-100 rounded-box z-1 mt-3 w-52 p-2 shadow"
>
{Links.map((l) => {
const { id, url, text } = l;
return (
<li
className={`${pathname === url ? "menu-active" : ""}`}
key={id}
>
{/* here we use Link */}
<Link href={url}>{text}</Link>
</li>
);
})}
</ul>
</div>
<a className="btn btn-ghost text-xl">Adv WebDev</a>
</div>
<div className="navbar-center hidden lg:flex">
<ul className="menu menu-horizontal px-1">
{Links.map((l) => {
const { id, url, text } = l;
return (
<li
className={`${pathname === url ? "menu-active" : ""}`}
key={id}
>
{/* here we use Link */}
<Link href={url}>{text}</Link>
</li>
);
})}
</ul>
</div>
<div className="navbar-end">
{isAuthenticated ? (
<div className="dropdown dropdown-end">
<div
tabIndex={0}
role="button"
className="btn btn-ghost btn-circle avatar placeholder"
>
<div className="bg-primary text-primary-content w-10 rounded-full flex items-center justify-center">
<span className="text-lg">
{user?.name?.charAt(0).toUpperCase()}
</span>
</div>
</div>
<ul
tabIndex={0}
className="menu menu-sm dropdown-content bg-base-100 rounded-box z-1 mt-3 w-52 p-2 shadow"
>
<li className="menu-title">{user?.name}</li>
<li>
<button onClick={logout}>Logout</button>
</li>
</ul>
</div>
) : (
<div className="flex gap-2">
<Link href="/login" className="btn btn-ghost btn-sm">
Login
</Link>
<Link href="/register" className="btn btn-primary btn-sm">
Sign Up
</Link>
</div>
)}
{/* {" "}
<div className="flex gap-2">
<Link href="/login" className="btn btn-ghost btn-sm">
Login
</Link>
<Link href="/register" className="btn btn-primary btn-sm">
Sign Up
</Link>
</div> */}
</div>
</nav>
);
};
export default NavBar;
+7
View File
@@ -0,0 +1,7 @@
"use client";
import { AuthProvider } from "../hooks/useAuth";
export function Providers({ children }: { children: React.ReactNode }) {
return <AuthProvider>{children}</AuthProvider>;
}
+23
View File
@@ -0,0 +1,23 @@
interface Link {
id: number;
url: string;
text: string;
}
export const Links: Link[] = [
{
id: 1,
url: "/",
text: "home",
},
{
id: 2,
url: "/people",
text: "People",
},
{
id: 3,
url: "/newsletters",
text: "Newsletters",
},
];
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

+33
View File
@@ -0,0 +1,33 @@
"use client";
export default function GlobalError({
error,
reset,
}: {
error: Error & { digest?: string };
reset: () => void;
}) {
return (
<html>
<body>
<div className="min-h-[50vh] flex items-center justify-center p-4">
<div className="text-center">
<div className="text-6xl mb-4">😵</div>
<h2 className="text-2xl font-bold mb-2">Something went wrong!</h2>
<p className="text-base-content/70 mb-4">
{error.message || "An unexpected error occurred"}
</p>
<div className="flex gap-4 justify-center">
<button onClick={() => reset()} className="btn btn-primary">
Try again
</button>
<a href="/" className="btn btn-ghost">
Go home
</a>
</div>
</div>
</div>
</body>
</html>
);
}
+55
View File
@@ -0,0 +1,55 @@
@import "tailwindcss";
@plugin "daisyui";
:root {
--background: #ffffff;
--foreground: #171717;
}
@theme inline {
--color-background: var(--background);
--color-foreground: var(--foreground);
--font-sans: var(--font-geist-sans);
--font-mono: var(--font-geist-mono);
}
@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}
body {
background: var(--background);
color: var(--foreground);
font-family: Arial, Helvetica, sans-serif;
}
/* HTML: <div class="loader"></div> */
/* From Uiverse.io by satyamchaudharydev */
.loader {
margin-left: 50%;
margin-top: 15%;
width: 60px;
height: 60px;
}
.loader::before {
content: "";
box-sizing: border-box;
position: absolute;
width: 60px;
height: 60px;
border-radius: 50%;
border-top: 2px solid #8900ff;
border-right: 2px solid transparent;
animation: spinner8217 0.8s linear infinite;
}
@keyframes spinner8217 {
to {
transform: rotate(360deg);
}
}
+99
View File
@@ -0,0 +1,99 @@
"use client";
import {
createContext,
useContext,
useState,
useEffect,
useCallback,
ReactNode
} from "react";
import {
checkGoogleSession,
handleGoogleSignout
} from "../actions/GoogleAction";
interface User {
id: string | null | undefined;
email: string | null | undefined;
name: string | null | undefined;
}
interface AuthState {
user: User;
isAuthenticated: boolean;
isLoading: boolean;
}
interface AuthContextType extends AuthState {
checkGoogle: () => void;
logout: () => Promise<void>;
}
const AuthContext = createContext<AuthContextType | undefined>(undefined);
export function AuthProvider({ children }: { children: ReactNode }) {
const user = {
id: "",
email: "",
name: ""
};
const [authState, setAuthState] = useState<AuthState>({
user: user,
isAuthenticated: false,
isLoading: true
});
const checkGoogle = async () => {
const session = await checkGoogleSession();
if (session) {
const currentUser: User = {
id: session.user?.id,
name: session.user?.name,
email: session.user?.email
};
setAuthState({
user: currentUser,
isAuthenticated: true,
isLoading: false
});
}
};
// Check auth status on mount
useEffect(() => {
checkGoogle();
}, []);
const logout = useCallback(async () => {
setAuthState({
user: user,
isAuthenticated: false,
isLoading: false
});
await handleGoogleSignout();
}, []);
const value: AuthContextType = {
...authState,
checkGoogle,
logout
};
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
}
/**
* useAuth hook - uses shared AuthContext
* All components using this hook share the same auth state
*/
export function useAuth() {
const context = useContext(AuthContext);
if (context === undefined) {
throw new Error("useAuth must be used within an AuthProvider");
}
return context;
}
+45
View File
@@ -0,0 +1,45 @@
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";
import NavBar from "./components/NavBar";
import { Toaster } from "react-hot-toast";
import PeopleProvider from "./PeopleProvider";
import { Providers } from "./components/Providers";
const geistSans = Geist({
variable: "--font-geist-sans",
subsets: ["latin"]
});
const geistMono = Geist_Mono({
variable: "--font-geist-mono",
subsets: ["latin"]
});
export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app"
};
export default function RootLayout({
children
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html
lang="en"
className={`${geistSans.variable} ${geistMono.variable} h-full antialiased`}
>
<body className="min-h-full flex flex-col">
<Providers>
<PeopleProvider>
<Toaster position="bottom-right" />
<NavBar />
{children}
</PeopleProvider>
</Providers>
</body>
</html>
);
}
+10
View File
@@ -0,0 +1,10 @@
export default function GlobalLoading() {
return (
<div className="min-h-[50vh] flex items-center justify-center">
<div className="text-center">
<span className="loading loading-spinner loading-lg text-primary"></span>
<p className="mt-4 text-base-content/70">Loading...</p>
</div>
</div>
);
}
+24
View File
@@ -0,0 +1,24 @@
interface PageProps {
params: Promise<{ id: string }>;
}
const NewsletterDetailPage = async ({ params }: PageProps) => {
const { id } = await params;
return (
<>
<div className="text-center">
<h1 className="font-bold text-center text-amber-900 tracking-tight mt-2 text-3xl">
Newsletter Page
</h1>
<h2 className="text-center text-fuchsia-600 mt-2">
{" "}
ID requested {id}{" "}
</h2>
<p className="mt-5">Your implementation goes here </p>
</div>
</>
);
};
export default NewsletterDetailPage;
+14
View File
@@ -0,0 +1,14 @@
"use client";
const NewslettersPage = () => {
return (
<div className="text-center">
<h1 className="font-bold text-center text-amber-900 tracking-tight mt-2 text-3xl">
Newsletters Page
</h1>
<p className="mt-5">Your implementation goes here </p>
</div>
);
};
export default NewslettersPage;
+23
View File
@@ -0,0 +1,23 @@
import Link from "next/link";
export default function NotFound() {
return (
<div className="min-h-[50vh] flex items-center justify-center p-4">
<div className="text-center">
<div className="text-8xl font-bold text-primary mb-4">404</div>
<h2 className="text-2xl font-bold mb-2">Page Not Found</h2>
<p className="text-base-content/70 mb-6">
The page you&apos;re looking for doesn&apos;t exist or has been moved.
</p>
<div className="flex gap-4 justify-center">
<Link href="/" className="btn btn-primary">
Go Home
</Link>
<Link href="/skills" className="btn btn-ghost">
Browse Skills
</Link>
</div>
</div>
</div>
);
}
+65
View File
@@ -0,0 +1,65 @@
import Image from "next/image";
export default function Home() {
return (
<div className="flex flex-col flex-1 items-center justify-center bg-zinc-50 font-sans dark:bg-black">
<main className="flex flex-1 w-full max-w-3xl flex-col items-center justify-between py-32 px-16 bg-white dark:bg-black sm:items-start">
<Image
className="dark:invert"
src="/next.svg"
alt="Next.js logo"
width={100}
height={20}
priority
/>
<div className="flex flex-col items-center gap-6 text-center sm:items-start sm:text-left">
<h1 className="max-w-xs text-3xl font-semibold leading-10 tracking-tight text-black dark:text-zinc-50">
To get started, edit the page.tsx file.
</h1>
<p className="max-w-md text-lg leading-8 text-zinc-600 dark:text-zinc-400">
Looking for a starting point or more instructions? Head over to{" "}
<a
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
className="font-medium text-zinc-950 dark:text-zinc-50"
>
Templates
</a>{" "}
or the{" "}
<a
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
className="font-medium text-zinc-950 dark:text-zinc-50"
>
Learning
</a>{" "}
center.
</p>
</div>
<div className="flex flex-col gap-4 text-base font-medium sm:flex-row">
<a
className="flex h-12 w-full items-center justify-center gap-2 rounded-full bg-foreground px-5 text-background transition-colors hover:bg-[#383838] dark:hover:bg-[#ccc] md:w-[158px]"
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
className="dark:invert"
src="/vercel.svg"
alt="Vercel logomark"
width={16}
height={16}
/>
Deploy Now
</a>
<a
className="flex h-12 w-full items-center justify-center rounded-full border border-solid border-black/[.08] px-5 transition-colors hover:border-transparent hover:bg-black/[.04] dark:border-white/[.145] dark:hover:bg-[#1a1a1a] md:w-[158px]"
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Documentation
</a>
</div>
</main>
</div>
);
}
+39
View File
@@ -0,0 +1,39 @@
"use client";
import type { Result } from "./person";
interface PersonItemProps extends Result {
remove: (uuid: string) => void;
}
const PersonItem = ({ remove, ...result }: PersonItemProps) => {
const { email, login, location, name, picture } = result;
return (
<div className="card bg-base-200 w-96 shadow-sm" key={login.uuid}>
<figure className="px-10 pt-10">
<img src={picture.medium} alt={name.last} className="rounded-sm" />
</figure>
<div className="card-body items-center text-center">
<h2 className="card-title sm:text-sm md:text-lg lg:text-xl">
{name.first} {name.last}
</h2>
<h4>{email}</h4>
<p className="sm:text-sm md:text-md lg:text-lg">
{location.city}, {location.country}
</p>
<div className="card-actions">
<button
className="btn btn-active btn-accent btn-xs sm:btn-sm md:btn-md lg:btn-lg xl:btn-xl"
onClick={() => remove(login.uuid)}
>
{" "}
remove{" "}
</button>
</div>
</div>
</div>
);
};
export default PersonItem;
+62
View File
@@ -0,0 +1,62 @@
"use client";
import axios from "axios";
import type { Result } from "./person";
import PersonItem from "./PersonItem";
import { useEffect, useState } from "react";
import { toast } from "react-hot-toast";
const url = "https://randomuser.me/api/?results=12";
const PeoplePage = () => {
const [users, setUsers] = useState<Result[]>([]);
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
axios
.get(url)
.then((response) => {
console.log(response);
setUsers(response.data.results);
setIsLoading(false);
})
.catch((error: any) => {
if (error.isAxiosError) {
console.log(error.response);
toast.error(`Error occurred while fetching..`);
} else {
console.log(error);
}
});
}, []);
if (isLoading) {
return (
<>
<span className="loading loading-ball loading-xs"></span>
<span className="loading loading-ball loading-sm"></span>
<span className="loading loading-ball loading-md"></span>
<span className="loading loading-ball loading-lg"></span>
<span className="loading loading-ball loading-xl"></span>
</>
);
}
return (
<section>
<h2 className="font-bold text-center text-amber-900 tracking-tight mt-2 text-3xl">
People Page
</h2>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 p-6">
{users?.map((user) => {
return (
<PersonItem {...user} key={user.login.uuid} remove={() => {}} />
);
})}
</div>
</section>
);
};
export default PeoplePage;
+71
View File
@@ -0,0 +1,71 @@
"use client";
import type { Result } from "./person";
import PersonItem from "./PersonItem";
import { useEffect, useState } from "react";
import {
fetchRandomUsers,
clearList,
removeUser,
} from "@/lib/features/people/personSlice";
import { useAppSelector, useAppDispatch, useAppStore } from "../../lib/hooks";
const PeoplePage = () => {
const { results, isLoading } = useAppSelector((store) => store.people);
const dispatch = useAppDispatch();
useEffect(() => {
dispatch(fetchRandomUsers());
}, []);
const handleClearList = () => {
dispatch(clearList());
};
const reset = () => {
dispatch(fetchRandomUsers());
};
const remove = (id: any) => {
dispatch(removeUser(id));
};
if (isLoading) {
return (
<div className="p-6 max-w-md mx-auto my-4">
{" "}
<span className="loading loading-spinner loading-sm"></span>
</div>
);
}
return (
<section>
<h2 className="font-bold text-center text-amber-900 tracking-tight mt-2 text-3xl">
People Page
</h2>
<div className="flex items-center justify-center mt-5">
{results?.length < 1 ? (
<button className="btn btn-soft" onClick={reset}>
reset
</button>
) : (
<button className="btn btn-soft" onClick={handleClearList}>
Clear All
</button>
)}
</div>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 p-6">
{results?.map((p: Result) => {
return <PersonItem {...p} key={p.login.uuid} remove={remove} />;
})}
</div>
</section>
);
};
export default PeoplePage;
+86
View File
@@ -0,0 +1,86 @@
interface RootObject {
results: Result[];
info: Info;
}
interface Info {
seed: string;
results: number;
page: number;
version: string;
}
interface Result {
content: React.ReactNode;
gender: string;
name: Name;
location: Location;
email: string;
login: Login;
dob: Dob;
registered: Dob;
phone: string;
cell: string;
id: Id;
picture: Picture;
nat: string;
}
interface Picture {
large: string;
medium: string;
thumbnail: string;
}
interface Id {
name: string;
value: null | string;
}
interface Dob {
date: string;
age: number;
}
interface Login {
uuid: string;
username: string;
password: string;
salt: string;
md5: string;
sha1: string;
sha256: string;
}
interface Location {
street: Street;
city: string;
state: string;
country: string;
postcode: number | string;
coordinates: Coordinates;
timezone: Timezone;
}
interface Timezone {
offset: string;
description: string;
}
interface Coordinates {
latitude: string;
longitude: string;
}
interface Street {
number: number;
name: string;
}
interface Name {
title: string;
first: string;
last: string;
}
export type { Result, Name, Picture, Location, Login };
+12
View File
@@ -0,0 +1,12 @@
import NextAuth from "next-auth";
import Google from "next-auth/providers/google";
export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [Google],
callbacks: {
authorized: async ({ auth }) => {
// Logged in users are authenticated, otherwise redirect to login page
return !!auth;
}
}
});
+18
View File
@@ -0,0 +1,18 @@
import { defineConfig, globalIgnores } from "eslint/config";
import nextVitals from "eslint-config-next/core-web-vitals";
import nextTs from "eslint-config-next/typescript";
const eslintConfig = defineConfig([
...nextVitals,
...nextTs,
// Override default ignores of eslint-config-next.
globalIgnores([
// Default ignores of eslint-config-next:
".next/**",
"out/**",
"build/**",
"next-env.d.ts",
]),
]);
export default eslintConfig;
+64
View File
@@ -0,0 +1,64 @@
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
import axios from "axios";
import { Result } from "@/app/people/person";
const url = "https://randomuser.me/api/?results=12";
const initialState = {
results: [],
isLoading: true,
} as any;
export const fetchRandomUsers = createAsyncThunk(
"people/getRandomUsers",
async (name, thunkApi) => {
try {
const response = await axios.get(url);
return response.data.results;
} catch (error: any) {
if (error.isAxiosError) {
console.log(error.response);
return thunkApi.rejectWithValue(error.response);
} else {
console.log(error);
}
}
},
);
const personSlice = createSlice({
name: "people",
initialState,
reducers: {
clearList: (state) => {
state.results = [];
},
removeUser: (state, action) => {
const uuid = action.payload;
state.results = state.results.filter(
(user: Result) => user.login.uuid !== uuid,
);
},
},
extraReducers: (builder) => {
builder.addCase(fetchRandomUsers.pending, (state) => {
state.isLoading = true;
});
builder.addCase(fetchRandomUsers.fulfilled, (state, action) => {
console.log(state);
console.log(action.payload);
state.results = action.payload;
state.isLoading = false;
console.log(state.results.length);
});
builder.addCase(fetchRandomUsers.rejected, (state) => {
state.isLoading = false;
});
},
});
console.log(personSlice);
export const { clearList, removeUser } = personSlice.actions;
export default personSlice.reducer;
+7
View File
@@ -0,0 +1,7 @@
import { useDispatch, useSelector, useStore } from "react-redux";
import type { RootState, AppDispatch, AppStore } from "./store";
// Use throughout your app instead of plain `useDispatch` and `useSelector`
export const useAppDispatch = useDispatch.withTypes<AppDispatch>();
export const useAppSelector = useSelector.withTypes<RootState>();
export const useAppStore = useStore.withTypes<AppStore>();
+15
View File
@@ -0,0 +1,15 @@
import { configureStore } from "@reduxjs/toolkit";
import "@/lib/features/people/personSlice";
import personReducer from "./features/people/personSlice";
export const makeStore = () => {
return configureStore({
reducer: { people: personReducer },
});
};
// Infer the type of makeStore
export type AppStore = ReturnType<typeof makeStore>;
// Infer the `RootState` and `AppDispatch` types from the store itself
export type RootState = ReturnType<AppStore["getState"]>;
export type AppDispatch = AppStore["dispatch"];
+10
View File
@@ -0,0 +1,10 @@
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
/* config options here */
experimental: {
useTypeScriptCli: true
}
};
export default nextConfig;
+2378
View File
File diff suppressed because it is too large. Load diff
+35
View File
@@ -0,0 +1,35 @@
{
"name": "lab3",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "eslint"
},
"overrides": {
"postcss": "^8.5.18",
"sharp": "^0.35.0"
},
"dependencies": {
"@reduxjs/toolkit": "^2.12.0",
"daisyui": "^5.7.0",
"next": "^16.2.12",
"next-auth": "^5.0.0-beta.32",
"react": "19.2.8",
"react-dom": "19.2.8",
"react-hot-toast": "^2.6.0",
"react-icons": "^5.7.0",
"react-redux": "^9.3.0"
},
"devDependencies": {
"@tailwindcss/postcss": "^4.3.3",
"@types/node": "^26",
"@types/react": "^19",
"@types/react-dom": "^19",
"tailwindcss": "^4.3.3",
"typescript": "7.0.2"
},
"browserlist": ">1%"
}
+7
View File
@@ -0,0 +1,7 @@
const config = {
plugins: {
"@tailwindcss/postcss": {},
},
};
export default config;
+31
View File
@@ -0,0 +1,31 @@
//export { auth as proxy } from "@/auth";
import { auth } from "@/auth";
// export const proxy = auth((req) => {
// if (!req.auth && req.nextUrl.pathname !== "/login") {
// const newUrl = new URL("/login", req.nextUrl.origin);
// return Response.redirect(newUrl);
// }
// });
export const proxy = auth((req) => {
const { pathname } = req.nextUrl;
const isAuthRoute = pathname === "/login" || pathname === "/register";
// If user is not authenticated and not visiting an auth page, redirect to login
if (!req.auth && !isAuthRoute) {
const newUrl = new URL("/login", req.nextUrl.origin);
return Response.redirect(newUrl);
}
// (Optional) If the user IS authenticated, prevent them from visiting login/register
if (req.auth && isAuthRoute) {
const homeUrl = new URL("/", req.nextUrl.origin);
return Response.redirect(homeUrl);
}
});
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
};
+1
View File
@@ -0,0 +1 @@
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>

After

Width:  |  Height:  |  Size: 391 B

+1
View File
@@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

+1
View File
@@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>

After

Width:  |  Height:  |  Size: 128 B

+1
View File
@@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>

After

Width:  |  Height:  |  Size: 385 B

+34
View File
@@ -0,0 +1,34 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
".next/dev/types/**/*.ts",
"**/*.mts"
],
"exclude": ["node_modules"]
}