Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(www): fix mdx reset on package manager tab switch #6108

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions apps/www/components/code-block-command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as React from "react"
import { CheckIcon, ClipboardIcon } from "lucide-react"

import { NpmCommands } from "@/types/unist"
import { useConfig } from "@/hooks/use-config"
import { useConfigPackageManager } from "@/hooks/use-config-package-manager"
import { copyToClipboardWithMeta } from "@/components/copy-button"
import { Tabs } from "@/registry/default/ui/tabs"
import { Button } from "@/registry/new-york/ui/button"
Expand All @@ -16,7 +16,8 @@ export function CodeBlockCommand({
__pnpmCommand__,
__bunCommand__,
}: React.ComponentProps<"pre"> & NpmCommands) {
const [config, setConfig] = useConfig()
const [configPackageManager, setConfigPackageManager] =
useConfigPackageManager()
const [hasCopied, setHasCopied] = React.useState(false)

React.useEffect(() => {
Expand All @@ -26,7 +27,7 @@ export function CodeBlockCommand({
}
}, [hasCopied])

const packageManager = config.packageManager || "pnpm"
const packageManager = configPackageManager || "pnpm"
const tabs = React.useMemo(() => {
return {
pnpm: __pnpmCommand__,
Expand Down Expand Up @@ -58,10 +59,7 @@ export function CodeBlockCommand({
<Tabs
defaultValue={packageManager}
onValueChange={(value) => {
setConfig({
...config,
packageManager: value as "pnpm" | "npm" | "yarn" | "bun",
})
setConfigPackageManager(value as "pnpm" | "npm" | "yarn" | "bun")
}}
>
<div className="flex items-center justify-between border-b border-zinc-800 bg-zinc-900 px-3 pt-2.5">
Expand Down
13 changes: 13 additions & 0 deletions apps/www/hooks/use-config-package-manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useAtom } from "jotai"
import { atomWithStorage } from "jotai/utils"

type ConfigPackageManager = "npm" | "yarn" | "pnpm" | "bun"

const configAtom = atomWithStorage<ConfigPackageManager>(
"config-package-manager",
"pnpm"
)

export function useConfigPackageManager() {
return useAtom(configAtom)
}
2 changes: 0 additions & 2 deletions apps/www/hooks/use-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ type Config = {
style: Style["name"]
theme: BaseColor["name"]
radius: number
packageManager: "npm" | "yarn" | "pnpm" | "bun"
}

const configAtom = atomWithStorage<Config>("config", {
style: "new-york",
theme: "zinc",
radius: 0.5,
packageManager: "pnpm",
})

export function useConfig() {
Expand Down