From 91548d3b9fb0bd07648f70466c48ccc692af6623 Mon Sep 17 00:00:00 2001 From: YR Chen Date: Fri, 25 Oct 2024 19:54:00 +0800 Subject: [PATCH] feat(web): prefer `hide-ui` over `hide-ui=true` --- web/src/components/DocumentControlButtons.tsx | 10 ++++------ web/src/pages/Docs.tsx | 6 +++--- web/src/pages/IframePageNotFound.tsx | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/web/src/components/DocumentControlButtons.tsx b/web/src/components/DocumentControlButtons.tsx index 1971b07ba..22c1ef9a5 100644 --- a/web/src/components/DocumentControlButtons.tsx +++ b/web/src/components/DocumentControlButtons.tsx @@ -41,12 +41,10 @@ export default function DocumentControlButtons(props: Props): JSX.Element { url = url.replace(props.version, 'latest') } - if (shareModalHideUi && !url.includes('?hide-ui=true')) { - const urlObject = URL.parse(url) - if (urlObject !== null) { - urlObject.searchParams.set('hide-ui', 'true') - url = urlObject.toString() - } + if (shareModalHideUi) { + const urlObject = new URL(url) + urlObject.search = 'hide-ui' + url = urlObject.toString() } return url diff --git a/web/src/pages/Docs.tsx b/web/src/pages/Docs.tsx index 3b944cc37..a25ca7125 100644 --- a/web/src/pages/Docs.tsx +++ b/web/src/pages/Docs.tsx @@ -24,7 +24,7 @@ export default function Docs(): JSX.Element { const hash = useRef(location.hash) const [version, setVersion] = useState(params.version ?? 'latest') - const [hideUi, setHideUi] = useState(searchParams.get('hide-ui') === 'true') + const [hideUi, setHideUi] = useState(searchParams.get('hide-ui') === '' || searchParams.get('hide-ui') === 'true') const [iframeUpdateTrigger, setIframeUpdateTrigger] = useState(0) // This provides the url for the iframe. @@ -99,7 +99,7 @@ export default function Docs(): JSX.Element { hash: string, hideUi: boolean ): string => { - return `/${project}/${version}/${encodeURI(page)}${hash}${hideUi ? '?hide-ui=true' : ''}` + return `/${project}/${version}/${encodeURI(page)}${hash}${hideUi ? '?hide-ui' : ''}` } const updateUrl = (newVersion: string, hideUi: boolean): void => { @@ -159,7 +159,7 @@ export default function Docs(): JSX.Element { const urlVersion = params.version ?? 'latest' const urlPage = params['*'] ?? '' const urlHash = location.hash - const urlHideUi = searchParams.get('hide-ui') === 'true' + const urlHideUi = searchParams.get('hide-ui') === '' || searchParams.get('hide-ui') === 'true' // update the state to the url params on first loadon if (urlProject !== project.current) { diff --git a/web/src/pages/IframePageNotFound.tsx b/web/src/pages/IframePageNotFound.tsx index df5c05d50..4ea34be46 100644 --- a/web/src/pages/IframePageNotFound.tsx +++ b/web/src/pages/IframePageNotFound.tsx @@ -11,7 +11,7 @@ interface Props { } export default function IframeNotFound(props: Props): JSX.Element { - const link = `/${props.project}/${props.version}${props.hideUi ? '?hide-ui=true' : ''}` + const link = `/${props.project}/${props.version}${props.hideUi ? '?hide-ui' : ''}` return (