|
@@ -1,38 +1,38 @@
|
|
-import React, { useEffect, useState, useRef } from "react";
|
|
|
|
-import classNames from "classnames/bind";
|
|
|
|
-import styles from "./Header.scss";
|
|
|
|
-import { Link } from "react-router-dom";
|
|
|
|
-import { ReactComponent as IconLogo } from "@assets/img/svg/logo_metarare.svg";
|
|
|
|
-import { ReactComponent as IconSearchGray } from "@assets/img/svg/ico_search_gray.svg";
|
|
|
|
-import { ReactComponent as IconArrow } from "@assets/img/svg/ico_arr_gray.svg";
|
|
|
|
import { ReactComponent as IconActivity } from "@assets/img/svg/ico_activity.svg";
|
|
import { ReactComponent as IconActivity } from "@assets/img/svg/ico_activity.svg";
|
|
-import { ReactComponent as IconTwitter } from "@assets/img/svg/ico_twitter.svg";
|
|
|
|
-import { ReactComponent as IconInstagram } from "@assets/img/svg/ico_insta.svg";
|
|
|
|
|
|
+import { ReactComponent as IconArrow } from "@assets/img/svg/ico_arr_gray.svg";
|
|
import { ReactComponent as IconFacebook } from "@assets/img/svg/ico_facebook.svg";
|
|
import { ReactComponent as IconFacebook } from "@assets/img/svg/ico_facebook.svg";
|
|
|
|
+import { ReactComponent as IconInstagram } from "@assets/img/svg/ico_insta.svg";
|
|
|
|
+import { ReactComponent as IconSearchGray } from "@assets/img/svg/ico_search_gray.svg";
|
|
|
|
+import { ReactComponent as IconTwitter } from "@assets/img/svg/ico_twitter.svg";
|
|
|
|
+import { ReactComponent as IconLogo } from "@assets/img/svg/logo_metarare.svg";
|
|
import URLInfo from "@src/constants/URLInfo";
|
|
import URLInfo from "@src/constants/URLInfo";
|
|
-import useSearch from "@src/hooks/useSearch";
|
|
|
|
-import ProfileModal from "../common/ProfileModal";
|
|
|
|
import LayerContainer from "@src/containers/common/LayerContainer";
|
|
import LayerContainer from "@src/containers/common/LayerContainer";
|
|
-import { useDispatch, useSelector } from "react-redux";
|
|
|
|
import useLogin from "@src/hooks/useLogin";
|
|
import useLogin from "@src/hooks/useLogin";
|
|
-import { useHistory, useLocation } from "react-router";
|
|
|
|
|
|
+import useSearch from "@src/hooks/useSearch";
|
|
|
|
+import { fetchExploreHint } from "@src/store/reducers/ExploreReducer";
|
|
import { fetchUserInfo } from "@src/store/reducers/UserReducer";
|
|
import { fetchUserInfo } from "@src/store/reducers/UserReducer";
|
|
-import { YoutubeIcon } from "../common/icon/youtube";
|
|
|
|
-import { useDebounce, useOnClickOutside} from "usehooks-ts";
|
|
|
|
|
|
+import classNames from "classnames/bind";
|
|
|
|
+import React, { useEffect, useRef, useState } from "react";
|
|
|
|
+import { useDispatch, useSelector } from "react-redux";
|
|
|
|
+import { useHistory, useLocation } from "react-router";
|
|
|
|
+import { Link } from "react-router-dom";
|
|
|
|
+import { useDebounce, useOnClickOutside } from "usehooks-ts";
|
|
import AutoCompleteSearch from "../common/AutoCompleteSearch";
|
|
import AutoCompleteSearch from "../common/AutoCompleteSearch";
|
|
-import { fetchExploreHint } from "@src/store/reducers/ExploreReducer";
|
|
|
|
|
|
+import ProfileModal from "../common/ProfileModal";
|
|
|
|
+import { YoutubeIcon } from "../common/icon/youtube";
|
|
|
|
+import styles from "./Header.scss";
|
|
|
|
|
|
const cx = classNames.bind(styles);
|
|
const cx = classNames.bind(styles);
|
|
|
|
|
|
const Header: React.FC = () => {
|
|
const Header: React.FC = () => {
|
|
- const searchRef = useRef(null)
|
|
|
|
|
|
+ const searchRef = useRef(null);
|
|
const history = useHistory();
|
|
const history = useHistory();
|
|
const dispatch = useDispatch();
|
|
const dispatch = useDispatch();
|
|
const [showAutoComplete, setShowAutoComplete] = useState<boolean>(false);
|
|
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));
|
|
- setShowAutoComplete(false)
|
|
|
|
|
|
+ setShowAutoComplete(false);
|
|
};
|
|
};
|
|
const SelectTextComplete = (text: string) => {
|
|
const SelectTextComplete = (text: string) => {
|
|
history.push(URLInfo.getSearchResultUrl(text));
|
|
history.push(URLInfo.getSearchResultUrl(text));
|
|
@@ -40,12 +40,15 @@ const Header: React.FC = () => {
|
|
const { keyword, setKeyword, onKeyPress, handleSearch } = useSearch({
|
|
const { keyword, setKeyword, onKeyPress, handleSearch } = useSearch({
|
|
onSearch,
|
|
onSearch,
|
|
});
|
|
});
|
|
- const debouncedValue = useDebounce<string>(keyword, 1000)
|
|
|
|
|
|
+ const debouncedValue = useDebounce<string>(keyword, 1000);
|
|
const [showCommunity, setShowCommunity] = useState(false);
|
|
const [showCommunity, setShowCommunity] = useState(false);
|
|
const [showProfile, setShowProfile] = useState<boolean>(false);
|
|
const [showProfile, setShowProfile] = useState<boolean>(false);
|
|
const location = useLocation();
|
|
const location = useLocation();
|
|
const { handleClickLoginButton, loginText } = useLogin();
|
|
const { handleClickLoginButton, loginText } = useLogin();
|
|
- const { hint } = useSelector((state) => state.explore)
|
|
|
|
|
|
+ const searchText = new URLSearchParams(location.search).get(
|
|
|
|
+ URLInfo.SEARCH_PARAM.SEARCH_TEXT
|
|
|
|
+ );
|
|
|
|
+ const { hint } = useSelector((state) => state.explore);
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
if (showProfile) {
|
|
if (showProfile) {
|
|
dispatch(fetchUserInfo());
|
|
dispatch(fetchUserInfo());
|
|
@@ -71,14 +74,21 @@ const Header: React.FC = () => {
|
|
});
|
|
});
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
- dispatchHint(keyword)
|
|
|
|
|
|
+ dispatchHint(keyword);
|
|
|
|
+ if (URLInfo.isExplorePage(location)) {
|
|
|
|
+ history.push(URLInfo.getSearchResultUrl(keyword));
|
|
|
|
+ }
|
|
}, [debouncedValue]);
|
|
}, [debouncedValue]);
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
- if(!URLInfo.isExplorePage(location)){
|
|
|
|
- setKeyword('')
|
|
|
|
|
|
+ if (!URLInfo.isExplorePage(location)) {
|
|
|
|
+ setKeyword("");
|
|
|
|
+ } else {
|
|
|
|
+ if (searchText) {
|
|
|
|
+ setKeyword(searchText);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }, [location])
|
|
|
|
|
|
+ }, [location]);
|
|
|
|
|
|
return (
|
|
return (
|
|
<div className={cx("header_wrap")}>
|
|
<div className={cx("header_wrap")}>
|