mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
* set up multiple themes in studio * set up multiple themes in studio * set up multiple themes in docs and www * update all resolvedTheme to also include deep-dark * update all resolvedTheme checks to also include deep-dark * update tailwind.config.js tokens * update tailwind.config.js tokens * update leftover scale12 token * update if resolvedTheme _doesn't_ include 'dark' * update more styling tokens * add dynamic themes to CmdK * fix nav and footer for multi theme * add data-theme selector output to transformTokens.js * update code-hike.css to target data-theme css * update tailwindcss to ^3.3.5 * ThemeImage with light and dark src for www and docs * add brand-button styling token * update old dark theme boolean * update old dark theme boolean * make homepage product visuals themeable * update product page themed images * update badge green with brand * fix roles list appearance * fix auth widget in auth page * update more dark logic * update more dark logic * add button default bg and border * update pricing page theme styling * clean up Themeimage * remove forceDark in homepage * update dark:border-dark occurrences * update dark:border-dark occurrences * fix dark mode base colors * remove foreground-strong * fix notification badge bg * remove some dark: selectors * update dark: selectors * update code-hike deep dark bg color * fix comment typo * update border-button-hover token * fix customer story logo * remove some more dark: selectors * restore forceDark in www homepage * fix auth react icon * fix homepage product visuals * remove theme * add brand-link token * fix checkbox bg * npm install * more visible EntityListItem active bg * fix --background-alternative-default css vars --------- Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com>
187 lines
5.3 KiB
TypeScript
187 lines
5.3 KiB
TypeScript
import '@code-hike/mdx/styles'
|
|
import 'config/code-hike.scss'
|
|
import '../styles/main.scss'
|
|
import '../styles/new-docs.scss'
|
|
import '../styles/prism-okaidia.scss'
|
|
|
|
import { SessionContextProvider } from '@supabase/auth-helpers-react'
|
|
import { createClient } from '@supabase/supabase-js'
|
|
import { AuthProvider, ThemeProvider, useTelemetryProps, useThemeSandbox } from 'common'
|
|
import { useRouter } from 'next/router'
|
|
import { useCallback, useEffect, useState } from 'react'
|
|
import { AppPropsWithLayout } from 'types'
|
|
import { CommandMenuProvider, useConsent } from 'ui'
|
|
import { TabsProvider } from 'ui/src/components/Tabs'
|
|
import PortalToast from 'ui/src/layout/PortalToast'
|
|
import Favicons from '~/components/Favicons'
|
|
import SiteLayout from '~/layouts/SiteLayout'
|
|
import { API_URL, IS_PLATFORM } from '~/lib/constants'
|
|
import { post } from '~/lib/fetchWrappers'
|
|
|
|
function MyApp({ Component, pageProps }: AppPropsWithLayout) {
|
|
const router = useRouter()
|
|
const telemetryProps = useTelemetryProps()
|
|
const { consentValue, hasAcceptedConsent } = useConsent()
|
|
|
|
useThemeSandbox()
|
|
|
|
const [supabase] = useState(() =>
|
|
IS_PLATFORM
|
|
? createClient(
|
|
process.env.NEXT_PUBLIC_SUPABASE_URL,
|
|
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY
|
|
)
|
|
: undefined
|
|
)
|
|
|
|
const handlePageTelemetry = useCallback(
|
|
(route: string) => {
|
|
return post(`${API_URL}/telemetry/page`, {
|
|
referrer: document.referrer,
|
|
title: document.title,
|
|
route,
|
|
ga: {
|
|
screen_resolution: telemetryProps?.screenResolution,
|
|
language: telemetryProps?.language,
|
|
},
|
|
})
|
|
},
|
|
[telemetryProps]
|
|
)
|
|
|
|
useEffect(() => {
|
|
function handleRouteChange(url: string) {
|
|
/*
|
|
* handle telemetry
|
|
*/
|
|
if (hasAcceptedConsent) handlePageTelemetry(url)
|
|
/*
|
|
* handle "scroll to top" behaviour on route change
|
|
*/
|
|
if (document) {
|
|
// do not scroll to top for reference docs
|
|
if (!url.includes('reference/')) {
|
|
// scroll container div to top
|
|
const container = document.getElementById('docs-content-container')
|
|
// check container exists (only avail on new docs)
|
|
if (container) container.scrollTop = 0
|
|
}
|
|
}
|
|
}
|
|
|
|
// Listen for page changes after a navigation or when the query changes
|
|
router.events.on('routeChangeComplete', handleRouteChange)
|
|
return () => {
|
|
router.events.off('routeChangeComplete', handleRouteChange)
|
|
}
|
|
}, [router, handlePageTelemetry, consentValue])
|
|
|
|
/**
|
|
* Save/restore scroll position when reloading or navigating back/forward.
|
|
*
|
|
* Required since scroll happens within a sub-container, not the page root.
|
|
*/
|
|
useEffect(() => {
|
|
const storageKey = 'scroll-position'
|
|
|
|
const container = document.getElementById('docs-content-container')
|
|
if (!container) {
|
|
return
|
|
}
|
|
|
|
const previousScroll = Number(sessionStorage.getItem(storageKey))
|
|
const [entry] = window.performance.getEntriesByType('navigation')
|
|
|
|
// Only restore scroll position on reload and back/forward events
|
|
if (
|
|
previousScroll &&
|
|
entry &&
|
|
isPerformanceNavigationTiming(entry) &&
|
|
['reload', 'back_forward'].includes(entry.type)
|
|
) {
|
|
container.scrollTop = previousScroll
|
|
}
|
|
|
|
const handler = () => {
|
|
// Scroll stored in session storage, so only persisted per tab
|
|
sessionStorage.setItem(storageKey, container.scrollTop.toString())
|
|
}
|
|
|
|
window.addEventListener('beforeunload', handler)
|
|
|
|
return () => window.removeEventListener('beforeunload', handler)
|
|
}, [router])
|
|
|
|
useEffect(() => {
|
|
if (!hasAcceptedConsent) return
|
|
|
|
/**
|
|
* Send page telemetry on first page load
|
|
*/
|
|
if (router.isReady) {
|
|
handlePageTelemetry(router.basePath + router.asPath)
|
|
}
|
|
}, [router, handlePageTelemetry, consentValue])
|
|
|
|
/**
|
|
* Reference docs use `history.pushState()` to jump to
|
|
* sub-sections without causing a re-render.
|
|
*
|
|
* We need to the below handler to manually force a re-render
|
|
* when navigating away from, then back to reference docs
|
|
*/
|
|
useEffect(() => {
|
|
function handler() {
|
|
router.replace(window.location.href)
|
|
}
|
|
|
|
window.addEventListener('popstate', handler)
|
|
|
|
return () => {
|
|
window.removeEventListener('popstate', handler)
|
|
}
|
|
}, [router])
|
|
|
|
const SITE_TITLE = 'Supabase Documentation'
|
|
|
|
const AuthContainer = (props) => {
|
|
return IS_PLATFORM ? (
|
|
<SessionContextProvider supabaseClient={supabase}>
|
|
<AuthProvider>{props.children}</AuthProvider>
|
|
</SessionContextProvider>
|
|
) : (
|
|
<AuthProvider>{props.children}</AuthProvider>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<Favicons />
|
|
<AuthContainer>
|
|
<ThemeProvider defaultTheme="system" enableSystem disableTransitionOnChange>
|
|
<CommandMenuProvider site="docs">
|
|
<TabsProvider>
|
|
<SiteLayout>
|
|
<PortalToast />
|
|
<Component {...pageProps} />
|
|
</SiteLayout>
|
|
</TabsProvider>
|
|
</CommandMenuProvider>
|
|
</ThemeProvider>
|
|
</AuthContainer>
|
|
</>
|
|
)
|
|
}
|
|
|
|
/**
|
|
* Type guard that checks if a performance entry is a
|
|
* `PerformanceNavigationTiming`.
|
|
*/
|
|
function isPerformanceNavigationTiming(
|
|
entry: PerformanceEntry
|
|
): entry is PerformanceNavigationTiming {
|
|
return entry.entryType === 'navigation'
|
|
}
|
|
|
|
export default MyApp
|