From feb88afb8c784e0db65be96073a1b0064e36128c Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 29 Aug 2022 18:00:08 +0200 Subject: fix: improve docs example (#4355) * fix: improve docs example * final touches * chore: prettier * lockfile * ci? * downgrade types node * fresh lockfile * lockfile and npmrc * remove debug log * Merge branch 'main' into docs-template-ts * merging lockfiles suck * update lockfile * satisfy linter --- .../src/components/RightSidebar/TableOfContents.tsx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'examples/docs/src/components/RightSidebar/TableOfContents.tsx') diff --git a/examples/docs/src/components/RightSidebar/TableOfContents.tsx b/examples/docs/src/components/RightSidebar/TableOfContents.tsx index 6348bdfd0..5c6851462 100644 --- a/examples/docs/src/components/RightSidebar/TableOfContents.tsx +++ b/examples/docs/src/components/RightSidebar/TableOfContents.tsx @@ -1,13 +1,18 @@ import type { FunctionalComponent } from 'preact'; -import { h, Fragment } from 'preact'; import { useState, useEffect, useRef } from 'preact/hooks'; -import { MarkdownHeading } from 'astro'; +import type { MarkdownHeading } from 'astro'; + +type ItemOffsets = { + id: string; + topOffset: number; +}; const TableOfContents: FunctionalComponent<{ headings: MarkdownHeading[] }> = ({ headings = [], }) => { - const itemOffsets = useRef([]); - const [activeId, setActiveId] = useState(undefined); + const itemOffsets = useRef([]); + // FIXME: Not sure what this state is doing. It was never set to anything truthy. + const [activeId] = useState(''); useEffect(() => { const getItemOffsets = () => { const titles = document.querySelectorAll('article :is(h1, h2, h3, h4)'); @@ -27,16 +32,16 @@ const TableOfContents: FunctionalComponent<{ headings: MarkdownHeading[] }> = ({ return ( <> -

On this page

+

On this page

    -
  • Overview
  • {headings .filter(({ depth }) => depth > 1 && depth < 4) .map((heading) => (