Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

12.5 KB
Raw Blame
'use client'

import DefaultLayout from '~/components/Layouts/Default'
import pageData from '~/data/surveys/state-of-startups-2026'
import { useSendTelemetryEvent } from '~/lib/telemetry'
import { AnimatePresence, motion } from 'motion/react'
import Link from 'next/link'
import { forwardRef, useEffect, useRef, useState, type RefObject } from 'react'
import { Button, cn } from 'ui'

import { ParticipantsCarousel } from './components/ParticipantsCarousel'
import { StateOfStartupsAuroraHeader } from './components/StateOfStartupsAuroraHeader'
import { SurveyChapter } from './components/SurveyChapter'
import { SurveyChapterSection } from './components/SurveyChapterSection'
import { SurveySectionBreak } from './components/SurveySectionBreak'
import { YearProvider } from './components/year-context'

interface FloatingTocProps {
  tocRef: RefObject<HTMLDivElement | null>
  isTocOpen: boolean
  setIsTocOpen: (open: boolean) => void
  activeChapter: number
}

function FloatingTableOfContents({
  tocRef,
  isTocOpen,
  setIsTocOpen,
  activeChapter,
}: FloatingTocProps) {
  const currentChapter = pageData.pageChapters[activeChapter - 1]

  return (
    <motion.div ref={tocRef} layout className="relative">
      <motion.div layout className="relative">
        <AnimatePresence mode="wait">
          {!isTocOpen ? (
            <motion.button
              key="pill"
              layoutId="toc-pill"
              layout
              onClick={() => setIsTocOpen(true)}
              className="flex flex-row items-center gap-2 shadow-xl rounded-full overflow-hidden px-2 pr-4 h-[30px] border border-overlay bg-overlay text-foreground font-mono uppercase text-xs"
              initial={{ opacity: 0, scale: 0.9, y: -6 }}
              animate={{ opacity: 1, scale: 1, y: 0 }}
              exit={{ opacity: 0, scale: 0.9, y: -6 }}
              transition={{
                layout: { duration: 0.5, type: 'spring' },
                duration: 0.15,
                ease: 'easeOut',
              }}
            >
              <motion.span
                layout="position"
                className="bg-surface-100 border border-surface-200 rounded-xl w-5 h-5 flex items-center justify-center text-foreground-light shrink-0"
              >
                {activeChapter}
              </motion.span>
              <AnimatePresence mode="popLayout">
                <motion.span
                  key={currentChapter?.shortTitle}
                  layout
                  className="text-foreground tracking-widest whitespace-nowrap"
                  initial={{ opacity: 0 }}
                  animate={{ opacity: 1 }}
                  exit={{ opacity: 0 }}
                  transition={{ duration: 0.2, delay: 0.1 }}
                >
                  {currentChapter?.shortTitle}
                </motion.span>
              </AnimatePresence>
            </motion.button>
          ) : (
            <motion.div
              key="dropdown"
              initial={{ opacity: 0, scale: 0.86, y: -10 }}
              animate={{ opacity: 1, scale: 1, y: 0 }}
              exit={{ opacity: 0, scale: 0.86, y: -10 }}
              transition={{ duration: 0.15, ease: 'easeOut' }}
              className="origin-[50%_25%] bg-background/80 backdrop-blur-lg border border-default rounded-xl shadow-xl overflow-hidden"
            >
              <ol className="max-h-[60vh] overflow-y-auto py-2 flex flex-col">
                {pageData.pageChapters.map((chapter, chapterIndex) => (
                  <motion.li
                    key={chapterIndex + 1}
                    initial={{ opacity: 0, y: -2 }}
                    animate={{ opacity: 1, y: 0 }}
                    transition={{
                      duration: 0.1,
                      ease: 'easeOut',
                      delay:
                        0.1 +
                        Math.exp(-(pageData.pageChapters.length - chapterIndex - 1) * 0.3) * 0.2,
                    }}
                  >
                    <Link
                      href={`#chapter-${chapterIndex + 1}`}
                      onClick={() => setIsTocOpen(false)}
                      className={cn(
                        'block px-6 py-2 text-xs transition-colors font-mono uppercase tracking-wider text-center text-foreground-light hover:text-primary hover:bg-brand-300/25',
                        chapterIndex + 1 === activeChapter && 'bg-brand-300/40 text-primary'
                      )}
                    >
                      {chapter.shortTitle}
                    </Link>
                  </motion.li>
                ))}
              </ol>
            </motion.div>
          )}
        </AnimatePresence>
      </motion.div>
    </motion.div>
  )
}

