mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-22 09:46:30 -05:00
fix: flexsearch types
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
f4b54ca5a4
commit
c94db0c1ff
2 changed files with 5 additions and 5 deletions
|
@ -12,7 +12,7 @@ import { UiIcon } from '../../../common/icons/ui-icon'
|
||||||
import type { CheatsheetSingleEntry, CheatsheetExtension } from '../../cheatsheet/cheatsheet-extension'
|
import type { CheatsheetSingleEntry, CheatsheetExtension } from '../../cheatsheet/cheatsheet-extension'
|
||||||
import { hasCheatsheetTopics } from '../../cheatsheet/cheatsheet-extension'
|
import { hasCheatsheetTopics } from '../../cheatsheet/cheatsheet-extension'
|
||||||
import styles from './cheatsheet.module.scss'
|
import styles from './cheatsheet.module.scss'
|
||||||
import type { IndexOptionsForDocumentSearch } from 'flexsearch-ts'
|
import type { IndexOptionsForDocumentSearch, StoreOption } from 'flexsearch-ts'
|
||||||
import React, { useCallback, useEffect, useMemo, useState } from 'react'
|
import React, { useCallback, useEffect, useMemo, useState } from 'react'
|
||||||
import { FormControl, InputGroup } from 'react-bootstrap'
|
import { FormControl, InputGroup } from 'react-bootstrap'
|
||||||
import { X } from 'react-bootstrap-icons'
|
import { X } from 'react-bootstrap-icons'
|
||||||
|
@ -24,7 +24,7 @@ interface CheatsheetSearchIndexEntry extends SearchIndexEntry {
|
||||||
example: string
|
example: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchOptions: IndexOptionsForDocumentSearch<CheatsheetSearchIndexEntry> = {
|
const searchOptions: IndexOptionsForDocumentSearch<CheatsheetSearchIndexEntry, StoreOption> = {
|
||||||
document: {
|
document: {
|
||||||
id: 'id',
|
id: 'id',
|
||||||
field: ['title', 'description', 'example']
|
field: ['title', 'description', 'example']
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
import type { IndexOptionsForDocumentSearch, Id, SimpleDocumentSearchResultSetUnit } from 'flexsearch-ts'
|
import type { IndexOptionsForDocumentSearch, Id, SimpleDocumentSearchResultSetUnit, StoreOption } from 'flexsearch-ts'
|
||||||
import { Document } from 'flexsearch-ts'
|
import { Document } from 'flexsearch-ts'
|
||||||
import { useEffect, useMemo, useState } from 'react'
|
import { useEffect, useMemo, useState } from 'react'
|
||||||
|
|
||||||
|
@ -21,12 +21,12 @@ export interface SearchIndexEntry {
|
||||||
*/
|
*/
|
||||||
export const useDocumentSearch = <T extends SearchIndexEntry>(
|
export const useDocumentSearch = <T extends SearchIndexEntry>(
|
||||||
entries: Array<T>,
|
entries: Array<T>,
|
||||||
options: IndexOptionsForDocumentSearch<T>,
|
options: IndexOptionsForDocumentSearch<T, StoreOption>,
|
||||||
searchTerm: string
|
searchTerm: string
|
||||||
): SimpleDocumentSearchResultSetUnit[] => {
|
): SimpleDocumentSearchResultSetUnit[] => {
|
||||||
const [results, setResults] = useState<SimpleDocumentSearchResultSetUnit[]>([])
|
const [results, setResults] = useState<SimpleDocumentSearchResultSetUnit[]>([])
|
||||||
const searchIndex = useMemo(() => {
|
const searchIndex = useMemo(() => {
|
||||||
const index = new Document<T>({
|
const index = new Document<T, StoreOption>({
|
||||||
tokenize: 'full',
|
tokenize: 'full',
|
||||||
...options
|
...options
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue