fix: make search case-insensitive (#925)
This commit is contained in:
@@ -5,7 +5,13 @@ import { ContentType, SNFile, SNNote } from '@standardnotes/snjs';
|
|||||||
import { FilesIllustration } from '@standardnotes/stylekit';
|
import { FilesIllustration } from '@standardnotes/stylekit';
|
||||||
import { observer } from 'mobx-react-lite';
|
import { observer } from 'mobx-react-lite';
|
||||||
import { FunctionComponent } from 'preact';
|
import { FunctionComponent } from 'preact';
|
||||||
import { StateUpdater, useCallback, useEffect, useState } from 'preact/hooks';
|
import {
|
||||||
|
StateUpdater,
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
} from 'preact/hooks';
|
||||||
import { Button } from '../Button';
|
import { Button } from '../Button';
|
||||||
import { Icon } from '../Icon';
|
import { Icon } from '../Icon';
|
||||||
import { PopoverFileItem } from './PopoverFileItem';
|
import { PopoverFileItem } from './PopoverFileItem';
|
||||||
@@ -44,6 +50,7 @@ export const AttachedFilesPopover: FunctionComponent<Props> = observer(
|
|||||||
const [attachedFiles, setAttachedFiles] = useState<SNFile[]>([]);
|
const [attachedFiles, setAttachedFiles] = useState<SNFile[]>([]);
|
||||||
const [allFiles, setAllFiles] = useState<SNFile[]>([]);
|
const [allFiles, setAllFiles] = useState<SNFile[]>([]);
|
||||||
const [searchQuery, setSearchQuery] = useState('');
|
const [searchQuery, setSearchQuery] = useState('');
|
||||||
|
const searchInputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
const filesList =
|
const filesList =
|
||||||
currentTab === PopoverTabs.AttachedFiles ? attachedFiles : allFiles;
|
currentTab === PopoverTabs.AttachedFiles ? attachedFiles : allFiles;
|
||||||
@@ -51,7 +58,8 @@ export const AttachedFilesPopover: FunctionComponent<Props> = observer(
|
|||||||
const filteredList =
|
const filteredList =
|
||||||
searchQuery.length > 0
|
searchQuery.length > 0
|
||||||
? filesList.filter(
|
? filesList.filter(
|
||||||
(file) => file.name.toLowerCase().indexOf(searchQuery) !== -1
|
(file) =>
|
||||||
|
file.name.toLowerCase().indexOf(searchQuery.toLowerCase()) !== -1
|
||||||
)
|
)
|
||||||
: filesList;
|
: filesList;
|
||||||
|
|
||||||
@@ -151,12 +159,14 @@ export const AttachedFilesPopover: FunctionComponent<Props> = observer(
|
|||||||
setSearchQuery((e.target as HTMLInputElement).value);
|
setSearchQuery((e.target as HTMLInputElement).value);
|
||||||
}}
|
}}
|
||||||
onBlur={closeOnBlur}
|
onBlur={closeOnBlur}
|
||||||
|
ref={searchInputRef}
|
||||||
/>
|
/>
|
||||||
{searchQuery.length > 0 && (
|
{searchQuery.length > 0 && (
|
||||||
<button
|
<button
|
||||||
className="flex absolute right-2 p-0 bg-transparent border-0 top-1/2 -translate-y-1/2 cursor-pointer"
|
className="flex absolute right-2 p-0 bg-transparent border-0 top-1/2 -translate-y-1/2 cursor-pointer"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSearchQuery('');
|
setSearchQuery('');
|
||||||
|
searchInputRef.current?.focus();
|
||||||
}}
|
}}
|
||||||
onBlur={closeOnBlur}
|
onBlur={closeOnBlur}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user