Skip to content

Commit

Permalink
persisting scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
AlfieJones committed Jun 9, 2024
1 parent fa1ac48 commit cc665d0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
26 changes: 23 additions & 3 deletions apps/marketing-astro/src/pages/docs/[...path].astro
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ const sections = await getFiles();

<!-- DESKTOP NAVIGATION -->



<nav class="text-base md:text-sm h-[calc(100vh-4.5rem)] overflow-x-hidden -ml-0.5 py-16 pl-0.5 scrollbar-thin">
<nav
class="text-base md:text-sm h-[calc(100vh-4.5rem)] overflow-x-hidden -ml-0.5 py-16 pl-0.5 scrollbar-thin"
id="docs-sidebar-nav"
>
<ul role="list" class="space-y-9">
{
sections.map((section) => (
Expand Down Expand Up @@ -223,3 +224,22 @@ const sections = await getFiles();
</div>
</div>
</Root>

<script>
document.addEventListener("astro:before-swap", () => {
sessionStorage.setItem(
"docs-sidebar-nav-scroll",
document.getElementById("docs-sidebar-nav")!.scrollTop.toString()
);
});

document.addEventListener("astro:after-swap", () => {
const scroll = sessionStorage.getItem("docs-sidebar-nav-scroll");
if (scroll) {
document.getElementById("docs-sidebar-nav")!.scrollTo({
top: parseInt(scroll),
behavior: "instant",
});
}
});
</script>
10 changes: 7 additions & 3 deletions apps/marketing-astro/src/pages/docs/nextPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Link } from "@pixeleye/ui/src/link";
import { getFiles } from "./utils";
import { ArrowLeftIcon, ArrowRightIcon } from "@heroicons/react/24/outline";


Expand Down Expand Up @@ -40,7 +39,7 @@ function PageLink({



export async function PageNavigation(
export function PageNavigation(
{
currentPageURL
}: {
Expand All @@ -49,7 +48,12 @@ export async function PageNavigation(
}
) {

const sections = (await getFiles()).flatMap((group) => group.links)
// const sections = (await getFiles()).flatMap((group) => group.links)

const sections: {
title: string;
href: string;
}[] = []

let currentPageIndex = sections.findIndex((page) => page.href === currentPageURL)

Expand Down

0 comments on commit cc665d0

Please sign in to comment.