export default function StateOfStartups2026Content() {
  const [showFloatingToc, setShowFloatingToc] = useState(false)
  const [isTocOpen, setIsTocOpen] = useState(false)
  const [activeChapter, setActiveChapter] = useState(1)
  const tocRef = useRef<HTMLDivElement>(null)
  const heroRef = useRef<HTMLDivElement>(null)
  const ctaBannerRef = useRef<HTMLElement>(null)

  // Scroll detection to show floating ToC
  useEffect(() => {
    const handleScroll = () => {
      const heroElement = heroRef.current
      const ctaBannerElement = ctaBannerRef.current

      if (heroElement && ctaBannerElement) {
        const heroRect = heroElement.getBoundingClientRect()
        const ctaBannerRect = ctaBannerElement.getBoundingClientRect()

        // Show floating ToC when the hero section is completely out of view
        // but hide it when the CTA banner comes into view
        if (heroRect.bottom < 0 && ctaBannerRect.top > window.innerHeight) {
          setShowFloatingToc(true)
        } else {
          setShowFloatingToc(false)
          setIsTocOpen(false)
        }
      }
    }

    window.addEventListener('scroll', handleScroll)
    return () => window.removeEventListener('scroll', handleScroll)
  }, [])

  // Active chapter detection
  useEffect(() => {
    const handleScroll = () => {
      const chapters = pageData.pageChapters
      const scrollY = window.scrollY + 100 // Offset for better detection

      for (let i = chapters.length - 1; i >= 0; i--) {
        const chapterElement = document.getElementById(`chapter-${i + 1}`)
        if (chapterElement && scrollY >= chapterElement.offsetTop) {
          setActiveChapter(i + 1)
          break
        }
      }
    }

    window.addEventListener('scroll', handleScroll)
    return () => window.removeEventListener('scroll', handleScroll)
  }, [])

  // Close ToC when clicking outside
  useEffect(() => {
    const handleClickOutside = (event: MouseEvent) => {
      const isOutsideFloating = tocRef.current && !tocRef.current.contains(event.target as Node)

      if (isOutsideFloating) {
        setIsTocOpen(false)
      }
    }

    if (isTocOpen) {
      document.addEventListener('mousedown', handleClickOutside)
    }

    return () => {
      document.removeEventListener('mousedown', handleClickOutside)
    }
  }, [isTocOpen])

  return (
    <YearProvider>
      <DefaultLayout className="bg-alternative overflow-hidden">
        <AnimatePresence>
          {showFloatingToc && (
            <motion.div
              key="floating-controls"
              className="fixed top-20 inset-x-0 z-50 pointer-events-none flex justify-center"
              initial={{ opacity: 0, y: -8 }}
              animate={{ opacity: 1, y: 0 }}
              exit={{ opacity: 0, y: -8 }}
              transition={{ duration: 0.2, ease: 'easeOut' }}
            >
              <motion.div layout className="flex items-start gap-2 pointer-events-auto">
                <FloatingTableOfContents
                  tocRef={tocRef}
                  isTocOpen={isTocOpen}
                  setIsTocOpen={setIsTocOpen}
                  activeChapter={activeChapter}
                />
              </motion.div>
            </motion.div>
          )}
        </AnimatePresence>
        {/* Intro section */}
        <section ref={heroRef} className="w-full">
          <StateOfStartupsAuroraHeader />
          <SurveySectionBreak className="hidden md:block" />
          <div className="grid grid-cols-1 md:grid-cols-3 max-w-240 mx-auto md:border-x border-muted">
            {/* Intro text */}
            <div className="md:col-span-2 flex flex-col gap-4 px-8 py-10 border-b md:border-b-0 md:border-r border-muted text-foreground text-xl md:text-2xl text-balance">
              <p>{pageData.heroSection.subheader}</p>
              <p>{pageData.heroSection.cta}</p>
            </div>

            {/* Table of contents */}
            <ol className="flex flex-col py-5">
              {pageData.pageChapters.map((chapter, chapterIndex) => (
                <li key={chapterIndex + 1}>
                  <Link
                    href={`#chapter-${chapterIndex + 1}`}
                    className="group flex flex-row gap-5 py-3 pl-7 pr-8 font-mono uppercase tracking-wide text-sm transition-all text-foreground-light hover:text-primary hover:bg-brand-300/25"
                  >
                    <span className="text-xs rounded-full bg-surface-75 border border-surface-200 group-hover:border-brand-500/40 w-5 h-5 flex items-center justify-center group-hover:bg-brand-600/5">
                      {chapterIndex + 1}
                    </span>{' '}
                    {chapter.shortTitle}
                  </Link>
                </li>
              ))}
            </ol>
          </div>

          <SurveySectionBreak />
        </section>

        {pageData.pageChapters.map((chapter, chapterIndex) => (
          <SurveyChapter
            key={chapterIndex + 1}
            number={chapterIndex + 1}
            shortTitle={chapter.shortTitle}
            title={chapter.title}
            description={chapter.description}
            pullQuote={chapter.pullQuote}
            pullQuoteCarousel={chapter.pullQuoteCarousel}
          >
            {chapter.sections.map((section, sectionIndex) => (
              <SurveyChapterSection key={sectionIndex + 1} section={section} />
            ))}
          </SurveyChapter>
        ))}
        <CTABanner ref={ctaBannerRef} />
        <ParticipantsList />
      </DefaultLayout>
    </YearProvider>
  )
}

// Component for the participants list
const ParticipantsList = () => {
  return (
    <section className="flex flex-col items-center gap-12 md:gap-20 py-20 md:py-28 text-center border-b border-muted">
      <div className="flex flex-col items-center gap-4 max-w-prose px-4">
        <h2 className="text-foreground text-3xl text-balance">Thank you</h2>
        <p className="text-foreground-light text-lg text-balance max-w-prose">
          A special thanks to the following companies for participating in this year's survey.
        </p>
      </div>

      <ParticipantsCarousel participants={pageData.participantsList} />
    </section>
  )
}

// Component for the 'Builders choose Supabase' CTA at the bottom of the page
const CTABanner = forwardRef<HTMLElement>((props, ref) => {
  const sendTelemetryEvent = useSendTelemetryEvent()
  return (
    <section
      className="flex flex-col items-center gap-4 px-4 py-32 text-center border-b border-muted"
      style={{
        background:
          'radial-gradient(circle at center 220%, hsl(var(--brand-400)), transparent 70%)',
      }}
      ref={ref}
    >
      <div className="flex flex-col items-center gap-4 max-w-prose">
        <h2 className="text-foreground text-5xl text-balance">Builders choose Supabase</h2>
        <p className="text-foreground-light text-lg">
          Supabase is the Postgres development platform. Build your startup with a Postgres
          database, Authentication, instant APIs, Edge Functions, Realtime subscriptions, Storage,
          and Vector embeddings.
        </p>
      </div>
      <div className="flex items-center justify-center gap-2 mt-4">
        <Button variant="primary" asChild size="medium">
          <a
            href="https://supabase.com/dashboard"
            onClick={() =>
              sendTelemetryEvent({
                action: 'start_project_button_clicked',
                properties: { buttonLocation: 'CTA Banner' },
              })
            }
          >
            Start your project
          </a>
        </Button>
        <Button asChild size="medium">
          <Link
            href="/contact/sales"
            onClick={() =>
              sendTelemetryEvent({
                action: 'request_demo_button_clicked',
                properties: { buttonLocation: 'CTA Banner' },
              })
            }
          >
            Request a demo
          </Link>
        </Button>
      </div>
    </section>
  )
})

CTABanner.displayName = 'CTABanner'