Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

Fix 404 frfr (#1084)

Zach Lankton62c45df392fb
diff --git a/apps/web/src/app/[locale]/[...catchAll404]/page.tsx b/apps/web/src/app/[locale]/[...catchAll404]/page.tsx
deleted file mode 100644
index 252e0bac..00000000
--- a/apps/web/src/app/[locale]/[...catchAll404]/page.tsx
+++ /dev/null
@@ -1,6 +0,0 @@
-import { notFound } from 'next/navigation';
-import NotFound from '../not-found';
-
-export default function CatchAllPage() {
- return <NotFound />;
-}
diff --git a/apps/web/src/app/[locale]/layout.tsx b/apps/web/src/app/[locale]/layout.tsx
index 3ca073ef..95359f6e 100644
--- a/apps/web/src/app/[locale]/layout.tsx
+++ b/apps/web/src/app/[locale]/layout.tsx
@@ -1,58 +1,5 @@
-import { Analytics } from '@vercel/analytics/react';
-
-import '../../styles/globals.css';
-
-import { Toaster } from '@repo/ui/components/toaster';
-import { Inter } from 'next/font/google';
-import { Navigation } from '~/components/navigation';
-import { getStaticParams } from '~/locales/server';
-import { Providers } from './providers';
-
-import { OG_URL, tagline } from '../metadata';
-
-export const metadata = {
- metadataBase: new URL(OG_URL),
- title: 'TypeHero',
- robots: {
- index: true,
- follow: true,
- },
- description: tagline,
- openGraph: {
- title: 'TypeHero',
- description: tagline,
- siteName: 'TypeHero',
- images: [
- {
- url: `${OG_URL}/api/default`,
- width: 1920,
- height: 1080,
- },
- ],
- locale: 'en-US',
- type: 'website',
- },
- twitter: {
- title: 'TypeHero',
- card: 'summary_large_image',
- images: [
- {
- url: `${OG_URL}/api/default`,
- width: 1920,
- height: 1080,
- },
- ],
- },
- icons: {
- shortcut: '/favicon.ico',
- },
-};
-
-const inter = Inter({ subsets: ['latin'] });
-
-export function generateStaticParams() {
- return getStaticParams();
-}
+'use client';
+import { I18nProviderClient } from '~/locales/client';
export default function RootLayout({
children,
@@ -62,26 +9,10 @@ export default function RootLayout({
params: { locale: string };
}) {
return (
- <html suppressHydrationWarning lang="en">
- <head>
- <meta
- content="Level up your typescript skills with interactive exercises"
- name="description"
- />
- <link href="/favicon.svg" rel="icon" type="image/svg+xml" />
- <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
- <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
- <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
- <link rel="manifest" href="/site.webmanifest" />
- </head>
- <body className={`${inter.className} flex flex-col`}>
- <Providers locale={locale}>
- <Navigation />
- <main className="flex-1">{children}</main>
- <Toaster />
- </Providers>
- <Analytics />
- </body>
- </html>
+ <>
+ <I18nProviderClient locale={locale}>
+ <main className="flex-1">{children}</main>
+ </I18nProviderClient>
+ </>
);
}
diff --git a/apps/web/src/app/[locale]/not-found.tsx b/apps/web/src/app/[locale]/not-found.tsx
deleted file mode 100644
index fb4c6b1f..00000000
--- a/apps/web/src/app/[locale]/not-found.tsx
+++ /dev/null
@@ -1,65 +0,0 @@
-import Image from 'next/image';
-import { Button } from '@repo/ui/components/button';
-import { getRandomChallenge } from '~/utils/server/get-random-challenge';
-
-export default async function NotFound() {
- const randomChallengeSlug = await getRandomChallenge();
-
- return (
- <div className="relative -mt-[56px] flex h-screen flex-col items-center justify-center gap-8 overflow-hidden">
- <Image
- className="animate-amogfly absolute left-0 -z-10 mx-auto opacity-80"
- alt="Early Access"
- src="/Red.webp"
- height="99"
- width="75"
- />
- <Image
- className="th-amogfly absolute left-0 -z-10 mx-auto opacity-80"
- alt="Early Access"
- src="/typehero.png"
- height="99"
- width="99"
- />
- <div className="stars absolute -left-full -z-50 mt-[56px] h-screen w-[200%]" />
- <div className="stars absolute -left-full -z-40 mt-[56px] h-1/2 w-[400%] scale-[2]" />
- <div className="stars absolute -left-full -z-30 mt-[56px] h-1/3 w-[600%] scale-[3]" />
- <div className="flex flex-col items-center justify-center">
- <h1 className="mb-4 font-mono text-4xl font-bold leading-tight opacity-60 md:text-9xl">
- 404
- </h1>
- <p className="px-6 text-center font-mono text-base md:px-0 md:text-xl">
- {/* Looks Like You Took a Wrong Turn at the Interface. <br className="hidden md:inline" />
- Let's Get You Back on Track */}
- Page not found, sus
- </p>
- </div>
- {randomChallengeSlug !== null ? (
- <div className="flex flex-col gap-4">
- <a href="/explore">
- <Button className="w-56" variant="default" size="lg">
- Go to explore
- </Button>
- </a>
- <a href={`/challenge/${randomChallengeSlug}`}>
- <Button
- variant="outline"
- size="lg"
- className="fancy-border-gradient bg-background relative mx-auto flex w-56 gap-4 border-none"
- >
- I'm feeling lucky
- </Button>
- </a>
- </div>
- ) : (
- <div>
- <a href="/">
- <Button variant="default" size="lg">
- Go to home
- </Button>
- </a>
- </div>
- )}
- </div>
- );
-}
diff --git a/apps/web/src/app/[locale]/providers.tsx b/apps/web/src/app/[locale]/providers.tsx
index e8f500df..5e434201 100644
--- a/apps/web/src/app/[locale]/providers.tsx
+++ b/apps/web/src/app/[locale]/providers.tsx
@@ -12,13 +12,12 @@ import { FeatureFlagProvider } from '../feature-flag-provider';
import type { Corner } from '@tanstack/react-query-devtools/build/lib/utils';
interface Props {
- locale: string;
children: React.ReactNode;
}
const queryClient = new QueryClient();
-export function Providers({ locale, children }: Props) {
+export function Providers({ children }: Props) {
const position: Corner = 'bottom-right';
return (
<QueryClientProvider client={queryClient}>
@@ -26,9 +25,7 @@ export function Providers({ locale, children }: Props) {
<SessionProvider>
<ThemeProvider attribute="class">
<FeatureFlagProvider>
- <TooltipProvider>
- <I18nProviderClient locale={locale}>{children}</I18nProviderClient>
- </TooltipProvider>
+ <TooltipProvider>{children}</TooltipProvider>
</FeatureFlagProvider>
<Suspense>
<Toolbar />
diff --git a/apps/web/src/app/layout.tsx b/apps/web/src/app/layout.tsx
new file mode 100644
index 00000000..8669ee96
--- /dev/null
+++ b/apps/web/src/app/layout.tsx
@@ -0,0 +1,78 @@
+import { Toaster } from '@repo/ui/components/toaster';
+import { Analytics } from '@vercel/analytics/react';
+import { Inter } from 'next/font/google';
+import { Navigation } from '~/components/Navigation';
+import { getStaticParams } from '~/locales/server';
+import '../styles/globals.css';
+import { Providers } from './[locale]/providers';
+import { OG_URL, tagline } from './metadata';
+
+export function generateStaticParams() {
+ return getStaticParams();
+}
+
+const inter = Inter({ subsets: ['latin'] });
+
+export const metadata = {
+ metadataBase: new URL(OG_URL),
+ title: 'TypeHero',
+ robots: {
+ index: true,
+ follow: true,
+ },
+ description: tagline,
+ openGraph: {
+ title: 'TypeHero',
+ description: tagline,
+ siteName: 'TypeHero',
+ images: [
+ {
+ url: `${OG_URL}/api/default`,
+ width: 1920,
+ height: 1080,
+ },
+ ],
+ locale: 'en-US',
+ type: 'website',
+ },
+ twitter: {
+ title: 'TypeHero',
+ card: 'summary_large_image',
+ images: [
+ {
+ url: `${OG_URL}/api/default`,
+ width: 1920,
+ height: 1080,
+ },
+ ],
+ },
+ icons: {
+ shortcut: '/favicon.ico',
+ },
+};
+
+export default function RootLayout({ children }: { children: React.ReactNode }) {
+ return (
+ <html suppressHydrationWarning lang="en">
+ <head>
+ <meta
+ content="Level up your typescript skills with interactive exercises"
+ name="description"
+ />
+ <link href="/favicon.svg" rel="icon" type="image/svg+xml" />
+ <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
+ <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
+ <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
+ <link rel="manifest" href="/site.webmanifest" />
+ </head>
+ <body className={`${inter.className} flex flex-col`}>
+ <Providers>
+ <Navigation />
+ {children}
+ <Toaster />
+ </Providers>
+ <Analytics />
+ </body>
+ </html>
+ );
+}
diff --git a/apps/web/src/app/not-found.tsx b/apps/web/src/app/not-found.tsx
new file mode 100644
index 00000000..3c46995e
--- /dev/null
+++ b/apps/web/src/app/not-found.tsx
@@ -0,0 +1,72 @@
+import { Button } from '@repo/ui/components/button';
+import Image from 'next/image';
+import { getScopedI18n } from '~/locales/server';
+import { getRandomChallenge } from '~/utils/server/get-random-challenge';
+
+export const dynamic = 'force-dynamic';
+
+export default async function NotFound() {
+ const t = await getScopedI18n('404');
+
+ const randomChallengeSlug = await getRandomChallenge();
+
+ return (
+ <>
+ <div className="relative -mt-[56px] flex h-screen flex-col items-center justify-center gap-8 overflow-hidden">
+ <Image
+ className="animate-amogfly absolute left-0 -z-10 mx-auto opacity-80"
+ alt="Early Access"
+ src="/Red.webp"
+ height="99"
+ width="75"
+ />
+ <Image
+ className="th-amogfly absolute left-0 -z-10 mx-auto opacity-80"
+ alt="Early Access"
+ src="/typehero.png"
+ height="99"
+ width="99"
+ />
+ <div className="stars absolute -left-full -z-50 mt-[56px] h-screen w-[200%]" />
+ <div className="stars absolute -left-full -z-40 mt-[56px] h-1/2 w-[400%] scale-[2]" />
+ <div className="stars absolute -left-full -z-30 mt-[56px] h-1/3 w-[600%] scale-[3]" />
+ <div className="flex flex-col items-center justify-center">
+ <h1 className="mb-4 font-mono text-4xl font-bold leading-tight opacity-60 md:text-9xl">
+ 404
+ </h1>
+ <p className="px-6 text-center font-mono text-base md:px-0 md:text-xl">
+ {/* Looks Like You Took a Wrong Turn at the Interface. <br className="hidden md:inline" />
+ Let's Get You Back on Track */}
+ {t('message')}
+ </p>
+ </div>
+ {randomChallengeSlug !== null ? (
+ <div className="flex flex-col gap-4">
+ <a href="/explore">
+ <Button className="w-56" variant="default" size="lg">
+ Go to explore
+ </Button>
+ </a>
+ <a href={`/challenge/${randomChallengeSlug}`}>
+ <Button
+ variant="outline"
+ size="lg"
+ className="fancy-border-gradient bg-background relative mx-auto flex w-56 gap-4 border-none"
+ >
+ I'm feeling lucky
+ </Button>
+ </a>
+ </div>
+ ) : (
+ <div>
+ <a href="/">
+ <Button variant="default" size="lg">
+ Go to home
+ </Button>
+ </a>
+ </div>
+ )}
+ </div>
+ </>
+ );
+}
diff --git a/apps/web/src/components/Navigation/index.tsx b/apps/web/src/components/Navigation/index.tsx
new file mode 100644
index 00000000..c70ef76e
--- /dev/null
+++ b/apps/web/src/components/Navigation/index.tsx
@@ -0,0 +1,138 @@
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+} from '@repo/ui/components/dropdown-menu';
+import { Play, Settings, Settings2, User } from '@repo/ui/icons';
+import Link from 'next/link';
+import { isAdminOrModerator } from '~/utils/auth-guards';
+import { getAllFlags } from '~/utils/feature-flags';
+import { getServerAuthSession } from '@repo/auth/server';
+import { ThemeButton } from './theme-button';
+import { NavLink } from './nav-link';
+import { NavWrapper } from './nav-wrapper';
+import { LoginLink } from './login-link';
+import { SignOutLink } from './signout-link';
+import { getScopedI18n } from '~/locales/server';
+
+export function getAdminUrl() {
+ // reference for vercel.com
+ if (process.env.VERCEL_URL) {
+ return `https://admin.typehero.dev`;
+ }
+
+ // assume localhost
+ return `http://localhost:3001`;
+}
+
+export async function Navigation() {
+ const t = await getScopedI18n('navigation');
+ const featureFlags = await getAllFlags();
+
+ return (
+ <header className="z-50 w-full">
+ <NavWrapper>
+ <div className="flex w-full items-center justify-between">
+ <div className="relative flex items-center gap-3">
+ <Link
+ className="flex items-center space-x-1.5 focus:outline-none focus-visible:ring-2"
+ href="/"
+ >
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ className="h-6 w-6"
+ viewBox="0 0 38 38"
+ fill="none"
+ >
+ <rect width="38" height="38" rx="4.5" fill="#3178C6" />
+ <path
+ fillRule="evenodd"
+ clipRule="evenodd"
+ d="M15.6947 20.9344H20V18H8V20.9344H12.2842V34H15.6947V20.9344Z"
+ fill="white"
+ />
+ <path
+ d="M22 34V18H25.4511V24.6309H30.5405V18H34V34H30.5405V27.3458H25.4511V34H22Z"
+ fill="white"
+ />
+ </svg>
+
+ <span className="font-bold leading-3">
+ type
+ <br />
+ hero
+ </span>
+ </Link>
+ {featureFlags?.enableExplore ? <NavLink title={t('explore')} href="/explore" /> : null}
+ {featureFlags?.enableTracks ? <NavLink title={t('tracks')} href="/tracks" /> : null}
+ </div>
+ <div className="flex">
+ <div className="flex items-center justify-end gap-2">
+ <ThemeButton />
+ {featureFlags?.enableLogin ? <LoginButton /> : null}
+ </div>
+ </div>
+ </div>
+ </NavWrapper>
+ </header>
+ );
+}
+
+async function LoginButton() {
+ const session = await getServerAuthSession();
+
+ const isAdminOrMod = isAdminOrModerator(session);
+
+ return session ? (
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <button
+ aria-label="profile button"
+ className="focus:bg-accent rounded-lg p-2 duration-300 focus:outline-none focus-visible:ring-2"
+ >
+ <User className="h-5 w-5" />
+ </button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent
+ align="end"
+ className="mt-[0.33rem] w-56 rounded-xl bg-white/50 backdrop-blur-sm dark:bg-neutral-950/50"
+ >
+ <Link className="block" href={`/@${session.user.name}`}>
+ <DropdownMenuItem className="focus:bg-accent rounded-lg p-2 duration-300 focus:outline-none dark:hover:bg-neutral-700/50">
+ <User className="mr-2 h-4 w-4" />
+ <span>Profile</span>
+ </DropdownMenuItem>
+ </Link>
+ <Link className="block" href="/settings">
+ <DropdownMenuItem className="focus:bg-accent rounded-lg p-2 duration-300 focus:outline-none">
+ <Settings2 className="mr-2 h-4 w-4" />
+ <span>Settings</span>
+ </DropdownMenuItem>
+ </Link>
+ {isAdminOrMod ? (
+ <a className="block" href={getAdminUrl()}>
+ <DropdownMenuItem className="focus:bg-accent rounded-lg p-2 duration-300 focus:outline-none dark:hover:bg-neutral-700/50">
+ <Settings className="mr-2 h-4 w-4" />
+ <span>Admin</span>
+ </DropdownMenuItem>
+ </a>
+ ) : null}
+ {isAdminOrMod ? (
+ <a className="block" href="/challenge-playground">
+ <DropdownMenuItem className="focus:bg-accent rounded-lg p-2 duration-300 focus:outline-none dark:hover:bg-neutral-700/50">
+ <Play className="mr-2 h-4 w-4" />
+ <span>Challenge Playground</span>
+ </DropdownMenuItem>
+ </a>
+ ) : null}
+ <DropdownMenuSeparator />
+
+ <SignOutLink />
+ </DropdownMenuContent>
+ </DropdownMenu>
+ ) : (
+ <LoginLink />
+ );
+}
diff --git a/apps/web/src/components/Navigation/login-link.tsx b/apps/web/src/components/Navigation/login-link.tsx
new file mode 100644
index 00000000..acebb2c9
--- /dev/null
+++ b/apps/web/src/components/Navigation/login-link.tsx
@@ -0,0 +1,29 @@
+'use client';
+import { LogIn } from '@repo/ui/icons';
+import Link from 'next/link';
+import { usePathname } from 'next/navigation';
+
+const BLACKLISTED_LOGIN_REDIRECT_PATHS = ['/', '/login'];
+
+export function LoginLink() {
+ const pathname = usePathname();
+ const isBlacklistedPath = BLACKLISTED_LOGIN_REDIRECT_PATHS.some((blacklistedPath) => {
+ return blacklistedPath === pathname;
+ });
+ return (
+ <Link
+ className="focus:bg-accent w-20 rounded-lg bg-transparent p-2 text-black duration-300 hover:bg-gray-200 focus:outline-none dark:text-white hover:dark:bg-gray-800"
+ href={{
+ pathname: '/login',
+ query: {
+ ...(!isBlacklistedPath && { redirectTo: pathname }),
+ },
+ }}
+ >
+ <div className="flex items-center space-x-2">
+ <LogIn className="h-5 w-5" />
+ <span className="dark:text-white">Login</span>
+ </div>
+ </Link>
+ );
+}
diff --git a/apps/web/src/components/Navigation/nav-link.tsx b/apps/web/src/components/Navigation/nav-link.tsx
new file mode 100644
index 00000000..6bc752eb
--- /dev/null
+++ b/apps/web/src/components/Navigation/nav-link.tsx
@@ -0,0 +1,19 @@
+'use client';
+import clsx from 'clsx';
+import Link from 'next/link';
+import { usePathname } from 'next/navigation';
+
+export function NavLink({ href, title }: { href: string; title: string }) {
+ const pathname = usePathname();
+ return (
+ <Link href={href} className="ml-4">
+ <div
+ className={clsx('hover:text-foreground text-foreground/80 transition-colors', {
+ '!text-foreground': pathname === href,
+ })}
+ >
+ {title}
+ </div>
+ </Link>
+ );
+}
diff --git a/apps/web/src/components/Navigation/nav-wrapper.tsx b/apps/web/src/components/Navigation/nav-wrapper.tsx
new file mode 100644
index 00000000..3f14fefa
--- /dev/null
+++ b/apps/web/src/components/Navigation/nav-wrapper.tsx
@@ -0,0 +1,21 @@
+'use client';
+
+import { usePathname } from 'next/navigation';
+import { useFullscreenSettingsStore } from '~/app/[locale]/challenge/_components/fullscreen';
+
+export function NavWrapper({ children }: { children: React.ReactNode }) {
+ const { fssettings } = useFullscreenSettingsStore();
+ const pathname = usePathname();
+
+ if (fssettings.isFullscreen) return <></>;
+
+ return (
+ <nav
+ className={`flex h-14 items-center text-sm font-medium ${
+ pathname?.startsWith('/challenge') ? 'px-4' : 'container'
+ }`}
+ >
+ {children}
+ </nav>
+ );
+}
diff --git a/apps/web/src/components/Navigation/signout-link.tsx b/apps/web/src/components/Navigation/signout-link.tsx
new file mode 100644
index 00000000..657259b5
--- /dev/null
+++ b/apps/web/src/components/Navigation/signout-link.tsx
@@ -0,0 +1,22 @@
+'use client';
+import { signOut } from '@repo/auth/react';
+import { Button } from '@repo/ui/components/button';
+import { useRouter } from 'next/navigation';
+
+export function SignOutLink() {
+ const router = useRouter();
+
+ const handleSignOut = async () => {
+ await signOut({ redirect: false });
+ router.refresh();
+ };
+ return (
+ <Button
+ className="h-8 w-full justify-start rounded-b-lg rounded-t-sm bg-opacity-50 px-2 text-red-500 hover:bg-red-500/20 hover:text-red-500"
+ onClick={handleSignOut}
+ variant="ghost"
+ >
+ <span className="text-red-500">Log out</span>
+ </Button>
+ );
+}
diff --git a/apps/web/src/components/Navigation/theme-button.tsx b/apps/web/src/components/Navigation/theme-button.tsx
new file mode 100644
index 00000000..3af19f42
--- /dev/null
+++ b/apps/web/src/components/Navigation/theme-button.tsx
@@ -0,0 +1,31 @@
+'use client';
+import { useEffect, useState } from 'react';
+import { useTheme } from 'next-themes';
+import { Moon, Sun } from '@repo/ui/icons';
+
+export function ThemeButton() {
+ const [mounted, setMounted] = useState(false);
+ const { setTheme, resolvedTheme } = useTheme();
+
+ useEffect(() => {
+ setMounted(true);
+ }, []);
+
+ return (
+ <>
+ {mounted ? (
+ <button
+ aria-label="theme button"
+ className="focus:bg-accent rounded-lg p-2 duration-300 focus:outline-none focus-visible:ring-2"
+ onClick={() => {
+ setTheme(resolvedTheme === 'dark' ? 'light' : 'dark');
+ }}
+ type="button"
+ >
+ {resolvedTheme === 'dark' && <Moon aria-hidden="true" className="h-5 w-5" />}
+ {resolvedTheme === 'light' && <Sun aria-hidden="true" className="h-5 w-5" />}
+ </button>
+ ) : null}
+ </>
+ );
+}
diff --git a/apps/web/src/components/navigation.tsx b/apps/web/src/components/navigation.tsx
deleted file mode 100644
index bb1b56d0..00000000
--- a/apps/web/src/components/navigation.tsx
+++ /dev/null
@@ -1,229 +0,0 @@
-'use client';
-
-import { signOut, useSession } from '@repo/auth/react';
-import { Button } from '@repo/ui/components/button';
-import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuSeparator,
- DropdownMenuTrigger,
-} from '@repo/ui/components/dropdown-menu';
-import { Loader2, LogIn, Moon, Play, Settings, Settings2, Sun, User } from '@repo/ui/icons';
-import clsx from 'clsx';
-import { useTheme } from 'next-themes';
-import Link from 'next/link';
-import { usePathname, useRouter } from 'next/navigation';
-import { useContext, useEffect, useState } from 'react';
-import { useFullscreenSettingsStore } from '~/app/[locale]/challenge/_components/fullscreen';
-import { FeatureFlagContext } from '~/app/feature-flag-provider';
-import { isAdminOrModerator } from '~/utils/auth-guards';
-
-export function getAdminUrl() {
- // reference for vercel.com
- if (process.env.VERCEL_URL) {
- return `https://admin.typehero.dev`;
- }
-
- // assume localhost
- return `http://localhost:3001`;
-}
-
-export function Navigation() {
- const { fssettings } = useFullscreenSettingsStore();
- const pathname = usePathname();
- const featureFlags = useContext(FeatureFlagContext);
-
- return (
- <header className="z-50 w-full">
- {!fssettings.isFullscreen && (
- <nav
- className={`flex h-14 items-center text-sm font-medium ${
- pathname?.startsWith('/challenge') ? 'px-4' : 'container'
- }`}
- >
- <div className="flex w-full items-center justify-between">
- <div className="relative flex items-center gap-3">
- <Link
- className="flex items-center space-x-1.5 focus:outline-none focus-visible:ring-2"
- href="/"
- >
- <svg
- xmlns="http://www.w3.org/2000/svg"
- className="h-6 w-6"
- viewBox="0 0 38 38"
- fill="none"
- >
- <rect width="38" height="38" rx="4.5" fill="#3178C6" />
- <path
- fillRule="evenodd"
- clipRule="evenodd"
- d="M15.6947 20.9344H20V18H8V20.9344H12.2842V34H15.6947V20.9344Z"
- fill="white"
- />
- <path
- d="M22 34V18H25.4511V24.6309H30.5405V18H34V34H30.5405V27.3458H25.4511V34H22Z"
- fill="white"
- />
- </svg>
-
- <span className="font-bold leading-3">
- type
- <br />
- hero
- </span>
- </Link>
- {featureFlags?.enableExplore ? (
- <Link href="/explore" className="ml-4">
- <div
- className={clsx('hover:text-foreground text-foreground/80 transition-colors', {
- '!text-foreground': pathname === '/explore',
- })}
- >
- Explore
- </div>
- </Link>
- ) : null}
- {featureFlags?.enableTracks ? (
- <Link href="/tracks" className="ml-4">
- <div
- className={clsx('hover:text-foreground text-foreground/80 transition-colors', {
- '!text-foreground': pathname === '/tracks',
- })}
- >
- Tracks
- </div>
- </Link>
- ) : null}
- </div>
- <div className="flex">
- <div className="flex items-center justify-end gap-2">
- <ThemeButton />
- {featureFlags?.enableLogin ? <LoginButton /> : null}
- </div>
- </div>
- </div>
- </nav>
- )}
- </header>
- );
-}
-
-function ThemeButton() {
- const [mounted, setMounted] = useState(false);
- const { setTheme, resolvedTheme } = useTheme();
-
- useEffect(() => {
- setMounted(true);
- }, []);
-
- return (
- <>
- {mounted ? (
- <button
- aria-label="theme button"
- className="focus:bg-accent rounded-lg p-2 duration-300 focus:outline-none focus-visible:ring-2"
- onClick={() => {
- setTheme(resolvedTheme === 'dark' ? 'light' : 'dark');
- }}
- type="button"
- >
- {resolvedTheme === 'dark' && <Moon aria-hidden="true" className="h-5 w-5" />}
- {resolvedTheme === 'light' && <Sun aria-hidden="true" className="h-5 w-5" />}
- </button>
- ) : null}
- </>
- );
-}
-
-const BLACKLISTED_LOGIN_REDIRECT_PATHS = ['/', '/login'];
-
-function LoginButton() {
- const { data: session, status } = useSession();
- const router = useRouter();
- const pathname = usePathname();
-
- const isAdminOrMod = isAdminOrModerator(session);
-
- const handleSignOut = async () => {
- await signOut({ redirect: false });
- router.refresh();
- };
-
- const isBlacklistedPath = BLACKLISTED_LOGIN_REDIRECT_PATHS.some((blacklistedPath) => {
- return blacklistedPath === pathname;
- });
-
- return session ? (
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <button
- aria-label="profile button"
- className="focus:bg-accent rounded-lg p-2 duration-300 focus:outline-none focus-visible:ring-2"
- >
- <User className="h-5 w-5" />
- </button>
- </DropdownMenuTrigger>
- <DropdownMenuContent
- align="end"
- className="mt-[0.33rem] w-56 rounded-xl bg-white/50 backdrop-blur-sm dark:bg-neutral-950/50"
- >
- <Link className="block" href={`/@${session.user.name}`}>
- <DropdownMenuItem className="focus:bg-accent rounded-lg p-2 duration-300 focus:outline-none dark:hover:bg-neutral-700/50">
- <User className="mr-2 h-4 w-4" />
- <span>Profile</span>
- </DropdownMenuItem>
- </Link>
- <Link className="block" href="/settings">
- <DropdownMenuItem className="focus:bg-accent rounded-lg p-2 duration-300 focus:outline-none">
- <Settings2 className="mr-2 h-4 w-4" />
- <span>Settings</span>
- </DropdownMenuItem>
- </Link>
- {isAdminOrMod ? (
- <a className="block" href={getAdminUrl()}>
- <DropdownMenuItem className="focus:bg-accent rounded-lg p-2 duration-300 focus:outline-none dark:hover:bg-neutral-700/50">
- <Settings className="mr-2 h-4 w-4" />
- <span>Admin</span>
- </DropdownMenuItem>
- </a>
- ) : null}
- {isAdminOrMod ? (
- <a className="block" href="/challenge-playground">
- <DropdownMenuItem className="focus:bg-accent rounded-lg p-2 duration-300 focus:outline-none dark:hover:bg-neutral-700/50">
- <Play className="mr-2 h-4 w-4" />
- <span>Challenge Playground</span>
- </DropdownMenuItem>
- </a>
- ) : null}
- <DropdownMenuSeparator />
- <Button
- className="h-8 w-full justify-start rounded-b-lg rounded-t-sm bg-opacity-50 px-2 text-red-500 hover:bg-red-500/20 hover:text-red-500"
- onClick={handleSignOut}
- variant="ghost"
- >
- <span className="text-red-500">Log out</span>
- </Button>
- </DropdownMenuContent>
- </DropdownMenu>
- ) : (
- <Link
- className="focus:bg-accent w-20 rounded-lg bg-transparent p-2 text-black duration-300 hover:bg-gray-200 focus:outline-none dark:text-white hover:dark:bg-gray-800"
- href={{
- pathname: '/login',
- query: {
- ...(!isBlacklistedPath && { redirectTo: pathname }),
- },
- }}
- >
- {status === 'loading' ? (
- <Loader2 className="h-5 w-5 animate-spin" />
- ) : (
- <div className="flex items-center space-x-2">
- <LogIn className="h-5 w-5" />
- <span className="dark:text-white">Login</span>
- </div>
- )}
- </Link>
- );
-}
diff --git a/apps/web/src/locales/en.ts b/apps/web/src/locales/en.ts
index 36dee81a..45a2140b 100644
--- a/apps/web/src/locales/en.ts
+++ b/apps/web/src/locales/en.ts
@@ -2,4 +2,7 @@ export default {
'landing.hero.description':
'Connect, collaborate, and grow with a community of TypeScript developers. Elevate your skills through interactive coding challenges, discussions, and knowledge sharing',
'landing.hero.buttons.waitlist': 'Join the waitlist',
+ '404.message': 'Page not found, sus',
+ 'navigation.explore': 'Explore',
+ 'navigation.tracks': 'Tracks',
} as const;