diff --git a/apps/docs/layouts/ref/RefSubLayout.tsx b/apps/docs/layouts/ref/RefSubLayout.tsx index fccc89c3340..972c1c6986a 100644 --- a/apps/docs/layouts/ref/RefSubLayout.tsx +++ b/apps/docs/layouts/ref/RefSubLayout.tsx @@ -1,4 +1,6 @@ -import { FC } from 'react' +import { useInView } from 'react-intersection-observer' +import { FC, useEffect, useState } from 'react' +import { useRouter } from 'next/router' interface ISectionContainer extends FC { id: string @@ -12,6 +14,12 @@ type RefSubLayoutSubComponents = { Examples: ISectionExamples } +type StickyHeader = { + id: string + title: string + monoFont: boolean +} + type RefSubLayoutType = {} const RefSubLayout: FC & RefSubLayoutSubComponents = (props) => { @@ -24,23 +32,37 @@ const RefSubLayout: FC & RefSubLayoutSubComponents = (props) = ) } -const Section: FC = (props) => { +const Section: FC = ({ id, title, monoFont, children }) => { return ( -
-
-

- {props.title} -

-
-
{props.children}
+
+ +
{children}
) } +const StickyHeader: FC = ({ id, title, monoFont }) => { + const router = useRouter() + + const { ref } = useInView({ + threshold: 1, + rootMargin: '-20% 0% -35% 0px', + onChange: (inView, entry) => { + //console.log('zans', 'running') + //if (inView) router.push(entry.target.id, undefined, { shallow: true }) + }, + }) + + return ( +

+ {title} +

+ ) +} + interface ISectionDetails extends FC {} const Details: FC = (props: any) => { diff --git a/apps/docs/pages/new/reference/javascript/[...slug].tsx b/apps/docs/pages/new/reference/javascript/[...slug].tsx index 2a40f4fb0e1..8cc6efafc85 100644 --- a/apps/docs/pages/new/reference/javascript/[...slug].tsx +++ b/apps/docs/pages/new/reference/javascript/[...slug].tsx @@ -1,16 +1,10 @@ -import { - useEffect, - // useRef, - useState, -} from 'react' -// pages/index.js +import { useEffect } from 'react' import fs from 'fs' import matter from 'gray-matter' import { MDXRemote } from 'next-mdx-remote' import { serialize } from 'next-mdx-remote/serialize' -import remarkGfm from 'remark-gfm' import components from '~/components/index' import { getAllDocs } from '~/lib/docs' @@ -29,49 +23,19 @@ import CodeBlock from '~/components/CodeBlock/CodeBlock' import { useRouter } from 'next/router' import { extractTsDocNode, generateParameters } from '~/lib/refGenerator/helpers' import { ComesFrom } from '~/components/ComesFrom' -import Link from 'next/link' import Param from '~/components/Params' import Options from '~/components/Options' import RefSubLayout from '~/layouts/ref/RefSubLayout' export default function JSReference(props) { - // const myRef = useRef(null) - - //console.log('props', props) - // console.log({ jsSpec }) - - const [offsetY, setOffsetY] = useState(0) - const [sections, setSections] = useState([]) + const router = useRouter() + const slug = router.query.slug[0] useEffect(() => { - const els: HTMLElement[] = Array.from(document.querySelectorAll('div.ref-container')) - - const allSections = els.map((el: HTMLElement, index: number) => { - const { top: boundingTop } = el.getBoundingClientRect() - - return { - topic: el.getAttribute('id')!, - boundingTop, - isActive: index === 0, - } - }) - - // console.log('allSections', allSections) - setSections(allSections) - }, []) - - const router = useRouter() - - function updateUrl(key) { - router.replace( - { - pathname: `/ref/js/${key}`, - // query: { sortBy: 'price' }, - }, - undefined, - { scroll: false } - ) - } + if (document && slug !== 'start') { + document.querySelector(`#${slug}`).scrollIntoView() + } + }) return ( @@ -80,8 +44,6 @@ export default function JSReference(props) { const tsDefinition = hasTsRef && extractTsDocNode(hasTsRef, jsTypeSpec) const parameters = hasTsRef ? generateParameters(tsDefinition) : '' - // console.log(`parameters ${item.title}`, parameters) - const functionMarkdownContent = props?.docs[itemIndex]?.content const shortText = hasTsRef ? tsDefinition.signatures[0].comment.shortText : '' @@ -100,63 +62,34 @@ export default function JSReference(props) { <>
- {/*

updateUrl(item.id)} - > - {examples.functions[itemIndex].title ?? - examples.functions[itemIndex].id ?? - item.name ?? - item.id} -

*/} {shortText && ( <>

- {/* */} )}
{item.description && (
- {/* */}

{item.description}

)} {functionMarkdownContent && (
- {/* */}
)} {item.notes && (
- {/* */} {item.notes}
)} {/* // parameters */} {parameters && (
- {/* */}
Parameters
    {parameters.map((param) => { @@ -185,7 +118,6 @@ export default function JSReference(props) { ) })}
- {/*
*/}
)} @@ -225,26 +157,6 @@ const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key {tables && tables.length > 0 && tables.map((table) => { - // console.log(table) - - // @ts-ignore - // const [content, setContent] = useState(null) - - // // @ts-ignore - // useEffect(() => { - // async function makeContent() { - // setContent( - // await serialize(table.content, { - // mdxOptions: { - // remarkPlugins: [remarkGfm], - // format: 'mdx', - // }, - // }) - // ) - // } - // makeContent() - // }, []) - return (
@@ -255,9 +167,6 @@ const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key
{table.name}
- - {/* {table.content} */} - {/* {content && } */} ) })} @@ -315,7 +224,6 @@ const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key export async function getStaticProps({ params }: { params: { slug: string[] } }) { const pages = jsSpec.functions.map((x) => x.id) - // console.log('pages', pages) /** * Read all the markdown files that might have @@ -325,10 +233,6 @@ export async function getStaticProps({ params }: { params: { slug: string[] } }) */ const allMarkdownDocs = await Promise.all( pages.map(async (x, i) => { - // const doc = getDocsBySlug(`docs/ref/database/${x}`) - - // if (i >= 5) return null - const pathName = `docs/ref/js/${x}.mdx` function checkFileExists(x) { @@ -346,10 +250,7 @@ export async function getStaticProps({ params }: { params: { slug: string[] } }) const fileContents = markdownExists ? fs.readFileSync(pathName, 'utf8') : '' const { data, content } = matter(fileContents) - // console.log('docBySlug', content) - // console.log() - // if (content) console.log(content) return { id: x, title: x, @@ -360,8 +261,6 @@ export async function getStaticProps({ params }: { params: { slug: string[] } }) }) ) - // console.log('allMarkdownDocs', allMarkdownDocs) - return { props: { docs: allMarkdownDocs,