Skip to content

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

Redo nav menu items object

Terry Suttonaa3e5b812272
diff --git a/apps/temp-docs/components/nav/SideBar.tsx b/apps/temp-docs/components/nav/SideBar.tsx
index 49e09de4c60..f505ba75a0a 100644
--- a/apps/temp-docs/components/nav/SideBar.tsx
+++ b/apps/temp-docs/components/nav/SideBar.tsx
@@ -3,68 +3,27 @@ import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'
import { IconChevronRight } from '~/../../packages/ui'
-const SideBar = ({ menuItems }: { menuItems: any }) => {
- console.log(Object.keys(menuItems))
-
- // The currently active second-level item in menuItems
- // ie: ['Overview', 'Tutorials', 'See Also', 'etc']
- // derive the state on the first run based on the asPath in the router
- //const [activeParentMenuItem, setActiveParentMenuItem] = useState()
+const SideBar = ({ menuItems: passedMenuItems }: { menuItems: any }) => {
+ const [menuItems, setMenuItems] = useState(passedMenuItems)
+ console.log('sidebar', menuItems)
const { asPath } = useRouter()
- function handleParentMenuToggle(e) {
- const toggleButton = e.target
- const sidebarMenu = document.querySelector('.sidebar-menu-container')
-
- // Close all parent menus
- const parentMenus = sidebarMenu.querySelectorAll('.parent-menu')
- parentMenus.forEach((menu) => menu.classList.add('hidden'))
-
- // Remove all active buttons
- const activeButtons = sidebarMenu.querySelectorAll('button.active')
- activeButtons.forEach((menu) => menu.classList.remove('active'))
-
- // Open the parent menu that's just been clicked
- const closestGroup = toggleButton.closest('.parent-menu-container')
- toggleButton.classList.add('active')
- const subMenu = closestGroup.querySelector('.parent-menu')
- subMenu.classList.contains('hidden')
- ? subMenu.classList.remove('hidden')
- : subMenu.classList.add('hidden')
- }
-
- function handleSubMenuToggle(e) {
- const toggleButton = e.target
- const closestGroup = toggleButton.closest('.sub-menu-group')
- // Remove all active buttons
- const activeButtons = closestGroup.querySelectorAll('button.active')
- activeButtons.forEach((menu) => menu.classList.remove('active'))
-
- // Open the parent menu that's just been clicked
- toggleButton.classList.add('active')
- const subMenu = closestGroup.querySelector('.sub-menu')
- subMenu.classList.contains('hidden')
- ? subMenu.classList.remove('hidden')
- : subMenu.classList.add('hidden')
- }
+ function toggleMenuItem(label: string) {
+ const newMenuItems = menuItems.map((item: any) => {
+ // see if the item has grandchildren
- const isMenuActive = (key) => {
- // check if main items have .some()
- if (menuItems[key].some((item) => item.link === asPath)) {
- return true
- }
+ // collapse all first
+ item.collapsed = true
- // check if sub items (sections) have .some()
- if (menuItems[key].some((item) => item.sections?.length > 0)) {
- if (
- menuItems[key].some((item) => item.sections?.some((section) => section.link === asPath))
- ) {
- return true
+ // then grab the one that matches the label and invert it
+ if (item.label === label) {
+ return { ...item, collapsed: !item.collapsed }
}
- }
- return false
+ return item
+ })
+ setMenuItems(newMenuItems)
}
return (
@@ -73,35 +32,61 @@ const SideBar = ({ menuItems }: { menuItems: any }) => {
h-screen overflow-y-scroll border-r py-10 px-6 sidebar-menu-container"
>
<ul className="w-full flex-col gap-12 mb-8">
- {Object.keys(menuItems).map((key, i) => (
+ {menuItems.map((item) => (
+ <li className="mt-1">
+ <button onClick={(e) => toggleMenuItem(item.label)} className="flex items-center">
+ <IconChevronRight /> {item.label}
+ </button>
+ <ul className={`mb-8 ml-5 text-sm ${item.collapsed ? 'hidden' : ''}`}>
+ {item.items.map((child) => (
+ <li>
+ {child.items ? (
+ <div>
+ <button
+ className="flex items-center"
+ onClick={(e) => toggleMenuItem(child.label)}
+ >
+ <IconChevronRight />
+ {child.label}
+ </button>
+ <ul className={`mb-4 mt-2 ml-2 ${child.collapsed ? 'hidden' : ''}`}>
+ {child.items.map((grandchild) => (
+ <li>{grandchild}</li>
+ ))}
+ </ul>
+ </div>
+ ) : (
+ child
+ )}
+ </li>
+ ))}
+ </ul>
+ </li>
+ ))}
+ {/* {Object.keys(menuItems).map((key, i) => (
<li key={key} className="mb-8 bg-gray-200 parent-menu-container">
<button
- onClick={(e) => handleParentMenuToggle(e)}
+ onClick={(e) => console.log('hay')}
className={[
'parent-menu-toggle text-sm bg-gray-500 flex items-center gap-1',
- isMenuActive(key) ? 'active' : '',
+ 2 > 1 ? 'active' : '',
].join(' ')}
>
<IconChevronRight size="tiny" strokeWidth="0.75" />
{key}
</button>
- <ul className={['parent-menu mt-4', isMenuActive(key) ? '' : 'hidden'].join(' ')}>
+ <ul className={['parent-menu mt-4', 2 > 1 ? '' : 'hidden'].join(' ')}>
{menuItems[key].map((item) =>
Array.isArray(item.sections) ? (
<div className="sub-menu-group ml-4">
<button
- onClick={(e) => handleSubMenuToggle(e)}
+ onClick={(e) => console.log()}
className="parent-menu-toggle text-sm bg-gray-500 flex items-center gap-1"
>
<IconChevronRight size="tiny" strokeWidth="0.75" />
{item.text}
</button>
- <ul
- className={[
- 'bg-gray-300 sub-menu ml-5',
- isMenuActive(key) ? 'hidden' : '',
- ].join(' ')}
- >
+ <ul className={['bg-gray-300 sub-menu ml-5', 2 > 1 ? 'hidden' : ''].join(' ')}>
{item.sections.map((menuItem) => (
<li>
<Link href={menuItem.link}>
@@ -125,7 +110,7 @@ const SideBar = ({ menuItems }: { menuItems: any }) => {
)}
</ul>
</li>
- ))}
+ ))} */}
</ul>
</div>
)
diff --git a/apps/temp-docs/components/nav/menu-items-reduced.js b/apps/temp-docs/components/nav/menu-items-reduced.js
new file mode 100644
index 00000000000..fac7e30122a
--- /dev/null
+++ b/apps/temp-docs/components/nav/menu-items-reduced.js
@@ -0,0 +1,319 @@
+export const menuItems = {
+ Docs: [
+ {
+ type: 'category',
+ label: 'Overview',
+ collapsed: true,
+ items: ['about', 'guides/features', 'architecture'],
+ },
+ {
+ type: 'category',
+ label: 'Quickstarts',
+ collapsed: true,
+ items: [
+ 'guides/with-angular',
+ 'guides/with-expo',
+ 'guides/with-flutter',
+ 'guides/with-ionic-angular',
+ 'guides/with-ionic-react',
+ 'guides/with-ionic-vue',
+ 'guides/with-nextjs',
+ 'guides/with-nuxt-3',
+ 'guides/with-react',
+ 'guides/with-redwoodjs',
+ 'guides/with-solidjs',
+ 'guides/with-svelte',
+ 'guides/with-sveltekit',
+ 'guides/with-vue-3',
+ ],
+ },
+ {
+ type: 'category',
+ label: 'CLI',
+ collapsed: true,
+ items: ['guides/cli', 'guides/cli/local-development', 'guides/cli/managing-environments'],
+ },
+ {
+ type: 'category',
+ label: 'Auth',
+ collapsed: true,
+ items: [
+ 'guides/auth',
+ {
+ type: 'category',
+ label: 'Authentication',
+ collapsed: true,
+ items: [
+ 'guides/auth/auth-email',
+ 'guides/auth/auth-magic-link',
+ 'guides/auth/auth-apple',
+ 'guides/auth/auth-azure',
+ 'guides/auth/auth-bitbucket',
+ 'guides/auth/auth-discord',
+ 'guides/auth/auth-facebook',
+ 'guides/auth/auth-github',
+ 'guides/auth/auth-gitlab',
+ 'guides/auth/auth-google',
+ 'guides/auth/auth-keycloak',
+ 'guides/auth/auth-linkedin',
+ 'guides/auth/auth-notion',
+ 'guides/auth/auth-slack',
+ 'guides/auth/auth-spotify',
+ 'guides/auth/auth-twitch',
+ 'guides/auth/auth-twitter',
+ 'guides/auth/auth-workos',
+ 'guides/auth/auth-zoom',
+ 'guides/auth/auth-twilio',
+ 'guides/auth/auth-vonage',
+ 'guides/auth/auth-messagebird',
+ ],
+ },
+ {
+ type: 'category',
+ label: 'Authorization',
+ collapsed: true,
+ items: [
+ 'guides/auth/row-level-security',
+ 'guides/auth/managing-user-data',
+ 'guides/auth/auth-captcha',
+ 'guides/auth/server-side-rendering',
+ 'guides/auth/auth-mfa',
+ ],
+ },
+ {
+ type: 'category',
+ label: 'Auth Helpers',
+ collapsed: true,
+ items: [
+ 'guides/auth/auth-helpers/index',
+ 'guides/auth/auth-helpers/auth-ui',
+ 'guides/auth/auth-helpers/nextjs',
+ 'guides/auth/auth-helpers/sveltekit',
+ ],
+ },
+ {
+ type: 'category',
+ label: 'Deep Dive',
+ collapsed: true,
+ items: [
+ 'learn/auth-deep-dive/auth-deep-dive-jwts',
+ 'learn/auth-deep-dive/auth-row-level-security',
+ 'learn/auth-deep-dive/auth-policies',
+ 'learn/auth-deep-dive/auth-gotrue',
+ 'learn/auth-deep-dive/auth-google-oauth',
+ ],
+ },
+ ],
+ },
+ {
+ type: 'category',
+ label: 'APIs',
+ collapsed: true,
+ items: ['guides/api', 'guides/api/generating-types'],
+ },
+ {
+ type: 'category',
+ label: 'Database',
+ collapsed: true,
+ items: [
+ 'guides/database',
+ 'guides/database/connecting-to-postgres',
+ 'guides/database/tables',
+ 'guides/database/functions',
+ 'guides/database/full-text-search',
+ 'guides/database/migrating-between-projects',
+ // 'guides/database/json',
+ // 'guides/database/arrays',
+ // 'guides/database/sql-to-api',
+ {
+ type: 'category',
+ label: 'Extensions',
+ collapsed: true,
+ items: [
+ 'guides/database/extensions',
+ 'guides/database/extensions/plv8',
+ 'guides/database/extensions/http',
+ 'guides/database/extensions/pgtap',
+ 'guides/database/extensions/uuid-ossp',
+ ],
+ },
+ {
+ type: 'category',
+ label: 'Configuration',
+ collapsed: true,
+ items: [
+ 'guides/database/timeouts',
+ 'guides/database/replication',
+ 'guides/database/managing-passwords',
+ 'guides/database/managing-timezones',
+ ],
+ },
+ ],
+ },
+ {
+ type: 'category',
+ label: 'Edge Functions',
+ collapsed: true,
+ items: [
+ 'guides/functions',
+ 'guides/functions/auth',
+ 'guides/functions/examples',
+ 'guides/functions/cicd-workflow',
+ ],
+ },
+ {
+ type: 'category',
+ label: 'Realtime',
+ collapsed: true,
+ items: ['guides/realtime', 'guides/realtime/quickstart', 'guides/realtime/postgres-cdc'],
+ },
+ {
+ type: 'category',
+ label: 'Storage',
+ collapsed: true,
+ items: ['guides/storage', 'guides/storage-cdn'],
+ },
+ {
+ type: 'category',
+ label: 'Platform',
+ collapsed: true,
+ items: [
+ 'guides/hosting/platform',
+ 'guides/platform/custom-domains',
+ 'guides/platform/disk-usage',
+ 'guides/platform/logs',
+ 'guides/platform/metrics',
+ 'guides/platform/performance',
+ 'guides/platform/permissions',
+ 'going-into-prod',
+ ],
+ },
+ {
+ type: 'category',
+ label: 'Self Hosting',
+ collapsed: true,
+ items: ['guides/hosting/overview', 'guides/hosting/docker'],
+ },
+ {
+ type: 'category',
+ label: 'Migrate to Supabase',
+ collapsed: true,
+ items: [
+ 'guides/migrations/firebase-auth',
+ 'guides/migrations/firestore-data',
+ 'guides/migrations/firebase-storage',
+ 'guides/migrations/heroku',
+ ],
+ },
+ {
+ type: 'category',
+ label: 'Integrations',
+ collapsed: true,
+ items: [
+ 'guides/integrations/integrations',
+ {
+ type: 'category',
+ label: 'Auth',
+ collapsed: true,
+ items: [
+ 'guides/integrations/auth0',
+ 'guides/integrations/authsignal',
+ 'guides/integrations/clerk',
+ 'guides/integrations/keyri',
+ 'guides/integrations/stytch',
+ 'guides/integrations/supertokens',
+ ],
+ },
+ {
+ type: 'category',
+ label: 'Caching / Offline-first',
+ collapsed: true,
+ items: ['guides/integrations/polyscale'],
+ },
+ {
+ type: 'category',
+ label: 'Developer Tools',
+ collapsed: true,
+ items: [
+ 'guides/integrations/pgmustard',
+ 'guides/integrations/prisma',
+ 'guides/integrations/sequin',
+ 'guides/integrations/snaplet',
+ 'guides/integrations/vercel',
+ ],
+ },
+ {
+ type: 'category',
+ label: 'Low-code',
+ collapsed: true,
+ items: [
+ 'guides/integrations/appsmith',
+ 'guides/integrations/dashibase',
+ 'guides/integrations/dhiwise',
+ 'guides/integrations/directus',
+ 'guides/integrations/draftbit',
+ 'guides/integrations/plasmic',
+ ],
+ },
+ ],
+ },
+ ],
+ reference: [
+ {
+ type: 'category',
+ label: 'Official',
+ // link: { type: 'doc', id: 'reference' },
+ collapsed: false,
+ items: [
+ { type: 'doc', id: 'reference' },
+ {
+ type: 'link',
+ label: 'Supabase JavaScript Library',
+ href: '/reference/javascript/',
+ },
+ {
+ type: 'link',
+ label: 'Supabase Flutter Library',
+ href: '/reference/dart',
+ },
+ { type: 'link', label: 'Supabase CLI', href: '/reference/cli' },
+ { type: 'link', label: 'Supabase API', href: '/reference/api' },
+ ],
+ },
+ // TODO: add back in with typedocs
+ // {
+ // type: 'category',
+ // label: 'Community',
+ // // link: { type: 'doc', id: 'about' },
+ // collapsed: false,
+ // items: [
+ // {
+ // type: 'link',
+ // label: 'Supabase Auth Helpers',
+ // href: '/reference/auth-helpers',
+ // },
+ // ],
+ // },
+ {
+ type: 'category',
+ label: 'Self-hosting',
+ collapsed: false,
+ items: [
+ { type: 'link', label: 'Auth Server', href: '/reference/auth' },
+ { type: 'link', label: 'Storage Server', href: '/reference/storage' },
+ ],
+ },
+ // {
+ // type: 'category',
+ // label: 'Postgres Extensions',
+ // link: { type: 'doc', id: 'postgres/extensions/intro' },
+ // collapsed: true,
+ // items: [
+ // 'postgres/extensions/http',
+ // 'postgres/extensions/pgtap',
+ // 'postgres/extensions/plv8',
+ // 'postgres/extensions/uuid-ossp',
+ // ],
+ // },
+ ],
+}
diff --git a/apps/temp-docs/layouts/Default.tsx b/apps/temp-docs/layouts/Default.tsx
index a6dd30aeb14..9b430714ccd 100644
--- a/apps/temp-docs/layouts/Default.tsx
+++ b/apps/temp-docs/layouts/Default.tsx
@@ -27,6 +27,8 @@ const Layout = ({
}
}, [])
+ console.log('default')
+
return (
<>
<Head>
diff --git a/apps/temp-docs/pages/[...slug].tsx b/apps/temp-docs/pages/[...slug].tsx
index 67d4dd39425..4a29e4db5d6 100644
--- a/apps/temp-docs/pages/[...slug].tsx
+++ b/apps/temp-docs/pages/[...slug].tsx
@@ -4,7 +4,7 @@ import { serialize } from 'next-mdx-remote/serialize'
import { MDXRemote } from 'next-mdx-remote'
import { MDXProvider } from '@mdx-js/react'
import components from '../components/index'
-import menuItems from '../components/nav/menu-items.json'
+import { menuItems } from '../components/nav/menu-items-reduced'
import { useRouter } from 'next/router'
// table of contents extractor
@@ -36,6 +36,7 @@ export default function Doc({
page = 'Docs'
break
}
+ console.log('slug')
return (
// @ts-ignore
diff --git a/apps/temp-docs/pages/index.tsx b/apps/temp-docs/pages/index.tsx
index f2e81ba28f0..ab9582018d7 100644
--- a/apps/temp-docs/pages/index.tsx
+++ b/apps/temp-docs/pages/index.tsx
@@ -2,7 +2,8 @@ import { MDXProvider } from '@mdx-js/react'
import { MDXRemote } from 'next-mdx-remote'
import { serialize } from 'next-mdx-remote/serialize'
import components from '~/components'
-import menuItems from '~/components/nav/menu-items.json'
+import { menuItems } from '~/components/nav/menu-items-reduced'
+
import Layout from '~/layouts/Default'
import { getDocsBySlug } from '../lib/docs'
export default function Home({
@@ -12,6 +13,7 @@ export default function Home({
meta: { title: string; description: string }
content: any
}) {
+ console.log({ menuItems }, 'index')
return (
<Layout meta={meta} menuItems={menuItems['Docs']} currentPage="Docs">
<MDXProvider components={components}>