Improve chance simulator forecasts and tracking UI
All checks were successful
Deploy Sokko G / deploy (push) Successful in 18s
All checks were successful
Deploy Sokko G / deploy (push) Successful in 18s
This commit is contained in:
parent
1d278ff551
commit
6e64cfacd5
10 changed files with 534 additions and 101 deletions
|
|
@ -27,6 +27,7 @@ import {
|
|||
} from "../features/toolboxes/storage/toolboxStorage.js";
|
||||
|
||||
const LIBRARY_TOOLBOX_ID = "library";
|
||||
const LIBRARY_ANCHOR_RETRY_DELAYS = [0, 80, 240, 600];
|
||||
|
||||
const MODULE_COMPONENTS = {
|
||||
memos: lazy(() => import("../features/toolboxes/modules/MemosModule.jsx").then((module) => ({ default: module.MemosModule }))),
|
||||
|
|
@ -83,12 +84,23 @@ function getCurrentLibraryAnchor() {
|
|||
return match ? decodeURIComponent(match[1]) : "";
|
||||
}
|
||||
|
||||
function scrollToLibraryTool(anchorId, replace = false) {
|
||||
const element = document.getElementById(anchorId);
|
||||
if (!element) return;
|
||||
function getLibraryAnchorOffset() {
|
||||
const topbar = document.querySelector(".topbar");
|
||||
const topbarHeight = topbar?.getBoundingClientRect?.().height || 0;
|
||||
return topbarHeight + 16;
|
||||
}
|
||||
|
||||
function scrollToLibraryTool(anchorId, replace = false, behavior = "smooth") {
|
||||
if (!anchorId) return;
|
||||
if (replace) history.replaceState(null, "", `#/library#${encodeURIComponent(anchorId)}`);
|
||||
const top = element.getBoundingClientRect().top + window.scrollY - 24;
|
||||
window.scrollTo({ top: Math.max(0, top), behavior: "smooth" });
|
||||
LIBRARY_ANCHOR_RETRY_DELAYS.forEach((delay, index) => {
|
||||
window.setTimeout(() => {
|
||||
const element = document.getElementById(anchorId);
|
||||
if (!element) return;
|
||||
const top = element.getBoundingClientRect().top + window.scrollY - getLibraryAnchorOffset();
|
||||
window.scrollTo({ top: Math.max(0, top), behavior: index === 0 ? behavior : "auto" });
|
||||
}, delay);
|
||||
});
|
||||
}
|
||||
|
||||
function findCategoryForAnchor(categories, anchorId) {
|
||||
|
|
@ -149,7 +161,7 @@ export function LibraryPage({ siteContent, actions }) {
|
|||
const category = findCategoryForAnchor(libraryCategories, anchorId) || libraryCategories[0];
|
||||
setActiveCategoryKey(category.key);
|
||||
if (!anchorId) return;
|
||||
requestAnimationFrame(() => scrollToLibraryTool(anchorId));
|
||||
requestAnimationFrame(() => scrollToLibraryTool(anchorId, false, "auto"));
|
||||
}, [libraryPayload, libraryCategories]);
|
||||
|
||||
const moduleContext = useMemo(() => ({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue