committing summative
This commit is contained in:
1 parent
73ac8e85be
commit
95b138f29e
44 files changed
+5319
-755
No files matched your search
@@ -0,0 +1,62 @@
|
||||
type ExternalNewsletter = {
|
||||
title: string;
|
||||
description: string;
|
||||
url: string;
|
||||
};
|
||||
|
||||
export default async function ExternalNewsletters() {
|
||||
try {
|
||||
const response = await fetch(
|
||||
"https://us-rse.org/api/newsletters.json", // can go to url to see the response body
|
||||
{
|
||||
signal: AbortSignal.timeout(5000), // errors after 5s to stop loading and go to catch
|
||||
}
|
||||
);
|
||||
|
||||
const numNewsletters = 5; // probably dont want a massively page I also dk how many newsletters the api is gonna return
|
||||
|
||||
if (!response.ok) { // display status if not succeeded
|
||||
throw new Error(`Feed request failed: ${response.status}`);
|
||||
}
|
||||
|
||||
const newsletters: ExternalNewsletter[] = await response.json(); // converts api response body into a list of objects of our type
|
||||
return (
|
||||
<section className="mt-12">
|
||||
<h2 className="text-3xl font-bold">
|
||||
{/* I am assuming when I pick the first five its the latest 5 */}
|
||||
Latest from US-RSE
|
||||
</h2>
|
||||
|
||||
<ul className="mt-6 space-y-6">
|
||||
{newsletters.slice(0, numNewsletters).map((newsletter) => ( // slice out varnum from 0 and map them to list items
|
||||
<li
|
||||
key={newsletter.url}
|
||||
className="border-b border-base-content/20 pb-6"
|
||||
>
|
||||
<h3 className="text-xl font-semibold">
|
||||
<a
|
||||
href={newsletter.url}
|
||||
className="hover:underline"
|
||||
>
|
||||
{newsletter.title}
|
||||
</a>
|
||||
</h3>
|
||||
|
||||
<p className="mt-2 text-base-content/70">
|
||||
{newsletter.description}
|
||||
</p>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("External newsletter feed failed:", error);
|
||||
|
||||
return (
|
||||
<p className="mt-12">
|
||||
This source is currently unavailable.
|
||||
</p>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
"use client";
|
||||
|
||||
import {Links} from "./navbarData";
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { useSession, signOut } from "next-auth/react";
|
||||
|
||||
export default function NavBar( { enforceAdmin } : { enforceAdmin: boolean; } ) {
|
||||
const pathname = usePathname();
|
||||
const { data: session} = useSession();
|
||||
const visibleLinks = Links.filter( // check each link
|
||||
(link) => (link.url !== "/dashboard" || session?.user) && (link.url !== "/users" || !enforceAdmin)
|
||||
// keep link if its not dashboard or if theres a session (logged in) (only keep dashboard if logged in)
|
||||
// and keep link if its not users or if enforceadmin is false
|
||||
);
|
||||
|
||||
return (
|
||||
<div 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 aria-label="Menu" 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">
|
||||
{visibleLinks.map((link) => ( // below highlights the active link
|
||||
<li className={pathname === link.url ? "menu-active" : ""} key={link.id}>
|
||||
<Link href={link.url}>{link.text}</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
<a className="btn btn-ghost text-xl">Secure CMS</a>
|
||||
</div>
|
||||
<div className="navbar-center hidden lg:flex">
|
||||
<ul className="menu menu-horizontal px-1">
|
||||
{visibleLinks.map((link) => (
|
||||
<li className={pathname === link.url ? "menu-active" : ""} key={link.id}>
|
||||
<Link href={link.url}>{link.text}</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
<div className="navbar-end gap-2">
|
||||
{session?.user ? (
|
||||
<>
|
||||
<span>{session.user.name || session.user.email || "Account"}</span>
|
||||
<button type="button" className="btn btn-ghost" onClick={() => signOut({ redirectTo: "/login" })}>
|
||||
Logout
|
||||
</button>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Link href="/login" className="btn btn-ghost">
|
||||
Login
|
||||
</Link>
|
||||
<Link href="/register" className="btn btn-primary">
|
||||
Sign Up
|
||||
</Link>
|
||||
</>
|
||||
)}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
"use client";
|
||||
|
||||
import { SessionProvider } from "next-auth/react";
|
||||
|
||||
export function Providers({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<SessionProvider>{children}</SessionProvider>
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
// surrounds page content to give children access to auth context and functions
|
||||
@@ -0,0 +1,28 @@
|
||||
interface Link {
|
||||
id: number;
|
||||
url: string;
|
||||
text: string;
|
||||
}
|
||||
|
||||
export const Links: Link[] = [
|
||||
{
|
||||
id: 1,
|
||||
url: "/",
|
||||
text: "Home",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
url: "/users",
|
||||
text: "Users",
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
url: "/dashboard",
|
||||
text: "Dashboard",
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
url: "/newsletters",
|
||||
text: "Newsletters",
|
||||
},
|
||||
]
|
||||
Reference in new issue
Block a user