|
| 1 | +'use client'; |
| 2 | + |
| 3 | +/** |
| 4 | + * AppShell — primary app-wide navigation (#1314). |
| 5 | + * |
| 6 | + * The landing page (`/`) already owns its own full marketing header/nav/ |
| 7 | + * footer (components/LandingPage.tsx — separate anchor-link nav for |
| 8 | + * #features/#how-it-works/#about/#contact), so AppShell skips rendering |
| 9 | + * on `/` to avoid a duplicate header there. Everywhere else (Markets, |
| 10 | + * Statistics, Create Market, account, tx, and — conditionally, once an |
| 11 | + * admin session exists — Admin) gets a persistent header with primary |
| 12 | + * navigation and a minimal footer, matching the sub-nav pattern already |
| 13 | + * established by app/admin/layout.tsx for its own section. |
| 14 | + */ |
| 15 | + |
| 16 | +import React, { useEffect, useState } from 'react'; |
| 17 | +import Link from 'next/link'; |
| 18 | +import { usePathname } from 'next/navigation'; |
| 19 | + |
| 20 | +const NAV_ITEMS = [ |
| 21 | + { href: '/markets', label: 'Markets' }, |
| 22 | + { href: '/statistics', label: 'Statistics' }, |
| 23 | + { href: '/markets/create', label: 'Create Market' }, |
| 24 | +]; |
| 25 | + |
| 26 | +export function AppShell({ children }: { children: React.ReactNode }) { |
| 27 | + const pathname = usePathname(); |
| 28 | + const [hasAdminSession, setHasAdminSession] = useState(false); |
| 29 | + |
| 30 | + useEffect(() => { |
| 31 | + setHasAdminSession(Boolean(sessionStorage.getItem('predictiq-admin-key'))); |
| 32 | + }, [pathname]); |
| 33 | + |
| 34 | + const isLandingPage = pathname === '/'; |
| 35 | + const isAdminSection = pathname?.startsWith('/admin'); |
| 36 | + |
| 37 | + if (isLandingPage || isAdminSection) { |
| 38 | + return <>{children}</>; |
| 39 | + } |
| 40 | + |
| 41 | + const navItems = hasAdminSession |
| 42 | + ? [...NAV_ITEMS, { href: '/admin/content', label: 'Admin' }] |
| 43 | + : NAV_ITEMS; |
| 44 | + |
| 45 | + return ( |
| 46 | + <div style={{ display: 'flex', flexDirection: 'column', minHeight: '100vh' }}> |
| 47 | + <a href="#app-main-content" className="skip-link"> |
| 48 | + Skip to main content |
| 49 | + </a> |
| 50 | + |
| 51 | + <header |
| 52 | + role="banner" |
| 53 | + style={{ |
| 54 | + borderBottom: '1px solid var(--border)', |
| 55 | + backgroundColor: 'var(--surface)', |
| 56 | + position: 'sticky', |
| 57 | + top: 0, |
| 58 | + zIndex: 100, |
| 59 | + }} |
| 60 | + > |
| 61 | + <div |
| 62 | + style={{ |
| 63 | + maxWidth: 'var(--container)', |
| 64 | + margin: '0 auto', |
| 65 | + padding: '1rem 1.5rem', |
| 66 | + display: 'flex', |
| 67 | + alignItems: 'center', |
| 68 | + justifyContent: 'space-between', |
| 69 | + gap: '1.5rem', |
| 70 | + }} |
| 71 | + > |
| 72 | + <Link |
| 73 | + href="/" |
| 74 | + aria-label="PredictIQ Home" |
| 75 | + style={{ textDecoration: 'none', fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: '1.2rem' }} |
| 76 | + > |
| 77 | + <span style={{ color: 'var(--fg)' }}>Predict</span> |
| 78 | + <span style={{ color: 'var(--gold)' }}>IQ</span> |
| 79 | + </Link> |
| 80 | + |
| 81 | + <nav aria-label="Primary navigation"> |
| 82 | + <ul |
| 83 | + style={{ |
| 84 | + display: 'flex', |
| 85 | + gap: '1.5rem', |
| 86 | + listStyle: 'none', |
| 87 | + margin: 0, |
| 88 | + padding: 0, |
| 89 | + }} |
| 90 | + > |
| 91 | + {navItems.map((item) => { |
| 92 | + const isActive = pathname === item.href || pathname?.startsWith(`${item.href}/`); |
| 93 | + return ( |
| 94 | + <li key={item.href}> |
| 95 | + <Link |
| 96 | + href={item.href} |
| 97 | + aria-current={isActive ? 'page' : undefined} |
| 98 | + style={{ |
| 99 | + textDecoration: 'none', |
| 100 | + fontSize: 'var(--text-sm)', |
| 101 | + fontWeight: 500, |
| 102 | + color: isActive ? 'var(--gold)' : 'var(--fg-muted)', |
| 103 | + }} |
| 104 | + > |
| 105 | + {item.label} |
| 106 | + </Link> |
| 107 | + </li> |
| 108 | + ); |
| 109 | + })} |
| 110 | + </ul> |
| 111 | + </nav> |
| 112 | + </div> |
| 113 | + </header> |
| 114 | + |
| 115 | + <main id="app-main-content" role="main" style={{ flex: 1 }}> |
| 116 | + {children} |
| 117 | + </main> |
| 118 | + |
| 119 | + <footer |
| 120 | + role="contentinfo" |
| 121 | + style={{ |
| 122 | + borderTop: '1px solid var(--border)', |
| 123 | + backgroundColor: 'var(--surface)', |
| 124 | + padding: '1.5rem', |
| 125 | + textAlign: 'center', |
| 126 | + fontSize: 'var(--text-xs)', |
| 127 | + color: 'var(--fg-muted)', |
| 128 | + }} |
| 129 | + > |
| 130 | + © {new Date().getFullYear()} PredictIQ. Built on Stellar. |
| 131 | + </footer> |
| 132 | + </div> |
| 133 | + ); |
| 134 | +} |
| 135 | + |
| 136 | +export default AppShell; |
0 commit comments