Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions apps/landing/src/components/table-of-contents/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { createContext, useContext, useEffect, useMemo, useState } from 'react'
export interface Content {
label: string
value: string
pathname: string
}

function sortContentsByDomOrder(items: Content[]): Content[] {
Expand Down Expand Up @@ -44,13 +45,15 @@ export function TableOfContentsProvider({
children: React.ReactNode
}) {
const pathname = usePathname()
const [contents, setContents] = useState<{ label: string; value: string }[]>(
const [contents, setContents] = useState<Content[]>([])
const [intersectingContents, setIntersectingContents] = useState<Content[]>(
[],
)

const [intersectingContents, setIntersectingContents] = useState<
{ label: string; value: string }[]
>([])
if (intersectingContents.some((content) => content.pathname !== pathname)) {
setIntersectingContents((prev) =>
prev.filter((content) => content.pathname === pathname),
)
}

const highlightedContent = intersectingContents[0] ?? null

Expand All @@ -62,6 +65,7 @@ export function TableOfContentsProvider({
const item = {
label: entry.target.innerText ?? '',
value: entry.target.id ?? '',
pathname: pathname ?? '',
}
setContents((prev) =>
prev.some((content) => content.value === item.value)
Expand All @@ -81,7 +85,7 @@ export function TableOfContentsProvider({
}
})
})
}, [])
}, [pathname])

useEffect(() => {
if (!io) return
Expand Down
Loading