import Head from 'next/head' import { useRouter } from 'next/router' import { useEffect } from 'react' import RefEducationSection from '~/components/reference/RefEducationSection' import RefFunctionSection from '~/components/reference/RefFunctionSection' import RefSubLayout from '~/layouts/ref/RefSubLayout' import ApiOperationSection from './ApiOperationSection' import CliCommandSection from './CLICommandSection' import OldVersionAlert from './OldVersionAlert' import { IAPISpec, ICommonSection, IRefStaticDoc, ISpec, TypeSpec } from './Reference.types' interface RefSectionHandlerProps { sections: ICommonSection[] spec?: ISpec | IAPISpec typeSpec?: TypeSpec pageProps: { docs: IRefStaticDoc[] } type: 'client-lib' | 'cli' | 'api' isOldVersion?: boolean } const RefSectionHandler = (props: RefSectionHandlerProps) => { const router = useRouter() const [slug] = router.query.slug // When user lands on a url like http://supabase.com/docs/reference/javascript/sign-up // find the #sign-up element and scroll to that useEffect(() => { document.getElementById(slug)?.scrollIntoView() }, [slug]) useEffect(() => { function handler() { const [slug] = window.location.pathname.split('/').slice(-1) document.getElementById(slug)?.scrollIntoView() } window.addEventListener('popstate', handler) return () => { window.removeEventListener('popstate', handler) } }, []) function getPageTitle() { switch (props.type) { case 'client-lib': return props.spec.info.title case 'cli': return 'Supabase CLI reference' case 'api': return 'Supabase API reference' default: return 'Supabase Docs' } } const pageTitle = getPageTitle() const section = props.sections.find((section) => section.slug === slug) const fullTitle = `${pageTitle}${section ? ` - ${section.title}` : ''}` const path = router.asPath.replace('/crawlers', '') return ( <>