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
26 changes: 26 additions & 0 deletions components/NotionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,32 @@ export const NotionPage = ({
// };
// }, [maxScrollPercentage]);

// Add a function to handle smooth scrolling to elements
const scrollToHashElement = useCallback(() => {
const hash = window.location.hash;
if (hash) {
// Remove the # from the hash
const elementId = hash.slice(1);
const element = document.getElementById(elementId);
if (element) {
// Wait a bit for the content to render
setTimeout(() => {
element.scrollIntoView({ behavior: "smooth" });
}, 100);
}
}
}, []);

// Handle initial load and hash changes
useEffect(() => {
scrollToHashElement();
// Listen for hash changes
window.addEventListener("hashchange", scrollToHashElement);
return () => {
window.removeEventListener("hashchange", scrollToHashElement);
};
}, [scrollToHashElement]);

if (!recordMap) {
return null;
}
Expand Down
Loading