mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-23 05:57:05 +02:00
refactor(v2): correct some of type errors reported by eslint (#4382)
* fix: correct some of type errors reported by eslint * fix: remove unnecessary import
This commit is contained in:
parent
a39c62f644
commit
bfe52cdae3
10 changed files with 32 additions and 21 deletions
|
@ -18,8 +18,10 @@ import {
|
|||
getActiveVersion,
|
||||
getActiveDocContext,
|
||||
getDocVersionSuggestions,
|
||||
GetActivePluginOptions,
|
||||
ActivePlugin,
|
||||
ActiveDocContext,
|
||||
DocVersionSuggestions,
|
||||
GetActivePluginOptions,
|
||||
} from '../../client/docsClientUtils';
|
||||
|
||||
export const useAllDocsData = (): Record<string, GlobalPluginData> =>
|
||||
|
@ -28,7 +30,9 @@ export const useAllDocsData = (): Record<string, GlobalPluginData> =>
|
|||
export const useDocsData = (pluginId: string | undefined) =>
|
||||
usePluginData('docusaurus-plugin-content-docs', pluginId) as GlobalPluginData;
|
||||
|
||||
export const useActivePlugin = (options: GetActivePluginOptions = {}) => {
|
||||
export const useActivePlugin = (
|
||||
options: GetActivePluginOptions = {},
|
||||
): ActivePlugin | undefined => {
|
||||
const data = useAllDocsData();
|
||||
const {pathname} = useLocation();
|
||||
return getActivePlugin(data, pathname, options);
|
||||
|
@ -57,27 +61,35 @@ export const useVersions = (pluginId: string | undefined): GlobalVersion[] => {
|
|||
return data.versions;
|
||||
};
|
||||
|
||||
export const useLatestVersion = (pluginId: string | undefined) => {
|
||||
export const useLatestVersion = (
|
||||
pluginId: string | undefined,
|
||||
): GlobalVersion => {
|
||||
const data = useDocsData(pluginId);
|
||||
return getLatestVersion(data);
|
||||
};
|
||||
|
||||
// Note: return undefined on doc-unrelated pages,
|
||||
// because there's no version currently considered as active
|
||||
export const useActiveVersion = (pluginId: string | undefined) => {
|
||||
export const useActiveVersion = (
|
||||
pluginId: string | undefined,
|
||||
): GlobalVersion | undefined => {
|
||||
const data = useDocsData(pluginId);
|
||||
const {pathname} = useLocation();
|
||||
return getActiveVersion(data, pathname);
|
||||
};
|
||||
|
||||
export const useActiveDocContext = (pluginId: string | undefined) => {
|
||||
export const useActiveDocContext = (
|
||||
pluginId: string | undefined,
|
||||
): ActiveDocContext => {
|
||||
const data = useDocsData(pluginId);
|
||||
const {pathname} = useLocation();
|
||||
return getActiveDocContext(data, pathname);
|
||||
};
|
||||
|
||||
// Useful to say "hey, you are not on the latest docs version, please switch"
|
||||
export const useDocVersionSuggestions = (pluginId: string | undefined) => {
|
||||
export const useDocVersionSuggestions = (
|
||||
pluginId: string | undefined,
|
||||
): DocVersionSuggestions => {
|
||||
const data = useDocsData(pluginId);
|
||||
const {pathname} = useLocation();
|
||||
return getDocVersionSuggestions(data, pathname);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue