mirror of
https://github.com/PeWu/topola-viewer.git
synced 2026-07-29 23:21:50 +00:00
Improve code quality
Fix lint warnings
This commit is contained in:
@@ -53,11 +53,11 @@ export function SearchBar(props: Props) {
|
||||
|
||||
/** On search input change. */
|
||||
function handleSearch(input: string | undefined) {
|
||||
if (!input) {
|
||||
if (!input || !searchIndex.current) {
|
||||
return;
|
||||
}
|
||||
const results = searchIndex
|
||||
.current!.search(input)
|
||||
const results = searchIndex.current
|
||||
.search(input)
|
||||
.map((result) => displaySearchResult(result));
|
||||
setSearchResults(results);
|
||||
}
|
||||
@@ -71,9 +71,9 @@ export function SearchBar(props: Props) {
|
||||
}
|
||||
|
||||
/** On search string changed. */
|
||||
function onChange(value: string) {
|
||||
function onChange(value: string | undefined) {
|
||||
debouncedHandleSearch.current(value);
|
||||
setSearchString(value);
|
||||
setSearchString(value || '');
|
||||
}
|
||||
|
||||
// Initialize the search index.
|
||||
@@ -83,7 +83,7 @@ export function SearchBar(props: Props) {
|
||||
|
||||
return (
|
||||
<Search
|
||||
onSearchChange={(_, data) => onChange(data.value!)}
|
||||
onSearchChange={(_, data) => onChange(data.value)}
|
||||
onResultSelect={(_, data) => handleResultSelect(data.result.id)}
|
||||
results={searchResults}
|
||||
noResultsMessage={intl.formatMessage({
|
||||
|
||||
@@ -57,7 +57,7 @@ function getHusbandLastName(
|
||||
}
|
||||
|
||||
class LunrSearchIndex implements SearchIndex {
|
||||
private index: lunr.Index | undefined;
|
||||
private index!: lunr.Index;
|
||||
private indiMap: Map<string, JsonIndi>;
|
||||
private famMap: Map<string, JsonFam>;
|
||||
|
||||
@@ -107,7 +107,6 @@ class LunrSearchIndex implements SearchIndex {
|
||||
lunrInstance: any,
|
||||
languages: string[],
|
||||
): void {
|
||||
let wordCharacters = '';
|
||||
const pipelineFunctions: PipelineFunction[] = [];
|
||||
const searchPipelineFunctions: PipelineFunction[] = [];
|
||||
languages.forEach((language) => {
|
||||
@@ -115,12 +114,10 @@ class LunrSearchIndex implements SearchIndex {
|
||||
// @ts-ignore
|
||||
const lunrLanguage = lunr[language];
|
||||
if (language === 'en') {
|
||||
wordCharacters += '\\w';
|
||||
pipelineFunctions.unshift(lunr.stopWordFilter);
|
||||
pipelineFunctions.push(lunr.stemmer);
|
||||
searchPipelineFunctions.push(lunr.stemmer);
|
||||
} else {
|
||||
wordCharacters += lunrLanguage.wordCharacters;
|
||||
if (lunrLanguage.stopWordFilter) {
|
||||
pipelineFunctions.unshift(lunrLanguage.stopWordFilter);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ export function TopBar(props: Props) {
|
||||
}
|
||||
|
||||
function chartMenus(screenSize: ScreenSize) {
|
||||
if (!props.showingChart) {
|
||||
if (!props.showingChart || !props.data) {
|
||||
return null;
|
||||
}
|
||||
const chartTypeItems = (
|
||||
@@ -147,7 +147,7 @@ export function TopBar(props: Props) {
|
||||
<Dropdown.Menu>{chartTypeItems}</Dropdown.Menu>
|
||||
</Dropdown>
|
||||
<SearchBar
|
||||
data={props.data!}
|
||||
data={props.data}
|
||||
onSelection={props.eventHandlers.onSelection}
|
||||
{...props}
|
||||
/>
|
||||
@@ -312,9 +312,9 @@ export function TopBar(props: Props) {
|
||||
<div className="topbar--title">
|
||||
{props.standalone ? <Link to="/">{title()}</Link> : title()}
|
||||
</div>
|
||||
{props.showingChart && (
|
||||
{props.showingChart && props.data && (
|
||||
<SearchBar
|
||||
data={props.data!}
|
||||
data={props.data}
|
||||
onSelection={props.eventHandlers.onSelection}
|
||||
{...props}
|
||||
/>
|
||||
|
||||
@@ -20,7 +20,7 @@ export function UrlMenu(props: Props) {
|
||||
useEffect(() => {
|
||||
if (dialogOpen) {
|
||||
setUrl('');
|
||||
inputRef.current!.focus();
|
||||
inputRef.current?.focus();
|
||||
}
|
||||
}, [dialogOpen]);
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ export function WikiTreeMenu(props: Props) {
|
||||
useEffect(() => {
|
||||
if (dialogOpen) {
|
||||
setWikiTreeId('');
|
||||
inputRef.current!.focus();
|
||||
inputRef.current?.focus();
|
||||
}
|
||||
}, [dialogOpen]);
|
||||
|
||||
@@ -50,7 +50,7 @@ export function WikiTreeMenu(props: Props) {
|
||||
function enterId(event: React.MouseEvent, id: string) {
|
||||
event.preventDefault(); // Do not follow link in href.
|
||||
setWikiTreeId(id);
|
||||
inputRef.current!.focus();
|
||||
inputRef.current?.focus();
|
||||
}
|
||||
|
||||
function wikiTreeIdModal() {
|
||||
|
||||
Reference in New Issue
Block a user