Skip to content

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

move pageType stuff to component level so they are more independent

Jonathan Summers-Muird6ded231b2e7
diff --git a/apps/docs/components/Navigation/NavBar.tsx b/apps/docs/components/Navigation/NavBar.tsx
index 6a3a4f525b5..3b6e7c4b7fe 100644
--- a/apps/docs/components/Navigation/NavBar.tsx
+++ b/apps/docs/components/Navigation/NavBar.tsx
@@ -7,11 +7,9 @@ import { useTheme } from '../Providers'
import { REFERENCES } from './Navigation.constants'
import { SearchButton } from '../DocSearch'
-interface Props {
- currentPage: string
-}
+import { getPageType } from '~/lib/helpers'
-const NavBar: FC<Props> = ({ currentPage }) => {
+const NavBar: FC = () => {
const { isDarkMode, toggleTheme } = useTheme()
const [mounted, setMounted] = useState(false)
const [mobileMenuOpen, setMobileMenuOpen] = useState(false)
@@ -27,6 +25,8 @@ const NavBar: FC<Props> = ({ currentPage }) => {
? pathSegments[pathSegments.indexOf(library) + 1]
: versions[0]
+ const pageType = getPageType(asPath)
+
useEffect(() => {
setMounted(true)
}, [isDarkMode])
@@ -96,7 +96,7 @@ const NavBar: FC<Props> = ({ currentPage }) => {
<Link href={p.link}>
<a
className={`text-sm ${
- currentPage.includes(p.key) ? 'text-brand-900' : 'text-scale-1100'
+ pageType.includes(p.key) ? 'text-brand-900' : 'text-scale-1100'
}`}
>
{p.text}
diff --git a/apps/docs/layouts/Default.tsx b/apps/docs/layouts/Default.tsx
index 7b7f4755b92..1bf04ebcf50 100644
--- a/apps/docs/layouts/Default.tsx
+++ b/apps/docs/layouts/Default.tsx
@@ -4,6 +4,9 @@ import NavBar from '../components/Navigation/NavBar'
import SideBar from '../components/Navigation/SideBar'
import Footer from '../components/Footer'
import TableOfContents from '~/components/TableOfContents'
+import { menuItems } from '~/components/Navigation/Navigation.constants'
+import { useRouter } from 'next/router'
+import { getPageType } from '~/lib/helpers'
interface Props {
meta: { title: string; description?: string; hide_table_of_contents?: boolean }
@@ -13,7 +16,9 @@ interface Props {
currentPage: string
}
-const Layout: FC<Props> = ({ meta, children, toc, menuItems, currentPage }) => {
+const Layout: FC<Props> = ({ meta, children, toc }) => {
+ const { asPath } = useRouter()
+
useEffect(() => {
const key = localStorage.getItem('supabaseDarkMode')
if (!key) {
@@ -27,6 +32,8 @@ const Layout: FC<Props> = ({ meta, children, toc, menuItems, currentPage }) => {
const hasTableOfContents =
toc !== undefined && toc.json.filter((item) => item.lvl !== 1 && item.lvl <= 3).length > 0
+ const pageType = getPageType(asPath)
+
return (
<>
<Head>
@@ -41,9 +48,9 @@ const Layout: FC<Props> = ({ meta, children, toc, menuItems, currentPage }) => {
</Head>
<main>
- <NavBar currentPage={currentPage} />
+ <NavBar />
<div className="flex w-full flex-row">
- <SideBar menuItems={menuItems} />
+ <SideBar menuItems={menuItems[pageType]} />
<div className="main-content-pane docs-width grid md:grid-cols-12 gap-4 justify-between p-4 pb-8 w-full">
<div
className={`${
diff --git a/apps/docs/layouts/DefaultLayout.tsx b/apps/docs/layouts/DefaultLayout.tsx
new file mode 100644
index 00000000000..fe682e44686
--- /dev/null
+++ b/apps/docs/layouts/DefaultLayout.tsx
@@ -0,0 +1,95 @@
+import { MDXProvider } from '@mdx-js/react'
+import Head from 'next/head'
+import { FC, useEffect } from 'react'
+import components from '~/components'
+import Footer from '~/components/Footer'
+import SideBar from '~/components/Navigation/SideBar'
+import TableOfContents from '~/components/TableOfContents'
+import NavBar from '~/components/Navigation/NavBar'
+
+interface Props {
+ meta: { title: string; description?: string; hide_table_of_contents?: boolean; video?: string }
+ children: any
+ toc?: any
+ menuItems: any
+ currentPage: string
+}
+
+const Layout: FC<Props> = (props: Props) => {
+ // const contentString = renderToString(props.children)
+
+ useEffect(() => {
+ const key = localStorage.getItem('supabaseDarkMode')
+ if (!key) {
+ // Default to dark mode if no preference config
+ document.documentElement.className = 'dark'
+ } else {
+ document.documentElement.className = key === 'true' ? 'dark' : ''
+ }
+ }, [])
+
+ // const contentString = renderToString(props.children)
+
+ // const content = serialize(contentString || '')
+
+ // console.log('contentString', contentString)
+
+ // const _toc = toc('#hello world', { maxdepth: 1, firsth1: false })
+
+ const hasTableOfContents =
+ props.toc !== undefined &&
+ props.toc.json.filter((item) => item.lvl !== 1 && item.lvl <= 3).length > 0
+
+ return (
+ <>
+ <Head>
+ <title>{props.meta?.title} | Supabase</title>
+ <meta name="description" content={props.meta?.description} />
+ <meta content="width=device-width, initial-scale=1" name="viewport" />
+ <link rel="icon" href="/docs/favicon.ico" />
+ <meta property="og:type" content="website" />
+ <meta property="og:site_name" content={props.meta?.title} />
+ <meta property="og:description" content={props.meta?.description} />
+ <meta property="og:title" content={props.meta?.title} />
+ </Head>
+
+ <main>
+ {/* <NavBar currentPage={currentPage} /> */}
+ <div className="flex w-full flex-row">
+ <NavBar currentPage={null} />
+ <SideBar menuItems={props.menuItems} />
+ <div className="main-content-pane docs-width grid md:grid-cols-12 gap-4 justify-between p-4 pb-8 w-full">
+ <div
+ className={`${
+ props.meta?.hide_table_of_contents || !hasTableOfContents
+ ? 'col-span-12 xl:col-start-2 xl:col-span-10 2xl:col-start-3 2xl:col-span-8'
+ : 'col-span-12 md:col-span-9'
+ } py-2 md:py-4 px-2 md:px-8`}
+ >
+ <p className="text-brand-900 tracking-wider">Tutorials</p>
+ <article className="prose dark:prose-dark dark:bg-scale-200 max-w-4xl mt-8">
+ <h1>{props.meta.title}</h1>
+ <div className="max-w-xs w-32 h-[1px] bg-gradient-to-r from-brand-800 to-brand-900 my-16"></div>
+
+ <MDXProvider components={components} children={props.children} />
+ </article>
+ </div>
+ {hasTableOfContents && !props.meta?.hide_table_of_contents && (
+ <div
+ className={[
+ 'border-scale-400 dark:bg-scale-200 table-of-contents-height border-l',
+ 'thin-scrollbar overflow-y-auto sticky hidden md:block md:col-span-3 px-2',
+ ].join(' ')}
+ >
+ <TableOfContents toc={props.toc} video={props.meta.video} />
+ </div>
+ )}
+ </div>
+ </div>
+ <Footer />
+ </main>
+ </>
+ )
+}
+
+export default Layout
diff --git a/apps/docs/pages/[...slug].tsx b/apps/docs/pages/[...slug].tsx
index e107b7e44aa..e5becdfe654 100644
--- a/apps/docs/pages/[...slug].tsx
+++ b/apps/docs/pages/[...slug].tsx
@@ -1,13 +1,10 @@
import toc from 'markdown-toc'
-import { MDXProvider } from '@mdx-js/react'
-import { useRouter } from 'next/router'
import { MDXRemote } from 'next-mdx-remote'
import { serialize } from 'next-mdx-remote/serialize'
import components from '../components/index'
-import { menuItems } from '../components/Navigation/Navigation.constants'
-import { getPageType } from '../lib/helpers'
-import { getAllDocs, getDocsBySlug } from '../lib/docs'
+
import Layout from '~/layouts/Default'
+import { getAllDocs, getDocsBySlug } from '../lib/docs'
interface Meta {
id: string
@@ -23,12 +20,9 @@ interface Props {
}
export default function Doc({ meta, content, toc }: Props) {
- const { asPath } = useRouter()
- const page = getPageType(asPath)
-
return (
// @ts-ignore
- <Layout meta={meta} toc={toc} menuItems={menuItems[page]} currentPage={page}>
+ <Layout meta={meta} toc={toc}>
<h1 className="text-7xl text-white">helo world</h1>
<MDXRemote {...content} components={components} />
</Layout>
diff --git a/apps/docs/pages/new/index.mdx b/apps/docs/pages/new/index.mdx
new file mode 100644
index 00000000000..1ea8a21f30a
--- /dev/null
+++ b/apps/docs/pages/new/index.mdx
@@ -0,0 +1,11 @@
+import Layout from '~/layouts/DefaultLayout'
+
+export const meta = {
+ title: 'Supabase Docs',
+}
+
+In this 25-minute guide, we’ll be building a collaborative user managment app using NextJS and Supabase.
+As users add and move rectangles in a canvas, changes will be automatically synced and persisted, allowing for a canvas that updates in real-time across clients.
+Users will also be able to see other users selections, and undo and redo actions.
+
+export default ({ children }) => <Layout meta={meta} children={children} />