Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 23x 23x 23x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 8x 8x 8x 8x 8x 8x 8x 8x 8x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 2x 2x 2x 2x 2x 2x 3x 3x 3x 3x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 2x 2x 2x 2x 8x 8x 8x 8x 8x 8x 8x 8x 8x 2x 2x 3x 3x 3x 3x | 'use client'
import Link from 'next/link'
import {usePathname} from 'next/navigation'
import {signOut, useSession} from 'next-auth/react'
import {ReactNode} from 'react'
import Dropdown from '@/components/Dropdown'
import ThemeToggle from '@/components/ThemeToggle'
import Avatar from '@/components/Avatar'
import {startTour} from '@/components/tour/Tour'
import {OfflineBadge} from '@/components/pwa/PwaSetup'
import {clearSaved} from '@/components/pwa/pwa'
const TABS = [
{href: '/songs', label: 'Songs'},
{href: '/setlists', label: 'Setlists'},
{href: '/rehearsals', label: 'Rehearsals'},
{href: '/proposals', label: 'Proposals'},
]
/** What the header needs to know, worked out on the server per request. */
export type ShellBand = {
/** "Monkee Wrench" for Monkee Business; Bandstand by default */
appName: string
/** The band on screen; null when none is chosen yet (or signed out) */
band: {
id: string
name: string
chat: {url: string; label: string} | null
isAdmin: boolean
} | null
/** Every band they're in, for switching */
bands: {id: string; name: string}[]
isOwner: boolean
}
// Screens that take the whole display (performance mode) or stand alone
const BARE = [/^\/perform\//, /^\/login/]
// The tour's sample pages stand in for these tabs
const TOUR_TABS: [RegExp, string][] = [
[/^\/tour\/(song|edit)$/, '/songs'],
[/^\/tour\/setlist$/, '/setlists'],
]
/** Is this tab the page being shown? */
export function isActive(pathname: string, href: string) {
const p = TOUR_TABS.find(([r]) => r.test(pathname))?.[1] ?? pathname
return p === href || p.startsWith(href + '/')
}
async function switchTo(bandId: string) {
// Pages saved for offline belong to the band they came from
await clearSaved()
const r = await fetch('/api/bands/current', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({bandId}),
})
// A full load: the layout (name, icon, menu) belongs to the band
if (r.ok) window.location.assign('/songs')
}
export default function AppShell({
ctx,
children,
}: {
ctx: ShellBand
children: ReactNode
}) {
const pathname = usePathname() ?? '/'
const {data: session} = useSession()
if (BARE.some((r) => r.test(pathname))) return <>{children}</>
const name = session?.user?.name || session?.user?.email || ''
const {band} = ctx
const others = ctx.bands.filter((b) => b.id !== band?.id)
const tabs = TABS
return (
<div className="flex min-h-dvh flex-col">
<div className="sticky top-0 z-30 border-b border-line bg-ink/95 backdrop-blur">
<header className="flex items-center gap-4 px-4 py-2">
<Link
href={band ? '/songs' : '/bands'}
className="text-[14px] font-extrabold uppercase tracking-[0.2em] no-underline"
>
{ctx.appName}
</Link>
<nav
aria-label="Main"
className={`hidden flex-1 gap-1 ${band ? 'md:flex' : ''}`}
>
{(band ? tabs : []).map((t) => {
const on = isActive(pathname, t.href)
return (
<Link
key={t.href}
href={t.href}
aria-current={on ? 'page' : undefined}
className={`rounded-lg px-3.5 py-2.5 no-underline ${on ? 'bg-text font-semibold text-ink' : 'text-muted hover:text-text'}`}
>
{t.label}
</Link>
)
})}
</nav>
<span className="flex-1 md:hidden" />
<OfflineBadge />
<ThemeToggle />
{session?.user && (
<Dropdown
label="Account menu"
triggerClassName="flex h-11 w-11 items-center justify-center overflow-hidden rounded-full bg-panel font-bold"
trigger={
<Avatar name={name} src={session.user.image} size={36} />
}
>
<p className="px-3 py-2 text-sm text-muted">
{name}
{band && ctx.bands.length > 1 && (
<span className="block text-xs text-faint">{band.name}</span>
)}
</p>
{band && <MenuLink href="/activity">Recent changes</MenuLink>}
{band?.chat && (
<a
href={band.chat.url}
target="_blank"
rel="noopener noreferrer"
className="block rounded-lg px-3 py-2.5 no-underline hover:bg-line"
>
{band.chat.label} ↗
</a>
)}
<MenuLink href="/account">Account & settings</MenuLink>
<MenuLink href="/help">Help</MenuLink>
{band && (
<button
type="button"
onClick={startTour}
className="block w-full rounded-lg px-3 py-2.5 text-left hover:bg-line"
>
Take the tour
</button>
)}
{band?.isAdmin && (
<MenuLink href="/members">Band members</MenuLink>
)}
{band?.isAdmin && <MenuLink href="/admin">Admin</MenuLink>}
{ctx.isOwner && (
<MenuLink href="/bands/manage">All bands</MenuLink>
)}
{others.length > 0 && (
<div className="mt-1 border-t border-line pt-1">
<p className="px-3 pb-1 pt-2 text-xs font-bold uppercase tracking-widest text-faint">
Switch band
</p>
{others.map((b) => (
<button
key={b.id}
type="button"
onClick={() => switchTo(b.id)}
className="block w-full rounded-lg px-3 py-2.5 text-left hover:bg-line"
>
{b.name}
</button>
))}
</div>
)}
<button
type="button"
onClick={async () => {
// Nothing saved on this device outlives signing out
await clearSaved()
signOut({callbackUrl: '/login'})
}}
className="block w-full rounded-lg px-3 py-2.5 text-left hover:bg-line"
>
Sign out
</button>
</Dropdown>
)}
</header>
{/* Phones: the tabs sit under the title bar, at the top (not a bottom bar) */}
{band && (
<nav
aria-label="Main"
className={`grid gap-1 px-2 pb-2 md:hidden grid-cols-4`}
>
{tabs.map((t) => {
const on = isActive(pathname, t.href)
return (
<Link
key={t.href}
href={t.href}
aria-current={on ? 'page' : undefined}
className={`flex min-h-11 items-center justify-center rounded-lg text-[13px] font-semibold no-underline ${on ? 'bg-text text-ink' : 'text-muted'}`}
>
{t.label}
</Link>
)
})}
</nav>
)}
</div>
<div className="flex-1">{children}</div>
</div>
)
}
function MenuLink({href, children}: {href: string; children: ReactNode}) {
return (
<Link
href={href}
className="block rounded-lg px-3 py-2.5 no-underline hover:bg-line"
>
{children}
</Link>
)
}
|