Files
simstudioai--sim/apps/docs/components/ui/video-chapters.tsx
T
wehub-resource-sync d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

74 lines
2.6 KiB
TypeScript

'use client'
import { useEffect, useState } from 'react'
import { cn } from '@/lib/utils'
/** Parse a chapter timestamp ("M:SS" or "H:MM:SS") into seconds. */
function parseTime(time: string): number {
const parts = time.split(':').map(Number)
if (parts.some(Number.isNaN)) return 0
return parts.reduce((acc, n) => acc * 60 + n, 0)
}
interface Chapter {
/** Chapter label. */
title: string
/** Timestamp, e.g. "0:45". */
time?: string
}
interface VideoChaptersProps {
/** Panel heading. Defaults to "Chapters". */
title?: string
chapters: Chapter[]
className?: string
}
/**
* Right-rail list of the current video's chapters — flat and borderless to
* match the docs' "On this page" TOC (small muted label, hover-highlighted
* rows). Rows are skip-to controls; they activate once the lesson's video is
* recorded.
*/
export function VideoChapters({ title = 'Chapters', chapters, className }: VideoChaptersProps) {
// Chapters only seek when a VideoPlaceholder with a real video is on the page.
// Handshake so the rows stay inert (not falsely clickable) on video-less lessons.
const [hasVideo, setHasVideo] = useState(false)
useEffect(() => {
const onReady = () => setHasVideo(true)
window.addEventListener('academy:video-ready', onReady)
window.dispatchEvent(new Event('academy:video-query'))
return () => window.removeEventListener('academy:video-ready', onReady)
}, [])
return (
<aside className={cn('not-prose', className)}>
<p className='mb-2 px-2.5 font-medium text-[0.8125rem] text-[var(--text-muted)]'>{title}</p>
<ul className='m-0 flex list-none flex-col gap-0.5 p-0'>
{chapters.map((chapter) => (
<li key={chapter.title}>
<button
type='button'
disabled={!hasVideo || chapter.time == null}
onClick={() => {
if (chapter.time == null) return
window.dispatchEvent(
new CustomEvent('academy:seek', { detail: { time: parseTime(chapter.time) } })
)
}}
className='flex w-full cursor-pointer items-baseline gap-3 rounded-lg px-2.5 py-2 text-left text-[var(--text-secondary)] text-sm transition-colors hover:bg-[var(--surface-active)] disabled:cursor-default disabled:hover:bg-transparent'
>
<span className='min-w-0 flex-1 break-words'>{chapter.title}</span>
{chapter.time && (
<span className='shrink-0 text-[var(--text-muted)] text-xs tabular-nums'>
{chapter.time}
</span>
)}
</button>
</li>
))}
</ul>
</aside>
)
}