Skip to content

Commit

Permalink
docs: fix client error for learning path
Browse files Browse the repository at this point in the history
  • Loading branch information
shahednasser committed Nov 14, 2024
1 parent 3e26522 commit 60c6f88
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 82 deletions.
7 changes: 6 additions & 1 deletion www/apps/book/components/Homepage/LinksSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ const Section = ({ title, links }: SectionProps) => {
<div className="flex flex-col gap-0.5 flex-1">
<h3 className="text-h3 text-medusa-fg-base">{title}</h3>
{links.map((link, index) => (
<Link key={index} className="text-compact-small-plus" href={link.href}>
<Link
key={index}
className="text-compact-small-plus"
href={link.href}
prefetch={false}
>
{link.text}
</Link>
))}
Expand Down
2 changes: 1 addition & 1 deletion www/apps/book/providers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const Providers = ({ children }: ProvidersProps) => {
<HooksLoader
options={{
pageScrollManager: true,
currentLearningPath: true,
currentLearningPath: false,
}}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const CardDefaultLayout = ({
<Link
href={href}
className="absolute left-0 top-0 h-full w-full rounded"
prefetch={false}
/>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const CardLargeLayout = ({
<Link
href={href}
className="absolute left-0 top-0 h-full w-full rounded"
prefetch={false}
/>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ export const CardLayoutMini = ({
{isExternal ? <ArrowUpRightOnBox /> : <TriangleRightMini />}
</span>
{href && (
<Link href={href} className="absolute left-0 top-0 w-full h-full" />
<Link
href={href}
className="absolute left-0 top-0 w-full h-full"
prefetch={false}
/>
)}
</div>
</div>
Expand Down
107 changes: 58 additions & 49 deletions www/packages/docs-ui/src/components/Notification/Item/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"use client"

import clsx from "clsx"
import React, { Children, ReactElement } from "react"
import React, { Children, ReactElement, useRef } from "react"
import { NotificationItemLayoutDefault } from "./Layout/Default"
// @ts-expect-error can't install the types package because it doesn't support React v19
import { CSSTransition } from "react-transition-group"

export type NotificationItemProps = {
layout?: "default" | "empty"
Expand All @@ -16,65 +20,70 @@ export type NotificationItemProps = {
setShow?: (value: boolean) => void
onClose?: () => void
closeButtonText?: string
passRef?: React.RefObject<HTMLDivElement>
} & React.HTMLAttributes<HTMLDivElement>

type EmptyLayoutProps = {
onClose?: () => void
}

export const NotificationItem = React.forwardRef<
HTMLDivElement,
NotificationItemProps
>(function NotificationItem(
{
className = "",
placement = "bottom",
show = true,
layout = "default",
setShow,
onClose,
children,
...rest
},
ref
) {
export const NotificationItem = ({
className = "",
placement = "bottom",
show = true,
layout = "default",
setShow,
onClose,
children,
...rest
}: NotificationItemProps) => {
const ref = useRef<HTMLDivElement>(null)
const handleClose = () => {
setShow?.(false)
onClose?.()
}

return (
<div
className={clsx(
"md:max-w-[320px] md:w-[320px] w-full",
"fixed md:right-docs_1 left-0 md:m-docs_1",
placement === "bottom" && "md:bottom-docs_1 bottom-0",
placement === "top" && "md:top-docs_1 top-0",
"opacity-100 transition-opacity duration-200 ease-ease",
!show && "!opacity-0",
className
)}
ref={ref}
<CSSTransition
timeout={200}
classNames={{
enter: "animate-slideInRight animate-fast",
exit: "animate-slideOutRight animate-fast",
}}
nodeRef={ref}
>
{layout === "default" && (
<NotificationItemLayoutDefault {...rest} handleClose={handleClose}>
{children}
</NotificationItemLayoutDefault>
)}
{layout === "empty" &&
Children.map(children, (child) => {
if (child) {
return React.cloneElement<EmptyLayoutProps>(
child as React.ReactElement<
EmptyLayoutProps,
React.FunctionComponent<EmptyLayoutProps>
>,
{
onClose: handleClose,
}
)
}
})}
</div>
<div
className={clsx(
"md:max-w-[320px] md:w-[320px] w-full",
"fixed md:right-docs_1 left-0 md:m-docs_1",
placement === "bottom" && "md:bottom-docs_1 bottom-0",
placement === "top" && "md:top-docs_1 top-0",
"opacity-100 transition-opacity duration-200 ease-ease",
!show && "!opacity-0",
className
)}
ref={ref}
>
{layout === "default" && (
<NotificationItemLayoutDefault {...rest} handleClose={handleClose}>
{children}
</NotificationItemLayoutDefault>
)}
{layout === "empty" &&
Children.map(children, (child) => {
if (child) {
return React.cloneElement<EmptyLayoutProps>(
child as React.ReactElement<
EmptyLayoutProps,
React.FunctionComponent<EmptyLayoutProps>
>,
{
onClose: handleClose,
}
)
}
})}
</div>
</CSSTransition>
)
})
}
41 changes: 11 additions & 30 deletions www/packages/docs-ui/src/components/Notification/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,16 @@ import {
NotificationItemType,
useNotifications,
} from "@/providers"
import React, { useEffect, useRef } from "react"
import React from "react"
import { NotificationItem } from "./Item"
// @ts-expect-error can't install the types package because it doesn't support React v19
import { CSSTransition, TransitionGroup } from "react-transition-group"
import { TransitionGroup } from "react-transition-group"
import clsx from "clsx"

export const NotificationContainer = () => {
const { notifications, removeNotification } =
useNotifications() as NotificationContextType

const notificationRefs = useRef([])

useEffect(() => {
notificationRefs.current = notificationRefs.current.slice(
0,
notifications.length
)
}, [notifications])

const handleClose = (notification: NotificationItemType) => {
notification.onClose?.()
if (notification.id) {
Expand All @@ -45,26 +36,16 @@ export const NotificationContainer = () => {
className
)}
>
{notifications.filter(condition).map((notification, index) => (
<CSSTransition
{notifications.filter(condition).map((notification) => (
<NotificationItem
{...notification}
onClose={() => handleClose(notification)}
className={clsx(
notification.className,
"!relative !top-0 !bottom-0 !right-0"
)}
key={notification.id}
timeout={200}
classNames={{
enter: "animate-slideInRight animate-fast",
exit: "animate-slideOutRight animate-fast",
}}
nodeRef={notificationRefs.current[index]}
>
<NotificationItem
{...notification}
onClose={() => handleClose(notification)}
ref={notificationRefs.current[index]}
className={clsx(
notification.className,
"!relative !top-0 !bottom-0 !right-0"
)}
/>
</CSSTransition>
/>
))}
</TransitionGroup>
)
Expand Down

0 comments on commit 60c6f88

Please sign in to comment.