mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-02 16:29:47 +02:00
refactor: improve internal typing (#6507)
* refactor: improve internal typing * fix * fix test
This commit is contained in:
parent
58e07a6796
commit
2553f1fb5a
14 changed files with 165 additions and 132 deletions
10
packages/docusaurus-theme-search-algolia/src/deps.d.ts
vendored
Normal file
10
packages/docusaurus-theme-search-algolia/src/deps.d.ts
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
declare module '@docsearch/react/modal';
|
||||
|
||||
declare module '@docsearch/react/style';
|
|
@ -4,7 +4,6 @@
|
|||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
|
||||
import React, {useState, useRef, useCallback, useMemo} from 'react';
|
||||
import {createPortal} from 'react-dom';
|
||||
|
@ -120,9 +119,7 @@ function DocSearch({
|
|||
}
|
||||
|
||||
return Promise.all([
|
||||
// @ts-ignore
|
||||
import('@docsearch/react/modal'),
|
||||
// @ts-ignore
|
||||
import('@docsearch/react/style'),
|
||||
import('./styles.css'),
|
||||
]).then(([{DocSearchModal: Modal}]) => {
|
||||
|
@ -271,8 +268,7 @@ function DocSearch({
|
|||
|
||||
function SearchBar(): JSX.Element {
|
||||
const {siteConfig} = useDocusaurusContext();
|
||||
// @ts-ignore
|
||||
return <DocSearch {...siteConfig.themeConfig.algolia} />;
|
||||
return <DocSearch {...(siteConfig.themeConfig.algolia as DocSearchProps)} />;
|
||||
}
|
||||
|
||||
export default SearchBar;
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
|
||||
/* eslint-disable jsx-a11y/no-autofocus */
|
||||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
|
||||
import React, {useEffect, useState, useReducer, useRef} from 'react';
|
||||
|
||||
|
@ -29,6 +28,7 @@ import {useAllDocsData} from '@docusaurus/plugin-content-docs/client';
|
|||
import Layout from '@theme/Layout';
|
||||
import Translate, {translate} from '@docusaurus/Translate';
|
||||
import styles from './styles.module.css';
|
||||
import type {ThemeConfig} from '@docusaurus/theme-search-algolia';
|
||||
|
||||
// Very simple pluralization: probably good enough for now
|
||||
function useDocumentsFoundPlural() {
|
||||
|
@ -151,14 +151,12 @@ type ResultDispatcher =
|
|||
|
||||
function SearchPage(): JSX.Element {
|
||||
const {
|
||||
siteConfig: {
|
||||
themeConfig: {
|
||||
// @ts-ignore
|
||||
algolia: {appId, apiKey, indexName, externalUrlRegex},
|
||||
},
|
||||
},
|
||||
siteConfig: {themeConfig},
|
||||
i18n: {currentLocale},
|
||||
} = useDocusaurusContext();
|
||||
const {
|
||||
algolia: {appId, apiKey, indexName, externalUrlRegex},
|
||||
} = themeConfig as ThemeConfig;
|
||||
const documentsFoundPlural = useDocumentsFoundPlural();
|
||||
|
||||
const docsSearchVersionsHelpers = useDocsSearchVersionsHelpers();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue