app: Drop persistent docs position.

This was very complicated, particularly between versions and tabs and windows, for something that offers only a minor convenience.

This also makes it simpler to navigate to a particular page interactively by just setting the iframe URL, which is useful for interactive help from the block editor.
This commit is contained in:
Laurens Valk
2026-03-30 14:24:24 +02:00
parent a09383de68
commit 2884825f4c
2 changed files with 2 additions and 60 deletions
+2 -5
View File
@@ -17,7 +17,7 @@ import StatusBar from '../status-bar/StatusBar';
import Toolbar from '../toolbar/Toolbar';
import Tour from '../tour/Tour';
import { isMacOS } from '../utils/os';
import { useAppLastDocsPageSetting } from './hooks';
import { docsDefaultPage } from './constants';
import { useI18n } from './i18n';
const Editor = React.lazy(async () => {
@@ -48,7 +48,6 @@ const Terminal = React.lazy(async () => {
const Docs: React.FunctionComponent = () => {
const { setIsSettingShowDocsEnabled } = useSettingIsShowDocsEnabled();
const { initialDocsPage, setLastDocsPage } = useAppLastDocsPageSetting();
return (
<iframe
@@ -80,10 +79,8 @@ const Docs: React.FunctionComponent = () => {
if (document.body.classList.contains(Classes.DARK)) {
contentWindow.document.documentElement.classList.add(Classes.DARK);
}
setLastDocsPage(contentWindow.location.href);
}}
src={initialDocsPage}
src={docsDefaultPage}
allowFullScreen={true}
width="100%"
height="100%"
-55
View File
@@ -1,55 +0,0 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
import { useEffect, useMemo } from 'react';
import { useLocalStorage, useSessionStorage } from 'usehooks-ts';
import { docsDefaultPage, docsPathPrefix, httpServerHeadersVersion } from './constants';
const defaultPage = `${docsDefaultPage}?v$${httpServerHeadersVersion}`;
export function useAppLastDocsPageSetting() {
const key = 'app.setting.lastDocsPage';
// last visited page is stored in local storage so that new windows get the
// last visited page
const [lastPageGlobalSetting, setLastPageGlobalSetting] = useLocalStorage(
key,
defaultPage,
);
// it is also stored in session storage in case two windows are open at the
// same time so that one window doesn't affect the other
const [lastPageSessionSetting, setLastPageSessionSetting] = useSessionStorage(
key,
lastPageGlobalSetting,
);
// mirror session storage value to local storage
useEffect(() => {
setLastPageGlobalSetting(lastPageSessionSetting);
}, [lastPageSessionSetting, setLastPageGlobalSetting]);
// the way the docs control works, we only provide the initial page, then
// it manages navigation after that, so we only want the initial of this
// value when the app first starts
const initialDocsPage = useMemo(
() => {
try {
const url = new URL(lastPageSessionSetting);
// in case someone is hacking the storage value directly
if (!url.pathname.startsWith(`/${docsPathPrefix}`)) {
throw new Error('invalid or outdated path');
}
return lastPageSessionSetting;
} catch {
return defaultPage;
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[], // no deps so that we only get the initial value
);
return { initialDocsPage, setLastDocsPage: setLastPageSessionSetting };
}