|
@@ -1,4 +1,4 @@
|
|
-import React, { useEffect, useState } from "react";
|
|
|
|
|
|
+import React, { useEffect, useState, useRef } from "react";
|
|
import classNames from "classnames/bind";
|
|
import classNames from "classnames/bind";
|
|
import styles from "./Header.scss";
|
|
import styles from "./Header.scss";
|
|
import { Link } from "react-router-dom";
|
|
import { Link } from "react-router-dom";
|
|
@@ -18,19 +18,25 @@ import useLogin from "@src/hooks/useLogin";
|
|
import { useHistory } from "react-router";
|
|
import { useHistory } from "react-router";
|
|
import { fetchUserInfo } from "@src/store/reducers/UserReducer";
|
|
import { fetchUserInfo } from "@src/store/reducers/UserReducer";
|
|
import { YoutubeIcon } from "../common/icon/youtube";
|
|
import { YoutubeIcon } from "../common/icon/youtube";
|
|
|
|
+import { useOnClickOutside} from "usehooks-ts";
|
|
|
|
+import AutoCompleteSearch from "../common/AutoCompleteSearch";
|
|
|
|
|
|
const cx = classNames.bind(styles);
|
|
const cx = classNames.bind(styles);
|
|
|
|
|
|
const Header: React.FC = () => {
|
|
const Header: React.FC = () => {
|
|
|
|
+ const searchRef = useRef(null)
|
|
const history = useHistory();
|
|
const history = useHistory();
|
|
const dispatch = useDispatch();
|
|
const dispatch = useDispatch();
|
|
-
|
|
|
|
|
|
+ const [showAutoComplete, setShowAutoComplete] = useState<boolean>(false);
|
|
const { userInfo, isUserInfoLoaded } = useSelector((store) => store.user);
|
|
const { userInfo, isUserInfoLoaded } = useSelector((store) => store.user);
|
|
const onSearch = () => {
|
|
const onSearch = () => {
|
|
history.push(URLInfo.getSearchResultUrl(keyword));
|
|
history.push(URLInfo.getSearchResultUrl(keyword));
|
|
};
|
|
};
|
|
|
|
+ const SelectTextComplete = (text: string) => {
|
|
|
|
+ history.push(URLInfo.getSearchResultUrl(text));
|
|
|
|
+ };
|
|
const { keyword, setKeyword, onKeyPress, handleSearch } = useSearch({
|
|
const { keyword, setKeyword, onKeyPress, handleSearch } = useSearch({
|
|
- onSearch
|
|
|
|
|
|
+ onSearch,
|
|
});
|
|
});
|
|
const [showCommunity, setShowCommunity] = useState(false);
|
|
const [showCommunity, setShowCommunity] = useState(false);
|
|
const [showProfile, setShowProfile] = useState<boolean>(false);
|
|
const [showProfile, setShowProfile] = useState<boolean>(false);
|
|
@@ -48,6 +54,23 @@ const Header: React.FC = () => {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ const fakeComplete = [
|
|
|
|
+ "test1",
|
|
|
|
+ "test2",
|
|
|
|
+ "test3",
|
|
|
|
+ "test4",
|
|
|
|
+ "test5",
|
|
|
|
+ "test6",
|
|
|
|
+ "test7",
|
|
|
|
+ "test8",
|
|
|
|
+ "test9",
|
|
|
|
+ "test10",
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ useOnClickOutside(searchRef, () => {
|
|
|
|
+ setShowAutoComplete(false);
|
|
|
|
+ });
|
|
|
|
+
|
|
return (
|
|
return (
|
|
<div className={cx("header_wrap")}>
|
|
<div className={cx("header_wrap")}>
|
|
<div className={cx("header_group")}>
|
|
<div className={cx("header_group")}>
|
|
@@ -58,7 +81,7 @@ const Header: React.FC = () => {
|
|
</Link>
|
|
</Link>
|
|
</h1>
|
|
</h1>
|
|
<div className={cx("gnb")}>
|
|
<div className={cx("gnb")}>
|
|
- <div className={cx("search_area")}>
|
|
|
|
|
|
+ <div className={cx("search_area")} ref={searchRef}>
|
|
<input
|
|
<input
|
|
type="text"
|
|
type="text"
|
|
placeholder="작품(NFT)이름을 입력해주세요"
|
|
placeholder="작품(NFT)이름을 입력해주세요"
|
|
@@ -66,11 +89,19 @@ const Header: React.FC = () => {
|
|
value={keyword}
|
|
value={keyword}
|
|
onKeyPress={onKeyPress}
|
|
onKeyPress={onKeyPress}
|
|
onChange={(e) => setKeyword(e.target.value)}
|
|
onChange={(e) => setKeyword(e.target.value)}
|
|
|
|
+ onFocus={() => {
|
|
|
|
+ setShowAutoComplete(true);
|
|
|
|
+ }}
|
|
/>
|
|
/>
|
|
<button className={cx("btn_search")} onClick={handleSearch}>
|
|
<button className={cx("btn_search")} onClick={handleSearch}>
|
|
<span className={cx("blind")}>Search</span>
|
|
<span className={cx("blind")}>Search</span>
|
|
<IconSearchGray className={cx("ico_search")} />
|
|
<IconSearchGray className={cx("ico_search")} />
|
|
</button>
|
|
</button>
|
|
|
|
+ <AutoCompleteSearch show={showAutoComplete} data={fakeComplete} onClick={(e) => {
|
|
|
|
+ setShowAutoComplete(false);
|
|
|
|
+ SelectTextComplete(e);
|
|
|
|
+ setKeyword(e);
|
|
|
|
+ }} />
|
|
</div>
|
|
</div>
|
|
<ul className={cx("menu_list")}>
|
|
<ul className={cx("menu_list")}>
|
|
<li className={cx("menu_item")}>
|
|
<li className={cx("menu_item")}>
|