From 9fd7b58f2e197d73f9242dba6fb9921e02eeba7a Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Wed, 13 Nov 2024 17:40:45 +0200 Subject: [PATCH] docs: improv version detection + fix breadcrumbs --- www/apps/book/sidebar.mjs | 8 ++++---- www/apps/book/types/index.d.ts | 1 - .../docs-ui/src/components/Breadcrumbs/index.tsx | 11 ++++++++--- .../src/components/MainNav/Version/index.tsx | 15 ++++++--------- www/packages/docs-ui/src/global-config.ts | 2 +- www/packages/types/src/sidebar.ts | 1 + 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/www/apps/book/sidebar.mjs b/www/apps/book/sidebar.mjs index af6d52d3ec39d..e0dcb359294ba 100644 --- a/www/apps/book/sidebar.mjs +++ b/www/apps/book/sidebar.mjs @@ -523,8 +523,8 @@ export const sidebar = numberSidebarItems( { type: "link", title: "Environment Variables", - path: "/learn/advanced-development/environment-variables" - } + path: "/learn/advanced-development/environment-variables", + }, ], }, { @@ -607,8 +607,8 @@ export const sidebar = numberSidebarItems( type: "link", path: "/learn/deployment/general", title: "General Deployment", - } - ] + }, + ], }, { type: "link", diff --git a/www/apps/book/types/index.d.ts b/www/apps/book/types/index.d.ts index 73bc06a87f99a..3934655afd10e 100644 --- a/www/apps/book/types/index.d.ts +++ b/www/apps/book/types/index.d.ts @@ -3,7 +3,6 @@ import { SidebarSectionItems, SidebarItem as SidebarItemType } from "types" export declare type SidebarItem = SidebarItemType & { isSoon: boolean number?: string - chapterTitle?: string } export declare type SidebarConfig = SidebarSectionItems diff --git a/www/packages/docs-ui/src/components/Breadcrumbs/index.tsx b/www/packages/docs-ui/src/components/Breadcrumbs/index.tsx index a643b7b5c6d47..4c5476abef5e5 100644 --- a/www/packages/docs-ui/src/components/Breadcrumbs/index.tsx +++ b/www/packages/docs-ui/src/components/Breadcrumbs/index.tsx @@ -50,7 +50,10 @@ export const Breadcrumbs = () => { tempBreadcrumbItems.set( breadcrumbPath, - item.parentItem?.childSidebarTitle || item.parentItem?.title || "" + item.parentItem?.childSidebarTitle || + item.parentItem?.chapterTitle || + item.parentItem?.title || + "" ) return tempBreadcrumbItems @@ -76,12 +79,14 @@ export const Breadcrumbs = () => { sidebarActiveItem.parentItem.type === "link" ? getLinkPath(sidebarActiveItem.parentItem) || "#" : "#", - sidebarActiveItem.parentItem.title || "" + sidebarActiveItem.parentItem.chapterTitle || + sidebarActiveItem.parentItem.title || + "" ) } tempBreadcrumbItems.set( getLinkPath(sidebarActiveItem) || "/", - sidebarActiveItem.title || "" + sidebarActiveItem.chapterTitle || sidebarActiveItem.title || "" ) } diff --git a/www/packages/docs-ui/src/components/MainNav/Version/index.tsx b/www/packages/docs-ui/src/components/MainNav/Version/index.tsx index f9e4380aa19f5..b4e37c81a5ce9 100644 --- a/www/packages/docs-ui/src/components/MainNav/Version/index.tsx +++ b/www/packages/docs-ui/src/components/MainNav/Version/index.tsx @@ -1,12 +1,12 @@ "use state" -import React, { useEffect, useMemo, useState } from "react" +import React, { useEffect, useState } from "react" import { useIsBrowser, useSiteConfig } from "../../../providers" import Link from "next/link" import { Tooltip } from "../../Tooltip" import clsx from "clsx" -const LOCAL_STORAGE_SUFFIX = "-seen" +const LOCAL_STORAGE_SUFFIX = "last-version" export const MainNavVersion = () => { const { @@ -14,20 +14,17 @@ export const MainNavVersion = () => { } = useSiteConfig() const [showNewBadge, setShowNewBadge] = useState(false) const { isBrowser } = useIsBrowser() - const localStorageKey = useMemo( - () => `${version.number}${LOCAL_STORAGE_SUFFIX}`, - [version] - ) useEffect(() => { if (!isBrowser) { return } - if (!localStorage.getItem(localStorageKey)) { + const storedVersion = localStorage.getItem(LOCAL_STORAGE_SUFFIX) + if (storedVersion !== version.number) { setShowNewBadge(true) } - }, [isBrowser, localStorageKey]) + }, [isBrowser]) const afterHover = () => { if (!showNewBadge) { @@ -35,7 +32,7 @@ export const MainNavVersion = () => { } setShowNewBadge(false) - localStorage.setItem(localStorageKey, "true") + localStorage.setItem(LOCAL_STORAGE_SUFFIX, version.number) } return ( diff --git a/www/packages/docs-ui/src/global-config.ts b/www/packages/docs-ui/src/global-config.ts index 8955e5243a3bc..40bd4591dbbc1 100644 --- a/www/packages/docs-ui/src/global-config.ts +++ b/www/packages/docs-ui/src/global-config.ts @@ -7,4 +7,4 @@ export const globalConfig: Pick = { "number": "2.0.4", "releaseUrl": "https://github.com/medusajs/medusa/releases/tag/v2.0.4" } -} \ No newline at end of file +} diff --git a/www/packages/types/src/sidebar.ts b/www/packages/types/src/sidebar.ts index 0a3f71612b6de..156bee79114c4 100644 --- a/www/packages/types/src/sidebar.ts +++ b/www/packages/types/src/sidebar.ts @@ -11,6 +11,7 @@ export type SidebarItemCommon = { childSidebarTitle?: string loaded?: boolean additionalElms?: React.ReactNode + chapterTitle?: string } export type SidebarItemLink = SidebarItemCommon & {