|
@@ -1,10 +1,9 @@
|
|
|
-
|
|
|
|
|
-import React, {
|
|
|
|
|
- useState, useCallback, useEffect, type JSX,
|
|
|
|
|
-} from 'react';
|
|
|
|
|
-
|
|
|
|
|
-import Downshift, { type DownshiftState, type StateChangeOptions } from 'downshift';
|
|
|
|
|
|
|
+import Downshift, {
|
|
|
|
|
+ type DownshiftState,
|
|
|
|
|
+ type StateChangeOptions,
|
|
|
|
|
+} from 'downshift';
|
|
|
import { useRouter } from 'next/router';
|
|
import { useRouter } from 'next/router';
|
|
|
|
|
+import React, { type JSX, useCallback, useEffect, useState } from 'react';
|
|
|
import { Modal, ModalBody } from 'reactstrap';
|
|
import { Modal, ModalBody } from 'reactstrap';
|
|
|
|
|
|
|
|
import { isIncludeAiMenthion, removeAiMenthion } from '../../utils/ai';
|
|
import { isIncludeAiMenthion, removeAiMenthion } from '../../utils/ai';
|
|
@@ -17,7 +16,6 @@ import { SearchMethodMenuItem } from './SearchMethodMenuItem';
|
|
|
import { SearchResultMenuItem } from './SearchResultMenuItem';
|
|
import { SearchResultMenuItem } from './SearchResultMenuItem';
|
|
|
|
|
|
|
|
const SearchModal = (): JSX.Element => {
|
|
const SearchModal = (): JSX.Element => {
|
|
|
-
|
|
|
|
|
const [searchKeyword, setSearchKeyword] = useState('');
|
|
const [searchKeyword, setSearchKeyword] = useState('');
|
|
|
const [isMenthionedToAi, setMenthionedToAi] = useState(false);
|
|
const [isMenthionedToAi, setMenthionedToAi] = useState(false);
|
|
|
|
|
|
|
@@ -29,10 +27,13 @@ const SearchModal = (): JSX.Element => {
|
|
|
setSearchKeyword(searchText);
|
|
setSearchKeyword(searchText);
|
|
|
}, []);
|
|
}, []);
|
|
|
|
|
|
|
|
- const selectSearchMenuItemHandler = useCallback((selectedItem: DownshiftItem) => {
|
|
|
|
|
- router.push(selectedItem.url);
|
|
|
|
|
- closeSearchModal();
|
|
|
|
|
- }, [closeSearchModal, router]);
|
|
|
|
|
|
|
+ const selectSearchMenuItemHandler = useCallback(
|
|
|
|
|
+ (selectedItem: DownshiftItem) => {
|
|
|
|
|
+ router.push(selectedItem.url);
|
|
|
|
|
+ closeSearchModal();
|
|
|
|
|
+ },
|
|
|
|
|
+ [closeSearchModal, router],
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
const submitHandler = useCallback(() => {
|
|
const submitHandler = useCallback(() => {
|
|
|
const url = new URL('_search', 'http://example.com');
|
|
const url = new URL('_search', 'http://example.com');
|
|
@@ -41,7 +42,10 @@ const SearchModal = (): JSX.Element => {
|
|
|
closeSearchModal();
|
|
closeSearchModal();
|
|
|
}, [closeSearchModal, router, searchKeyword]);
|
|
}, [closeSearchModal, router, searchKeyword]);
|
|
|
|
|
|
|
|
- const stateReducer = (state: DownshiftState<DownshiftItem>, changes: StateChangeOptions<DownshiftItem>) => {
|
|
|
|
|
|
|
+ const stateReducer = (
|
|
|
|
|
+ state: DownshiftState<DownshiftItem>,
|
|
|
|
|
+ changes: StateChangeOptions<DownshiftItem>,
|
|
|
|
|
+ ) => {
|
|
|
// Do not update highlightedIndex on mouse hover
|
|
// Do not update highlightedIndex on mouse hover
|
|
|
if (changes.type === Downshift.stateChangeTypes.itemMouseEnter) {
|
|
if (changes.type === Downshift.stateChangeTypes.itemMouseEnter) {
|
|
|
return {
|
|
return {
|
|
@@ -59,8 +63,7 @@ const SearchModal = (): JSX.Element => {
|
|
|
}
|
|
}
|
|
|
if (searchModalData?.searchKeyword == null) {
|
|
if (searchModalData?.searchKeyword == null) {
|
|
|
setSearchKeyword('');
|
|
setSearchKeyword('');
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
|
|
+ } else {
|
|
|
setSearchKeyword(searchModalData.searchKeyword);
|
|
setSearchKeyword(searchModalData.searchKeyword);
|
|
|
}
|
|
}
|
|
|
}, [searchModalData?.isOpened, searchModalData?.searchKeyword]);
|
|
}, [searchModalData?.isOpened, searchModalData?.searchKeyword]);
|
|
@@ -72,7 +75,12 @@ const SearchModal = (): JSX.Element => {
|
|
|
const searchKeywordWithoutAi = removeAiMenthion(searchKeyword);
|
|
const searchKeywordWithoutAi = removeAiMenthion(searchKeyword);
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
- <Modal size="lg" isOpen={searchModalData?.isOpened ?? false} toggle={closeSearchModal} data-testid="search-modal">
|
|
|
|
|
|
|
+ <Modal
|
|
|
|
|
+ size="lg"
|
|
|
|
|
+ isOpen={searchModalData?.isOpened ?? false}
|
|
|
|
|
+ toggle={closeSearchModal}
|
|
|
|
|
+ data-testid="search-modal"
|
|
|
|
|
+ >
|
|
|
<ModalBody className="pb-2">
|
|
<ModalBody className="pb-2">
|
|
|
<Downshift
|
|
<Downshift
|
|
|
onSelect={selectSearchMenuItemHandler}
|
|
onSelect={selectSearchMenuItemHandler}
|
|
@@ -88,7 +96,9 @@ const SearchModal = (): JSX.Element => {
|
|
|
}) => (
|
|
}) => (
|
|
|
<div {...getRootProps({}, { suppressRefError: true })}>
|
|
<div {...getRootProps({}, { suppressRefError: true })}>
|
|
|
<div className="text-muted d-flex justify-content-center align-items-center p-1">
|
|
<div className="text-muted d-flex justify-content-center align-items-center p-1">
|
|
|
- <span className={`material-symbols-outlined fs-4 me-3 ${isMenthionedToAi ? 'text-primary' : ''}`}>
|
|
|
|
|
|
|
+ <span
|
|
|
|
|
+ className={`material-symbols-outlined fs-4 me-3 ${isMenthionedToAi ? 'text-primary' : ''}`}
|
|
|
|
|
+ >
|
|
|
{isMenthionedToAi ? 'psychology' : 'search'}
|
|
{isMenthionedToAi ? 'psychology' : 'search'}
|
|
|
</span>
|
|
</span>
|
|
|
<SearchForm
|
|
<SearchForm
|
|
@@ -102,7 +112,9 @@ const SearchModal = (): JSX.Element => {
|
|
|
className="btn border-0 d-flex justify-content-center p-0"
|
|
className="btn border-0 d-flex justify-content-center p-0"
|
|
|
onClick={closeSearchModal}
|
|
onClick={closeSearchModal}
|
|
|
>
|
|
>
|
|
|
- <span className="material-symbols-outlined fs-4 ms-3 py-0">close</span>
|
|
|
|
|
|
|
+ <span className="material-symbols-outlined fs-4 ms-3 py-0">
|
|
|
|
|
+ close
|
|
|
|
|
+ </span>
|
|
|
</button>
|
|
</button>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|