mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
fix: header link on packages with entrypoints (#11285)
* fix: header link on packages with entrypoints * types: add types --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -3,13 +3,14 @@
|
|||||||
import { Loader2Icon } from 'lucide-react';
|
import { Loader2Icon } from 'lucide-react';
|
||||||
import { useParams, useRouter } from 'next/navigation';
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
import { Select, SelectList, SelectOption, SelectTrigger } from '@/components/ui/Select';
|
import { Select, SelectList, SelectOption, SelectTrigger } from '@/components/ui/Select';
|
||||||
|
import type { EntryPoint } from '@/util/fetchEntryPoints';
|
||||||
import { parseDocsPathParams } from '@/util/parseDocsPathParams';
|
import { parseDocsPathParams } from '@/util/parseDocsPathParams';
|
||||||
|
|
||||||
export function EntryPointSelect({
|
export function EntryPointSelect({
|
||||||
entryPoints,
|
entryPoints,
|
||||||
isLoading,
|
isLoading,
|
||||||
}: {
|
}: {
|
||||||
readonly entryPoints: { readonly entryPoint: string }[];
|
readonly entryPoints: EntryPoint[];
|
||||||
readonly isLoading: boolean;
|
readonly isLoading: boolean;
|
||||||
}) {
|
}) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { VersionSelect } from '@/components/VersionSelect';
|
|||||||
import { SidebarHeader as BasSidebarHeader } from '@/components/ui/Sidebar';
|
import { SidebarHeader as BasSidebarHeader } from '@/components/ui/Sidebar';
|
||||||
import { buttonStyles } from '@/styles/ui/button';
|
import { buttonStyles } from '@/styles/ui/button';
|
||||||
import { PACKAGES_WITH_ENTRY_POINTS } from '@/util/constants';
|
import { PACKAGES_WITH_ENTRY_POINTS } from '@/util/constants';
|
||||||
|
import type { EntryPoint } from '@/util/fetchEntryPoints';
|
||||||
|
|
||||||
export function SidebarHeader() {
|
export function SidebarHeader() {
|
||||||
const params = useParams<{
|
const params = useParams<{
|
||||||
@@ -21,7 +22,7 @@ export function SidebarHeader() {
|
|||||||
|
|
||||||
const hasEntryPoints = PACKAGES_WITH_ENTRY_POINTS.includes(params.packageName);
|
const hasEntryPoints = PACKAGES_WITH_ENTRY_POINTS.includes(params.packageName);
|
||||||
|
|
||||||
const { data: entryPoints, isLoading: isLoadingEntryPoints } = useQuery({
|
const { data: entryPoints, isLoading: isLoadingEntryPoints } = useQuery<EntryPoint[]>({
|
||||||
queryKey: ['entryPoints', params.packageName, params.version],
|
queryKey: ['entryPoints', params.packageName, params.version],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const response = await fetch(`/api/docs/entrypoints?packageName=${params.packageName}&version=${params.version}`);
|
const response = await fetch(`/api/docs/entrypoints?packageName=${params.packageName}&version=${params.version}`);
|
||||||
@@ -43,7 +44,10 @@ export function SidebarHeader() {
|
|||||||
<BasSidebarHeader className="bg-[#f3f3f4] p-4 dark:bg-[#121214]">
|
<BasSidebarHeader className="bg-[#f3f3f4] p-4 dark:bg-[#121214]">
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
<div className="flex place-content-between place-items-center p-1">
|
<div className="flex place-content-between place-items-center p-1">
|
||||||
<Link className="text-xl font-bold" href={`/docs/packages/${params.packageName}/${params.version}`}>
|
<Link
|
||||||
|
className="text-xl font-bold"
|
||||||
|
href={`/docs/packages/${params.packageName}/${params.version}${hasEntryPoints ? `/${entryPoints?.[0]?.entryPoint ?? ''}` : ''}`}
|
||||||
|
>
|
||||||
{params.packageName}
|
{params.packageName}
|
||||||
</Link>
|
</Link>
|
||||||
<div className="flex place-items-center gap-2">
|
<div className="flex place-items-center gap-2">
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { join } from 'node:path';
|
|||||||
import { PACKAGES_WITH_ENTRY_POINTS } from './constants';
|
import { PACKAGES_WITH_ENTRY_POINTS } from './constants';
|
||||||
import { ENV } from './env';
|
import { ENV } from './env';
|
||||||
|
|
||||||
export async function fetchEntryPoints(packageName: string, version: string) {
|
export async function fetchEntryPoints(packageName: string, version: string): Promise<EntryPoint[] | null> {
|
||||||
const hasEntryPoint = PACKAGES_WITH_ENTRY_POINTS.includes(packageName);
|
const hasEntryPoint = PACKAGES_WITH_ENTRY_POINTS.includes(packageName);
|
||||||
|
|
||||||
if (!hasEntryPoint) {
|
if (!hasEntryPoint) {
|
||||||
@@ -37,3 +37,7 @@ export async function fetchEntryPoints(packageName: string, version: string) {
|
|||||||
|
|
||||||
return fileContent.json();
|
return fileContent.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface EntryPoint {
|
||||||
|
readonly entryPoint: string;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user