Connect, collaborate, and grow with a community of TypeScript developers
feat: Explore drawer panel (#1354)
Fahad97fb325d929e
diff --git a/apps/web/src/app/[locale]/challenge/[slug]/getChallengeRouteData.ts b/apps/web/src/app/[locale]/challenge/[slug]/getChallengeRouteData.tsindex 67c9d1f2..49e2cd3b 100644--- a/apps/web/src/app/[locale]/challenge/[slug]/getChallengeRouteData.ts+++ b/apps/web/src/app/[locale]/challenge/[slug]/getChallengeRouteData.ts@@ -83,3 +83,62 @@ export const getChallengeRouteData = cache(async (slug: string, session: Sessiontrack,};});+export const getCurrentChallenge = cache(async (slug: string, session: Session | null) => {+ return prisma.challenge.findFirstOrThrow({+ where: {+ slug,+ status: 'ACTIVE',+ },+ include: {+ user: {+ select: {+ name: true,+ },+ },+ _count: {+ select: {+ vote: true,+ },+ },+ vote: {+ where: {+ userId: session?.user?.id || '',+ },+ },+ bookmark: {+ where: {+ userId: session?.user?.id || '',+ },+ },+ submission: {+ where: {+ userId: session?.user?.id || '',+ isSuccessful: true,+ },+ take: 1,+ },+ },+ });+});++export type GetCurrentChallengeType = Awaited<ReturnType<typeof getCurrentChallenge>>;++export const isEnrolledInAnyTrack = cache(async (session: Session | null) => {+ if (!session) {+ return false;+ }+ const userWithTrackCount = await prisma.user.findUnique({+ where: { id: session?.user?.id },+ select: {+ _count: {+ select: { tracks: true },+ },+ },+ });++ const numberOfTrack = userWithTrackCount?._count.tracks;+ if (!numberOfTrack) {+ return false;+ }+ return true;+});diff --git a/apps/web/src/app/[locale]/challenge/[slug]/left-wrapper.tsx b/apps/web/src/app/[locale]/challenge/[slug]/left-wrapper.tsxindex 71798052..bdedbe88 100644--- a/apps/web/src/app/[locale]/challenge/[slug]/left-wrapper.tsx+++ b/apps/web/src/app/[locale]/challenge/[slug]/left-wrapper.tsx@@ -13,6 +13,8 @@ import { FlaskConical, History, Text } from '@repo/ui/icons';import { AOT_CHALLENGES } from './aot-slugs';import type { ChallengeRouteData } from './getChallengeRouteData';import { useTrackNavigationVisiblity } from './use-track-visibility.hook';+import { ProblemExplorerTrackNav } from '~/components/Navigation/problem-explorer-track-nav';+import { useProblemExplorerContext } from '~/app/problem-explorer.hooks';type Tab = 'description' | 'solutions' | 'submissions';interface Props {@@ -27,6 +29,7 @@ export function LeftWrapper({ children, challenge, track, expandPanel, isDesktopconst pathname = usePathname();const router = useRouter();const [isCollapsed, setIsCollapsed] = useState(false);+ const { isExplorerDisabled } = useProblemExplorerContext();const featureFlags = useContext(FeatureFlagContext);@@ -97,11 +100,7 @@ export function LeftWrapper({ children, challenge, track, expandPanel, isDesktop// Hide the enrolled track when in collapsed mobile view.const isTrackFeatureEnabled = featureFlags?.enableInChallengeTrack;const hasEnrolledTrackForChallenge = track !== null;- const isTrackVisible =- isTrackFeatureEnabled &&- hasEnrolledTrackForChallenge &&- (!isCollapsed || isDesktop) &&- !isAotChallenge;+ const isTrackVisible = isTrackFeatureEnabled && (!isCollapsed || isDesktop) && !isAotChallenge;const isIconOnly = isCollapsed && isDesktop;const { setIsTrackTitleVisible } = useTrackNavigationVisiblity();@@ -112,7 +111,7 @@ export function LeftWrapper({ children, challenge, track, expandPanel, isDesktopreturn (<div className="flex h-full w-full flex-col">- {Boolean(isTrackVisible) && (+ {Boolean(isTrackVisible && hasEnrolledTrackForChallenge) && (<ChallengeTrackNavigationchallenge={challenge}track={track}@@ -120,6 +119,13 @@ export function LeftWrapper({ children, challenge, track, expandPanel, isDesktopclassName={cn('border-b border-zinc-300 p-1 dark:border-zinc-700')}/>)}++ {Boolean(isTrackVisible && !hasEnrolledTrackForChallenge && !isExplorerDisabled) && (+ <ProblemExplorerTrackNav+ isCollapsed={isCollapsed}+ className={cn('border-b border-zinc-300 p-1 dark:border-zinc-700')}+ />+ )}<Tabsref={tabsRef}className="flex h-full w-full flex-col overflow-hidden"diff --git a/apps/web/src/app/[locale]/challenge/_components/challenge-layout-wrapper.tsx b/apps/web/src/app/[locale]/challenge/_components/challenge-layout-wrapper.tsxindex ff50ae41..6f8ba15b 100644--- a/apps/web/src/app/[locale]/challenge/_components/challenge-layout-wrapper.tsx+++ b/apps/web/src/app/[locale]/challenge/_components/challenge-layout-wrapper.tsx@@ -1,10 +1,11 @@'use client';-import { useState, type ReactNode } from 'react';+import { useState, type ReactNode, useEffect } from 'react';import type { ChallengeRouteData } from '../[slug]/getChallengeRouteData';import { ChallengeLayout, MOBILE_BREAKPOINT } from './challenge-layout';import usePanelAdjustments from './usePanelAdjustments';import { LeftWrapper } from '../[slug]/left-wrapper';import { Wrapper } from '../[slug]/wrapper';+import { useChallengeRouteData } from '~/app/challenge-route-data.hook';interface Props {challenge: ChallengeRouteData['challenge'];@@ -13,6 +14,12 @@ interface Props {}export function ChallengeLayoutWrapper({ challenge, track, children }: Props) {+ const { setCurrentChallenge } = useChallengeRouteData();++ useEffect(() => {+ setCurrentChallenge(challenge);+ }, [challenge, setCurrentChallenge]);+const [isDesktop, setIsDesktop] = useState(window.innerWidth > MOBILE_BREAKPOINT);const LEFT_PANEL_BREAKPOINT = isDesktop ? 500 : 318;const DEFAULT_DESKTOP_WIDTH_PX = `${LEFT_PANEL_BREAKPOINT}px`;diff --git a/apps/web/src/app/[locale]/challenge/_components/explore-drawer.tsx b/apps/web/src/app/[locale]/challenge/_components/explore-drawer.tsxnew file mode 100644index 00000000..12dd8e6d--- /dev/null+++ b/apps/web/src/app/[locale]/challenge/_components/explore-drawer.tsx@@ -0,0 +1,22 @@+import { Sheet, SheetContent, SheetTrigger } from '@repo/ui/components/sheet';+import { ExplorerPanel } from './sheet-content-custom';+import type { ReactNode } from 'react';++interface Props {+ children: ReactNode;+ asChild?: boolean;+}++export function ExploreDrawer({ children, asChild = false }: Props) {+ return (+ <Sheet>+ <SheetTrigger asChild={asChild}>{children}</SheetTrigger>+ <SheetContent+ className="flex w-full flex-col gap-8 overflow-y-scroll sm:max-w-[400px] md:max-w-[540px]"+ side="left"+ >+ <ExplorerPanel />+ </SheetContent>+ </Sheet>+ );+}diff --git a/apps/web/src/app/[locale]/challenge/_components/select-dropdown.tsx b/apps/web/src/app/[locale]/challenge/_components/select-dropdown.tsxnew file mode 100644index 00000000..3ef15903--- /dev/null+++ b/apps/web/src/app/[locale]/challenge/_components/select-dropdown.tsx@@ -0,0 +1,33 @@+import {+ Select,+ SelectContent,+ SelectGroup,+ SelectItem,+ SelectLabel,+ SelectTrigger,+ SelectValue,+} from '@repo/ui/components/select';+import { SORT_KEYS, type SortKeyType } from '~/app/get-challenges-and-title';++export interface SelectDropdownProps {+ sortKey: SortKeyType;+ handleValueChange: (value: string) => void;+}++export const SelectDropdown = ({ sortKey, handleValueChange }: SelectDropdownProps) => (+ <Select defaultValue={sortKey.value} onValueChange={handleValueChange}>+ <SelectTrigger className="w-[190px]">+ <SelectValue placeholder="Select Challenges" />+ </SelectTrigger>+ <SelectContent>+ <SelectGroup>+ <SelectLabel>Select Track</SelectLabel>+ {SORT_KEYS.map((sortKey, index) => (+ <SelectItem key={index} value={sortKey.value}>+ {sortKey.label} Challenges+ </SelectItem>+ ))}+ </SelectGroup>+ </SelectContent>+ </Select>+);diff --git a/apps/web/src/app/[locale]/challenge/_components/sheet-content-custom.tsx b/apps/web/src/app/[locale]/challenge/_components/sheet-content-custom.tsxnew file mode 100644index 00000000..4662aaaf--- /dev/null+++ b/apps/web/src/app/[locale]/challenge/_components/sheet-content-custom.tsx@@ -0,0 +1,99 @@+import { SheetHeader, SheetTitle } from '@repo/ui/components/sheet';+import Link from 'next/link';+import { ChevronRight } from '@repo/ui/icons';+import { TrackChallenge } from '../../tracks/_components/track-challenge-card';+import { TrackProgress } from '../../tracks/_components/track-progress';+import { SelectDropdown } from './select-dropdown';+import { useChallengeRouteData } from '~/app/challenge-route-data.hook';+import { useProblemExplorerContext } from '~/app/problem-explorer.hooks';+import { useAllChallengesContext } from '~/app/all-challenges.hook';+import { useLocalStorage } from '~/utils/useLocalStorage';+import { getChallengesAndTitle, type ChallengeType } from '~/app/get-challenges-and-title';+import { useMemo } from 'react';++export function ExplorerPanel() {+ const [, setTrackNameStorage] = useLocalStorage('trackName', 'popular');+ const { getTrack, setTrack, title, setTitle, sortKey, setSortKey } = useProblemExplorerContext();+ const { allChallenges } = useAllChallengesContext();++ const handleValueChange = (value: string) => {+ const { title, challenges, key } = getChallengesAndTitle(value as ChallengeType, allChallenges);+ setTitle(title);+ setTrack(challenges);+ setTrackNameStorage(value);+ setSortKey(key);+ };++ const { currentChallenge } = useChallengeRouteData();++ const challenges = getTrack;+ const completedChallenges = useMemo(+ () =>+ challenges+ .filter((challenge) => {+ return (+ challenge.submission.length &&+ challenge.submission.some((submission) => submission.isSuccessful)+ );+ })+ .map((challenge) => challenge.id),+ [challenges],+ );++ const inProgressChallenges = useMemo(+ () =>+ challenges+ .filter((challenge) => {+ return (+ challenge.submission.length &&+ challenge.submission.every((submission) => !submission.isSuccessful)+ );+ })+ .map((challenge) => challenge.id),+ [challenges],+ );+ return (+ <>+ <SheetHeader>+ <SheetTitle>+ <Link+ href="/explore"+ className="text-foreground flex max-w-full items-center justify-start gap-4 text-xl font-semibold"+ >+ <span className="overflow-hidden text-ellipsis whitespace-nowrap">+ Explore all challenges+ </span>+ <ChevronRight className="mt-0.5 h-6 w-6 shrink-0" />+ </Link>+ <div className="mt-8 flex items-start justify-between gap-4 text-lg">+ <div>{title}</div>+ <div className="text-sm">+ <SelectDropdown sortKey={sortKey} handleValueChange={handleValueChange} />+ </div>+ </div>+ </SheetTitle>+ </SheetHeader>+ {sortKey.value !== 'popular' ? (+ <TrackProgress+ completedChallenges={completedChallenges.length}+ totalChallenges={challenges.length}+ />+ ) : null}+ <div className="flex flex-col">+ {challenges.map((challenge) => {+ return (+ <Link key={challenge.id} href={`/challenge/${challenge.slug}`}>+ <TrackChallenge+ challenge={challenge}+ isCompleted={completedChallenges.includes(challenge.id)}+ isInProgress={inProgressChallenges.includes(challenge.id)}+ isSelected={challenge.id === currentChallenge?.id}+ isCompact+ />+ </Link>+ );+ })}+ </div>+ </>+ );+}diff --git a/apps/web/src/app/[locale]/context-providers.tsx b/apps/web/src/app/[locale]/context-providers.tsxnew file mode 100644index 00000000..c090298f--- /dev/null+++ b/apps/web/src/app/[locale]/context-providers.tsx@@ -0,0 +1,24 @@+import React from 'react';+import { ChallegeRouteDataProvider } from '../challenge-route-data.hook';+import { ProblemExplorerProvider } from '../problem-explorer.hooks';+import { AllChallengesProvider } from '../all-challenges.hook';+import { getAllChallenges } from './explore/_components/explore.action';+import { auth } from '@repo/auth/server';+import { isEnrolledInAnyTrack } from './challenge/[slug]/getChallengeRouteData';++interface Props {+ children: React.ReactNode;+}++export async function ContextProviders({ children }: Props) {+ const allChallenges = await getAllChallenges();+ const session = await auth();+ const isExplorerDisabled = await isEnrolledInAnyTrack(session);+ return (+ <AllChallengesProvider AC={allChallenges}>+ <ProblemExplorerProvider isDisabled={isExplorerDisabled} AC={allChallenges}>+ <ChallegeRouteDataProvider>{children}</ChallegeRouteDataProvider>+ </ProblemExplorerProvider>+ </AllChallengesProvider>+ );+}diff --git a/apps/web/src/app/[locale]/explore/_components/explore.action.ts b/apps/web/src/app/[locale]/explore/_components/explore.action.tsindex 76372bfd..51b6a020 100644--- a/apps/web/src/app/[locale]/explore/_components/explore.action.ts+++ b/apps/web/src/app/[locale]/explore/_components/explore.action.ts@@ -58,6 +58,9 @@ export async function getChallengesByTagOrDifficulty(str: string, take?: number)}),});}+export type ChallengesByTagOrDifficulty = Awaited<+ ReturnType<typeof getChallengesByTagOrDifficulty>+>;/*** Fetches the length of how many challenges are in a@@ -79,3 +82,31 @@ export const getExploreChallengesLengthByTagOrDifficulty = cache((str: string) =},});});++export const getAllChallenges = cache(async () => {+ const popularChallenges = await getChallengesByTagOrDifficulty('popular', 12);+ const beginnerChallenges = await getChallengesByTagOrDifficulty('beginner');+ const easyChallenges = await getChallengesByTagOrDifficulty('easy');+ const mediumChallenges = await getChallengesByTagOrDifficulty('medium');+ const hardChallenges = await getChallengesByTagOrDifficulty('hard');+ const extremeChallenges = await getChallengesByTagOrDifficulty('extreme');++ const allChallenges: AllChallenges = {+ popularChallenges,+ beginnerChallenges,+ easyChallenges,+ mediumChallenges,+ hardChallenges,+ extremeChallenges,+ };+ return allChallenges;+});++export interface AllChallenges {+ popularChallenges: ChallengesByTagOrDifficulty;+ beginnerChallenges: ChallengesByTagOrDifficulty;+ easyChallenges: ChallengesByTagOrDifficulty;+ mediumChallenges: ChallengesByTagOrDifficulty;+ hardChallenges: ChallengesByTagOrDifficulty;+ extremeChallenges: ChallengesByTagOrDifficulty;+}diff --git a/apps/web/src/app/[locale]/tracks/_components/enroll-button.tsx b/apps/web/src/app/[locale]/tracks/_components/enroll-button.tsxindex 6ff28cb0..11022df8 100644--- a/apps/web/src/app/[locale]/tracks/_components/enroll-button.tsx+++ b/apps/web/src/app/[locale]/tracks/_components/enroll-button.tsx@@ -4,6 +4,7 @@ import { Button } from '@repo/ui/components/button';import { toast } from '@repo/ui/components/use-toast';import { useState } from 'react';import type { enrollUserInTrack, unenrollUserFromTrack } from './track.action';+import { useProblemExplorerContext } from '~/app/problem-explorer.hooks';interface EnrollButtonProps {action: typeof enrollUserInTrack | typeof unenrollUserFromTrack;@@ -14,12 +15,15 @@ interface EnrollButtonProps {export function ActionButton({ action, text, trackId, slug }: EnrollButtonProps) {const [isLoading, setIsLoading] = useState(false);+ const { setIsExplorerDisabled } = useProblemExplorerContext();return (<ButtonclassName="shadcnoverridetransition select-none rounded-3xl bg-black text-white shadow-[0px_16px_6px_-16px_#ff4,4px_2px_4px_-2px_#f4f,-4px_2px_4px_-2px_#4f4] hover:-translate-y-1 hover:bg-neutral-800 hover:shadow-[0px_16px_6px_-12px_#ff4,4px_6px_6px_-2px_#f4f,-4px_6px_6px_-2px_#4f4] active:translate-y-0 active:scale-[0.99] active:shadow-[0px_10px_3px_-16px_#ff4,8px_0px_2px_-2px_#f4f,-8px_0px_2px_-2px_#4f4] dark:bg-white dark:text-black dark:hover:bg-white dark:hover:brightness-125 dark:hover:saturate-150"disabled={isLoading}onClick={async () => {setIsLoading(true);+ setIsExplorerDisabled(text === 'Enroll');+try {await action(trackId, slug);toast({diff --git a/apps/web/src/app/all-challenges.hook.tsx b/apps/web/src/app/all-challenges.hook.tsxnew file mode 100644index 00000000..569622ad--- /dev/null+++ b/apps/web/src/app/all-challenges.hook.tsx@@ -0,0 +1,34 @@+'use client';+import { createContext, useState, useContext } from 'react';+import { type AllChallenges } from './[locale]/explore/_components/explore.action';++interface AllChallengesContextType {+ allChallenges: AllChallenges;+ setAllChallenges: React.Dispatch<React.SetStateAction<AllChallenges>>;+}++export const AllChallengesContext = createContext<AllChallengesContextType>(+ {} as AllChallengesContextType,+);++interface AllChallengesProviderProps {+ children: React.ReactNode;+ AC: AllChallenges;+}+export const AllChallengesProvider = ({ children, AC }: AllChallengesProviderProps) => {+ const [allChallenges, setAllChallenges] = useState<AllChallenges>(AC);++ return (+ <AllChallengesContext.Provider value={{ allChallenges, setAllChallenges }}>+ {children}+ </AllChallengesContext.Provider>+ );+};++export const useAllChallengesContext = () => {+ const context = useContext(AllChallengesContext);+ if (context === undefined) {+ throw new Error('use useAllChallengesContext hook within AllChallengesContextProvider');+ }+ return context;+};diff --git a/apps/web/src/app/challenge-route-data.hook.tsx b/apps/web/src/app/challenge-route-data.hook.tsxnew file mode 100644index 00000000..0466bff6--- /dev/null+++ b/apps/web/src/app/challenge-route-data.hook.tsx@@ -0,0 +1,28 @@+'use client';+import { createContext, useState, useContext, type PropsWithChildren } from 'react';+import type { GetCurrentChallengeType } from './[locale]/challenge/[slug]/getChallengeRouteData';++interface ChallengeRouteDataContextType {+ currentChallenge: GetCurrentChallengeType | null;+ setCurrentChallenge: React.Dispatch<React.SetStateAction<GetCurrentChallengeType | null>>;+}++export const ChallengeRouteDataContext = createContext({} as ChallengeRouteDataContextType);++export const ChallegeRouteDataProvider = ({ children }: PropsWithChildren) => {+ const [currentChallenge, setCurrentChallenge] = useState<GetCurrentChallengeType | null>(null);++ return (+ <ChallengeRouteDataContext.Provider value={{ currentChallenge, setCurrentChallenge }}>+ {children}+ </ChallengeRouteDataContext.Provider>+ );+};++export const useChallengeRouteData = () => {+ const context = useContext(ChallengeRouteDataContext);+ if (context === undefined) {+ throw new Error('use useChallengeRouteData hook within ChallegeRouteDataProvider');+ }+ return context;+};diff --git a/apps/web/src/app/get-challenges-and-title.tsx b/apps/web/src/app/get-challenges-and-title.tsxnew file mode 100644index 00000000..c30cfcf1--- /dev/null+++ b/apps/web/src/app/get-challenges-and-title.tsx@@ -0,0 +1,102 @@+import type {+ AllChallenges,+ ChallengesByTagOrDifficulty,+} from './[locale]/explore/_components/explore.action';++export const SORT_KEYS = [+ {+ label: 'Popular',+ value: 'popular',+ },+ {+ label: 'Beginner',+ value: 'beginner',+ },+ {+ label: 'Easy',+ value: 'easy',+ },+ {+ label: 'Medium',+ value: 'medium',+ },+ {+ label: 'Hard',+ value: 'hard',+ },+ {+ label: 'Extreme',+ value: 'extreme',+ },+] as const;++export type ChallengeLabelType = (typeof SORT_KEYS)[number]['label'];++export type ChallengeType = (typeof SORT_KEYS)[number]['value'];++export interface SortKeyType {+ label: ChallengeLabelType;+ value: ChallengeType;+}+export type ChallengeTitles =+ | 'Great for Beginners'+ | 'Great for Enthusiasts'+ | 'Great for Experts'+ | 'Great for Learners'+ | 'Great for Masters'+ | 'Recommended Challenges';++interface ChallengeResult {+ title: ChallengeTitles;+ challenges: ChallengesByTagOrDifficulty;+ key: SortKeyType;+}+export function getChallengesAndTitle(+ trackName: ChallengeType,+ AC: AllChallenges,+): ChallengeResult {+ switch (trackName) {+ case 'popular':+ return {+ title: 'Recommended Challenges',+ challenges: AC.popularChallenges,+ key: SORT_KEYS[0],+ };+ case 'beginner':+ return {+ title: 'Great for Beginners',+ challenges: AC.beginnerChallenges,+ key: SORT_KEYS[1],+ };+ case 'easy':+ return {+ title: 'Great for Learners',+ challenges: AC.easyChallenges,+ key: SORT_KEYS[2],+ };+ case 'medium':+ return {+ title: 'Great for Enthusiasts',+ challenges: AC.mediumChallenges,+ key: SORT_KEYS[3],+ };+ case 'hard':+ return {+ title: 'Great for Experts',+ challenges: AC.hardChallenges,+ key: SORT_KEYS[4],+ };+ case 'extreme':+ return {+ title: 'Great for Masters',+ challenges: AC.extremeChallenges,+ key: SORT_KEYS[5],+ };+ default:+ return {+ title: 'Recommended Challenges',+ challenges: AC.popularChallenges,+ key: SORT_KEYS[0],+ };+ }+}diff --git a/apps/web/src/app/layout.tsx b/apps/web/src/app/layout.tsxindex cfa37fe4..fc3f74f0 100644--- a/apps/web/src/app/layout.tsx+++ b/apps/web/src/app/layout.tsx@@ -6,6 +6,7 @@ import { getStaticParams } from '~/locales/server';import '../styles/globals.css';import { Providers } from './[locale]/providers';import { OG_URL, tagline } from './metadata';+import { ContextProviders } from './[locale]/context-providers';export function generateStaticParams() {return getStaticParams();@@ -63,9 +64,11 @@ export default function RootLayout({ children }: { children: React.ReactNode })</head><body className={`${inter.className} flex flex-col`}><Providers>- <Navigation />- {children}- <Toaster />+ <ContextProviders>+ <Navigation />+ {children}+ <Toaster />+ </ContextProviders></Providers><Analytics /></body>diff --git a/apps/web/src/app/problem-explorer.hooks.tsx b/apps/web/src/app/problem-explorer.hooks.tsxnew file mode 100644index 00000000..3237db69--- /dev/null+++ b/apps/web/src/app/problem-explorer.hooks.tsx@@ -0,0 +1,72 @@+'use client';+import { createContext, useState, useContext } from 'react';+import type {+ AllChallenges,+ ChallengesByTagOrDifficulty,+} from '~/app/[locale]/explore/_components/explore.action';+import {+ getChallengesAndTitle,+ type ChallengeType,+ type ChallengeTitles,+ type SortKeyType,+} from './get-challenges-and-title';+import { useLocalStorage } from '~/utils/useLocalStorage';++interface ProblemExplorerContextType {+ sortKey: SortKeyType;+ setSortKey: React.Dispatch<React.SetStateAction<SortKeyType>>;+ title: ChallengeTitles;+ setTitle: React.Dispatch<React.SetStateAction<ChallengeTitles>>;+ isExplorerDisabled: boolean;+ setIsExplorerDisabled: React.Dispatch<React.SetStateAction<boolean>>;+ getTrack: ChallengesByTagOrDifficulty;+ setTrack: React.Dispatch<React.SetStateAction<ChallengesByTagOrDifficulty>>;+}++export const ProblemExplorerContext = createContext<ProblemExplorerContextType>(+ {} as ProblemExplorerContextType,+);++interface ProblemExplorerProviderProps {+ children: React.ReactNode;+ isDisabled: boolean;+ AC: AllChallenges;+}+export const ProblemExplorerProvider = ({+ children,+ AC,+ isDisabled,+}: ProblemExplorerProviderProps) => {+ const [trackStorage] = useLocalStorage('trackName', 'popular');+ const trackName = trackStorage as ChallengeType;+ const { challenges, title: currentTitle, key } = getChallengesAndTitle(trackName, AC);+ const [getTrack, setTrack] = useState<ChallengesByTagOrDifficulty>(challenges);+ const [title, setTitle] = useState<ChallengeTitles>(currentTitle);+ const [sortKey, setSortKey] = useState<SortKeyType>(key);+ const [isExplorerDisabled, setIsExplorerDisabled] = useState<boolean>(isDisabled);++ return (+ <ProblemExplorerContext.Provider+ value={{+ sortKey,+ setSortKey,+ title,+ setTitle,+ getTrack,+ setTrack,+ isExplorerDisabled,+ setIsExplorerDisabled,+ }}+ >+ {children}+ </ProblemExplorerContext.Provider>+ );+};++export const useProblemExplorerContext = () => {+ const context = useContext(ProblemExplorerContext);+ if (context === undefined) {+ throw new Error('use useProblemExplorerContext hook within ProblemExplorerContextProvider');+ }+ return context;+};diff --git a/apps/web/src/components/Navigation/explore-nav.tsx b/apps/web/src/components/Navigation/explore-nav.tsxnew file mode 100644index 00000000..c6f55cb6--- /dev/null+++ b/apps/web/src/components/Navigation/explore-nav.tsx@@ -0,0 +1,28 @@+'use client';+import clsx from 'clsx';+import Link from 'next/link';+import { usePathname } from 'next/navigation';+import { ProblemExplorerNav } from './problem-explorer-nav';++interface ExploreNavProps {+ href: string;+ title: string;+}++export function ExploreNav({ href, title }: ExploreNavProps) {+ const pathname = usePathname();+ if (pathname.startsWith('/challenge')) {+ return <ProblemExplorerNav />;+ }+ return (+ <Link href={href}>+ <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/index.tsx b/apps/web/src/components/Navigation/index.tsxindex ab13afc3..ad126070 100644--- a/apps/web/src/components/Navigation/index.tsx+++ b/apps/web/src/components/Navigation/index.tsx@@ -33,7 +33,6 @@ export function getAdminUrl() {export async function Navigation() {const session = await auth();-const isAdminOrMod = isAdminOrModerator(session);const t = await getScopedI18n('navigation');const featureFlags = await getAllFlags();diff --git a/apps/web/src/components/Navigation/problem-explorer-nav.tsx b/apps/web/src/components/Navigation/problem-explorer-nav.tsxnew file mode 100644index 00000000..82bcd130--- /dev/null+++ b/apps/web/src/components/Navigation/problem-explorer-nav.tsx@@ -0,0 +1,93 @@+'use client';+import { useChallengeRouteData } from '~/app/challenge-route-data.hook';+import { useProblemExplorerContext } from '~/app/problem-explorer.hooks';+import { useMemo } from 'react';+import { ExploreDrawer } from '~/app/[locale]/challenge/_components/explore-drawer';+import { Tooltip, TooltipContent, TooltipTrigger } from '@repo/ui/components/tooltip';+import Link from 'next/link';+import { ChevronLeft, ChevronRight } from '@repo/ui/icons';++export function ProblemExplorerNav() {+ const { currentChallenge } = useChallengeRouteData();+ const { getTrack } = useProblemExplorerContext();+ const track = getTrack;+ const currentIndex = useMemo(() => {+ if (!track.length) return null;++ const index = track.findIndex((x) => x.id === currentChallenge?.id);+ return index === -1 ? null : index;+ }, [track, currentChallenge]);++ const next = useMemo(() => {+ if (!track.length) return null;+ if (currentIndex === null) return null;++ const nextIndex = currentIndex + 1;+ return nextIndex < track.length ? track[nextIndex] : null;+ }, [currentIndex, track]);++ const previous = useMemo(() => {+ if (!track.length) return null;+ if (currentIndex === null) return null;++ const prevIndex = currentIndex - 1;+ return prevIndex >= 0 ? track[prevIndex] : null;+ }, [currentIndex, track]);++ if (!currentChallenge) {+ return <div>Loading...</div>;+ }++ return (+ <div className="flex items-center gap-1.5">+ <ExploreDrawer asChild>+ <span className="hover:text-foreground text-foreground/80 mr-1 cursor-pointer items-center transition-colors">+ <Tooltip delayDuration={0}>+ <TooltipTrigger asChild>+ <span>Explorer</span>+ </TooltipTrigger>+ <TooltipContent sideOffset={10}>Expand panel</TooltipContent>+ </Tooltip>+ </span>+ </ExploreDrawer>+ {previous?.slug || next?.slug ? (+ <>+ <Tooltip delayDuration={0}>+ <TooltipTrigger asChild>+ {previous?.slug ? (+ <Link+ href={`/challenge/${previous?.slug}`}+ className="hover:bg-accent hover:text-accent-foreground border-muted text-foreground/80 cursor-pointer rounded-sm border p-0.5 transition-colors dark:hover:bg-zinc-900"+ >+ <ChevronLeft className="h-5 w-5" />+ </Link>+ ) : (+ <span className="border-muted text-foreground/80 cursor-not-allowed rounded-sm border p-0.5 opacity-50 transition-colors dark:hover:bg-zinc-900">+ <ChevronLeft className="h-5 w-5" />+ </span>+ )}+ </TooltipTrigger>+ <TooltipContent sideOffset={5}>Previous</TooltipContent>+ </Tooltip>+ <Tooltip delayDuration={0}>+ <TooltipTrigger asChild>+ {next?.slug ? (+ <Link+ href={`/challenge/${next?.slug}`}+ className="hover:bg-accent hover:text-accent-foreground border-muted text-foreground/80 cursor-pointer rounded-sm border p-0.5 transition-colors dark:hover:bg-zinc-900"+ >+ <ChevronRight className="h-5 w-5" />+ </Link>+ ) : (+ <span className="border-muted text-foreground/80 cursor-not-allowed rounded-sm border p-0.5 opacity-50 transition-colors dark:hover:bg-zinc-900">+ <ChevronRight className="h-5 w-5" />+ </span>+ )}+ </TooltipTrigger>+ <TooltipContent sideOffset={5}>Next</TooltipContent>+ </Tooltip>+ </>+ ) : null}+ </div>+ );+}diff --git a/apps/web/src/components/Navigation/problem-explorer-track-nav.tsx b/apps/web/src/components/Navigation/problem-explorer-track-nav.tsxnew file mode 100644index 00000000..202fcdfe--- /dev/null+++ b/apps/web/src/components/Navigation/problem-explorer-track-nav.tsx@@ -0,0 +1,111 @@+'use client';+import { useChallengeRouteData } from '~/app/challenge-route-data.hook';+import { useProblemExplorerContext } from '~/app/problem-explorer.hooks';+import { useMemo } from 'react';+import { ExploreDrawer } from '~/app/[locale]/challenge/_components/explore-drawer';+import { Tooltip, TooltipContent, TooltipTrigger } from '@repo/ui/components/tooltip';+import Link from 'next/link';+import { ChevronLeft, ChevronRight, Swords } from '@repo/ui/icons';+import { cn } from '@repo/ui/cn';+import { Button } from '@repo/ui/components/button';++interface ProblemExplorerTrackNav {+ isCollapsed: boolean;+ className?: string;+}+export function ProblemExplorerTrackNav({ isCollapsed, className }: ProblemExplorerTrackNav) {+ const { currentChallenge } = useChallengeRouteData();+ const { getTrack, title } = useProblemExplorerContext();+ const track = getTrack;+ const currentIndex = useMemo(() => {+ if (!track.length) return null;++ const index = track.findIndex((x) => x.id === currentChallenge?.id);+ return index === -1 ? null : index;+ }, [track, currentChallenge]);++ const next = useMemo(() => {+ if (!track.length) return null;+ if (currentIndex === null) return null;++ const nextIndex = currentIndex + 1;+ return nextIndex < track.length ? track[nextIndex] : null;+ }, [currentIndex, track]);++ const previous = useMemo(() => {+ if (!track.length) return null;+ if (currentIndex === null) return null;++ const prevIndex = currentIndex - 1;+ return prevIndex >= 0 ? track[prevIndex] : null;+ }, [currentIndex, track]);++ return (+ <div+ className={cn(+ {+ 'flex h-[44px] items-center gap-1': !isCollapsed,+ 'text-muted-foreground inline-flex h-auto': isCollapsed,+ },+ className,+ )}+ >+ <ExploreDrawer asChild>+ <Button+ variant="ghost"+ size="sm"+ className={cn('inline-flex flex-1 gap-2 overflow-hidden rounded-tl-xl', {+ 'justify-start': !isCollapsed,+ 'h-full items-center justify-center p-4 hover:bg-neutral-200/50 dark:hover:bg-neutral-700/50':+ isCollapsed,+ })}+ >+ <Swords className="h-4 w-4 shrink-0" />+ {Boolean(!isCollapsed) && (+ <span className="overflow-hidden text-ellipsis whitespace-nowrap">+ {previous?.slug || next?.slug ? title : 'Problem Explorer'}+ </span>+ )}+ </Button>+ </ExploreDrawer>+ {previous?.slug || next?.slug ? (+ <>+ <Tooltip delayDuration={0}>+ <TooltipTrigger asChild>+ {previous?.slug ? (+ <Link+ href={`/challenge/${previous?.slug}`}+ className="hover:bg-accent hover:text-accent-foreground border-muted text-foreground/80 cursor-pointer rounded-sm border p-0.5 transition-colors dark:hover:bg-zinc-900"+ >+ <ChevronLeft className="h-5 w-5" />+ </Link>+ ) : (+ <span className="border-muted text-foreground/80 cursor-not-allowed rounded-sm border p-0.5 opacity-50 transition-colors dark:hover:bg-zinc-900">+ <ChevronLeft className="h-5 w-5" />+ </span>+ )}+ </TooltipTrigger>+ <TooltipContent sideOffset={5}>Previous</TooltipContent>+ </Tooltip>+ <Tooltip delayDuration={0}>+ <TooltipTrigger asChild>+ {next?.slug ? (+ <Link+ href={`/challenge/${next?.slug}`}+ className="hover:bg-accent hover:text-accent-foreground border-muted text-foreground/80 cursor-pointer rounded-sm border p-0.5 transition-colors dark:hover:bg-zinc-900"+ >+ <ChevronRight className="h-5 w-5" />+ </Link>+ ) : (+ <span className="border-muted text-foreground/80 cursor-not-allowed rounded-sm border p-0.5 opacity-50 transition-colors dark:hover:bg-zinc-900">+ <ChevronRight className="h-5 w-5" />+ </span>+ )}+ </TooltipTrigger>+ <TooltipContent sideOffset={5}>Next</TooltipContent>+ </Tooltip>+ </>+ ) : null}+ </div>+ );+}diff --git a/apps/web/src/utils/useLocalStorage.ts b/apps/web/src/utils/useLocalStorage.tsindex fa3ac1e6..6792e311 100644--- a/apps/web/src/utils/useLocalStorage.ts+++ b/apps/web/src/utils/useLocalStorage.ts@@ -1,9 +1,12 @@import { useState } from 'react';export function useLocalStorage(key: string, initialValue: string): [string, (v: string) => void] {- const [storedValue, setStoredValue] = useState(() => {+ const [storedValue, setStoredValue] = useState<string>(() => {try {- return window.localStorage.getItem(key) || initialValue;+ if (window !== undefined) {+ return window.localStorage.getItem(key) || initialValue;+ }+ return initialValue;} catch (error) {console.error(error);return initialValue;