Skip to content

Commit

Permalink
chore: upgrade docusaurus to 2.3.1 & react 18.2
Browse files Browse the repository at this point in the history
  • Loading branch information
blakef committed Mar 13, 2023
1 parent 103d9e7 commit 4f2bf39
Show file tree
Hide file tree
Showing 4 changed files with 279 additions and 299 deletions.
12 changes: 6 additions & 6 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@
]
},
"dependencies": {
"@docusaurus/core": "^2.0.1",
"@docusaurus/plugin-pwa": "^2.0.1",
"@docusaurus/preset-classic": "^2.0.1",
"@docusaurus/core": "^2.3.1",
"@docusaurus/plugin-pwa": "^2.3.1",
"@docusaurus/preset-classic": "^2.3.1",
"docusaurus-plugin-sass": "^0.2.2",
"esbuild-loader": "^2.19.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-github-btn": "^1.3.0",
"sass": "^1.53.0"
},
"devDependencies": {
"@docusaurus/types": "^2.0.1",
"@docusaurus/types": "^2.3.1",
"@react-native-website/lint-examples": "0.0.0",
"alex": "^10.0.0",
"fs-extra": "^10.1.0",
Expand Down
12 changes: 6 additions & 6 deletions website/src/pages/showcase.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ const Showcase = () => {
const {siteConfig} = useDocusaurusContext();

const {meta, microsoft, shopify, wix, others} = siteConfig.customFields.users;
const [pinnedRandomizedApps, setPinnedRandomizedApps] = useState([]);
const [randomizedApps, setRandomizedApps] = useState([]);

useEffect(() => {
setRandomizedApps(randomizeApps(others.filter(app => !app.pinned)));
setPinnedRandomizedApps(randomizeApps(others.filter(app => app.pinned)));
}, []);
const [pinnedRandomizedApps] = useState(
randomizeApps(others.filter(app => !app.pinned))
);
const [randomizedApps] = useState(
randomizeApps(others.filter(app => app.pinned))
);

return (
<Layout
Expand Down
65 changes: 34 additions & 31 deletions website/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
*/

import React from 'react';
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
import {
useVersions,
useLatestVersion,
useActiveDocContext,
} from '@docusaurus/plugin-content-docs/client';
import {useDocsPreferredVersion} from '@docusaurus/theme-common';
import {useDocsVersionCandidates} from '@docusaurus/theme-common/internal';
import {translate} from '@docusaurus/Translate';
import {useLocation} from '@docusaurus/router';
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';

const getVersionMainDoc = version =>
version.docs.find(doc => doc.id === version.mainDocId);
Expand All @@ -27,11 +29,10 @@ export default function DocsVersionDropdownNavbarItem({
dropdownItemsAfter,
...props
}) {
const {search, hash} = useLocation();
const activeDocContext = useActiveDocContext(docsPluginId);
const versions = useVersions(docsPluginId);
const latestVersion = useLatestVersion(docsPluginId);
const {preferredVersion, savePreferredVersionName} =
useDocsPreferredVersion(docsPluginId);
const {savePreferredVersionName} = useDocsPreferredVersion(docsPluginId);

// (CUSTOM) Hide version dropdown on non-versioned pages
if (!activeDocContext.activeDoc) {
Expand All @@ -41,32 +42,31 @@ export default function DocsVersionDropdownNavbarItem({
// (CUSTOM) Show only `next` and last 5 versions in the dropdown
const reducedVersions = versions.slice(0, 6);

function getItems() {
const versionLinks = reducedVersions.map(version => {
// We try to link to the same doc, in another version
// When not possible, fallback to the "main doc" of the version
const versionDoc =
activeDocContext?.alternateDocVersions[version.name] ||
getVersionMainDoc(version);
return {
isNavLink: true,
label: version.label,
to: versionDoc.path,
isActive: () => version === activeDocContext?.activeVersion,
onClick: () => {
savePreferredVersionName(version.name);
},
};
});
return [...dropdownItemsBefore, ...versionLinks, ...dropdownItemsAfter];
}
const versionLinks = reducedVersions.map(version => {
// We try to link to the same doc, in another version
// When not possible, fallback to the "main doc" of the version
const versionDoc =
activeDocContext?.alternateDocVersions[version.name] ??
getVersionMainDoc(version);
return {
label: version.label,
// preserve ?search#hash suffix on version switches
to: `${versionDoc.path}${search}${hash}`,
isActive: () => version === activeDocContext?.activeVersion,
onClick: () => savePreferredVersionName(version.name),
};
});
const items = [
...dropdownItemsBefore,
...versionLinks,
...dropdownItemsAfter,
];

const items = getItems();
const dropdownVersion =
activeDocContext.activeVersion ?? preferredVersion ?? latestVersion; // Mobile dropdown is handled a bit differently
const dropdownVersion = useDocsVersionCandidates(docsPluginId)[0];

// Mobile dropdown is handled a bit differently
const dropdownLabel =
mobile && items
mobile && items.length > 1
? translate({
id: 'theme.navbar.mobileVersionsDropdown.label',
message: 'Versions',
Expand All @@ -75,10 +75,13 @@ export default function DocsVersionDropdownNavbarItem({
})
: dropdownVersion.label;
const dropdownTo =
mobile && items ? undefined : getVersionMainDoc(dropdownVersion).path; // We don't want to render a version dropdown with 0 or 1 item
// If we build the site with a single docs version (onlyIncludeVersions: ['1.0.0'])
// We'd rather render a button instead of a dropdown
mobile && items.length > 1
? undefined
: getVersionMainDoc(dropdownVersion).path;

// We don't want to render a version dropdown with 0 or 1 item. If we build
// the site with a single docs version (onlyIncludeVersions: ['1.0.0']),
// We'd rather render a button instead of a dropdown
if (items.length <= 1) {
return (
<DefaultNavbarItem
Expand Down
Loading

0 comments on commit 4f2bf39

Please sign in to comment.