Skip to content

Commit

Permalink
use same priority order for all navbar items: activeVersion ?? prefer…
Browse files Browse the repository at this point in the history
…redVersion ?? latestVersion
  • Loading branch information
slorber committed Oct 12, 2020
1 parent 15424bb commit d9c4d9b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import DefaultNavbarItem from './DefaultNavbarItem';
import {useLatestVersion, useActiveDocContext} from '@theme/hooks/useDocs';
import clsx from 'clsx';
import type {Props} from '@theme/NavbarItem/DocNavbarItem';
import useDocsPreferredVersion from '../../utils/docsPreferredVersion/useDocsPreferredVersion';

export default function DocNavbarItem({
docId,
Expand All @@ -18,10 +19,11 @@ export default function DocNavbarItem({
docsPluginId,
...props
}: Props): JSX.Element {
const latestVersion = useLatestVersion(docsPluginId);
const {activeVersion, activeDoc} = useActiveDocContext(docsPluginId);
const {preferredVersion} = useDocsPreferredVersion(docsPluginId);
const latestVersion = useLatestVersion(docsPluginId);

const version = activeVersion ?? latestVersion;
const version = activeVersion ?? preferredVersion ?? latestVersion;

const doc = version.docs.find((versionDoc) => versionDoc.id === docId);
if (!doc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React from 'react';
import DefaultNavbarItem from './DefaultNavbarItem';
import {useActiveVersion, useLatestVersion} from '@theme/hooks/useDocs';
import type {Props} from '@theme/NavbarItem/DocsVersionNavbarItem';
import useDocsPreferredVersion from '../../utils/docsPreferredVersion/useDocsPreferredVersion';

const getVersionMainDoc = (version) =>
version.docs.find((doc) => doc.id === version.mainDocId);
Expand All @@ -20,8 +21,9 @@ export default function DocsVersionNavbarItem({
...props
}: Props): JSX.Element {
const activeVersion = useActiveVersion(docsPluginId);
const {preferredVersion} = useDocsPreferredVersion(docsPluginId);
const latestVersion = useLatestVersion(docsPluginId);
const version = activeVersion ?? latestVersion;
const version = activeVersion ?? preferredVersion ?? latestVersion;
const label = staticLabel ?? version.label;
const path = staticTo ?? getVersionMainDoc(version).path;
return <DefaultNavbarItem {...props} label={label} to={path} />;
Expand Down

0 comments on commit d9c4d9b

Please sign in to comment.