Skip to content

Commit

Permalink
docs: improv version detection + fix breadcrumbs (#10083)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahednasser authored Nov 13, 2024
1 parent c054f47 commit 0ea5765
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
8 changes: 4 additions & 4 deletions www/apps/book/sidebar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
],
},
{
Expand Down Expand Up @@ -607,8 +607,8 @@ export const sidebar = numberSidebarItems(
type: "link",
path: "/learn/deployment/general",
title: "General Deployment",
}
]
},
],
},
{
type: "link",
Expand Down
1 change: 0 additions & 1 deletion www/apps/book/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 8 additions & 3 deletions www/packages/docs-ui/src/components/Breadcrumbs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 || ""
)
}

Expand Down
15 changes: 6 additions & 9 deletions www/packages/docs-ui/src/components/MainNav/Version/index.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,38 @@
"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 {
config: { version },
} = 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) {
return
}

setShowNewBadge(false)
localStorage.setItem(localStorageKey, "true")
localStorage.setItem(LOCAL_STORAGE_SUFFIX, version.number)
}

return (
Expand Down
2 changes: 1 addition & 1 deletion www/packages/docs-ui/src/global-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export const globalConfig: Pick<DocsConfig, "version"> = {
"number": "2.0.4",
"releaseUrl": "https://github.com/medusajs/medusa/releases/tag/v2.0.4"
}
}
}
1 change: 1 addition & 0 deletions www/packages/types/src/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type SidebarItemCommon = {
childSidebarTitle?: string
loaded?: boolean
additionalElms?: React.ReactNode
chapterTitle?: string
}

export type SidebarItemLink = SidebarItemCommon & {
Expand Down

0 comments on commit 0ea5765

Please sign in to comment.