Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/header #55 #70

Merged
merged 11 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
"@iconify/react": "^5.2.0",
"@mui/icons-material": "^6.4.1",
"@mui/material": "^6.4.1",
"@types/react-slick": "^0.23.13",
"@tanstack/react-query": "^5.66.0",
"@types/react-slick": "^0.23.13",
"axios": "^1.7.9",
"chart.js": "^4.4.7",
"lucide-react": "^0.474.0",
"pretendard": "^1.3.9",
"react": "^18.3.1",
"react-chartjs-2": "^5.3.0",
"react-daum-postcode": "^3.2.0",
"react-datepicker": "^8.0.0",
"react-daum-postcode": "^3.2.0",
"react-dom": "^18.3.1",
"react-router-dom": "^7.1.1",
"react-slick": "^0.30.3",
Expand Down
38 changes: 0 additions & 38 deletions src/components/HeaderIconMenu.tsx

This file was deleted.

96 changes: 76 additions & 20 deletions src/components/ResponsiveHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import icMyPage from '../assets/header/icon-mypage.svg';
import icUpload from '../assets/header/icon-upload.svg';
import imgTicket from '../assets/ticket.svg';
import { useNavigate } from "react-router-dom";
import { ChangeEvent, useEffect, useRef, useState } from "react";
import { ChangeEvent, KeyboardEvent, useEffect, useRef, useState } from "react";
import CategoryMenu from './CategoryMenu';
import { useModalContext } from './Modal/context/ModalContext';
import SplashModal from '../pages/login/components/SplashModal';
import imgVector from '../assets/Vector.png';
import { ReactComponent as IcList } from '../assets/icList.svg';
import icDel from '../assets/icDel.svg';

const recentKeywords = ['์• ํ”Œ์›Œ์น˜','์• ํ”Œ์›Œ์น˜','์• ํ”Œ์›Œ์น˜','์• ํ”Œ์›Œ์น˜',
'์• ํ”Œ์›Œ์น˜','์• ํ”Œ์›Œ์น˜','์• ํ”Œ์›Œ์น˜','์• ํ”Œ์›Œ์น˜','์• ํ”Œ์›Œ์น˜','์• ํ”Œ์›Œ์น˜',
];
import axiosInstance from '../apis/axiosInstance';
import { TSearch } from '../types/searchKeywords';
import { useAuth } from '../context/AuthContext';
import { useIsSearchCompleted } from '../store/store';

const ResponsiveHeader = () => {
const navigate = useNavigate();
Expand All @@ -33,6 +33,23 @@ const ResponsiveHeader = () => {
const searchRef = useRef<HTMLDivElement>(null);
const [searchText, setSearchText] = useState<string>('');
const categoryRef = useRef<HTMLDivElement>(null);
const [hotKeywords, setHotKeywords] = useState<string[]>([]);
const [recentKeywords, setRecentKeywords] = useState<string[]>([]);
const { isAuthenticated, logout } = useAuth();
const isSearchCompleted = useIsSearchCompleted(v=>v.isSearchCompleted);

const getSearch = async () => {
const { data }:{data:TSearch} = await axiosInstance.get(
isAuthenticated ? '/api/member/search'
: '/api/permit/search'
);

console.log('recentSearch:', data.result.recentSearch);
setHotKeywords(data.result.popularSearch);
setRecentKeywords(data.result.recentSearch);
};
const delSearch = async (keyword:string) =>
await axiosInstance.delete(`/api/member/search?keyword=${keyword}`);

const handleCategoryOut = (e:MouseEvent) => {
const currentCategoryRef = categoryRef.current;
Expand All @@ -52,15 +69,36 @@ const ResponsiveHeader = () => {
const handleSearchInput = (e: ChangeEvent<HTMLInputElement>) => {
setSearchText(e.target.value);
};
const handleSearchEnter = (e:KeyboardEvent<HTMLInputElement>) => {
if (e.key === "Enter") {
navigate(`/search/${searchText}`);
setIsSearchClicked(false);
};
};

const handleDelKeyword = (keyword:string) => {
// delSearch(): ํ•ด๋‹น ํ‚ค์›Œ๋“œ ์„œ๋ฒ„์—์„œ ์‚ญ์ œ
delSearch(keyword).then(_=>getSearch());
};

const handleOpenModal = () => {
openModal(({ onClose }) => <SplashModal onClose={onClose} />);
};

const onClickLoginBtn = () => {
setIsLoggedIn((prev) => !prev); // ํด๋ฆญํ•  ๋•Œ๋งˆ๋‹ค ๋กœ๊ทธ์ธ/๋กœ๊ทธ์•„์›ƒ ์ƒํƒœ ๋ณ€๊ฒฝ
if (!isAuthenticated) handleOpenModal();
else logout();
};

// ์‹œ์ž‘ํ•˜์ž๋งˆ์ž ํ˜ธ์ถœ๋  API
useEffect(() => {
getSearch();
}, [isAuthenticated]);

// ๊ฒ€์ƒ‰ํ•  ๋•Œ๋งˆ๋‹ค ์ตœ์‹  ๊ฒ€์ƒ‰์–ด ๊ฐฑ์‹ 
useEffect(() => {
getSearch();
}, [isSearchCompleted]);

useEffect(() => {
document.addEventListener('mousedown', handleClickOutside);
document.addEventListener('mousedown', handleCategoryOut);
Expand All @@ -74,8 +112,8 @@ const ResponsiveHeader = () => {
<>
<Wrapper>
<TopContainer>
<LoginBtn onClick={onClickLoginBtn} state={String(isLoggedIn)}>
{isLoggedIn ? '๋กœ๊ทธ์•„์›ƒ' : '๋กœ๊ทธ์ธ'}
<LoginBtn onClick={onClickLoginBtn} state={String(isAuthenticated)}>
{isAuthenticated ? '๋กœ๊ทธ์•„์›ƒ' : '๋กœ๊ทธ์ธ'}
</LoginBtn>
<LineDiv height={'27px'} margin={'0 32px'} className='line-1' />
<SmallIconDiv>
Expand Down Expand Up @@ -104,37 +142,46 @@ const ResponsiveHeader = () => {
<SearchBoxDiv>
<TicketImg src={ticket} />
<SearchInput
type="text"
type="search"
onClick={()=>setIsSearchClicked(true)}
value={searchText}
onChange={handleSearchInput}
onKeyUp={handleSearchEnter}
/>
<SearchIcon src={icSearch} />
<KeywordContainer
ref={searchRef}
$show={String(isSearchClicked)}
>
<KeywordBox>
{isLoggedIn===false
? <KeywordBox>
<KeywordTitle>
<img src={imgVector} width={15} height={15} />
<Span>์ตœ๊ทผ ๊ฒ€์ƒ‰</Span>
</KeywordTitle>
<RecentKeywordsBox>
{recentKeywords.map((v,_) => (
{recentKeywords.length!==0 ?
recentKeywords.map((v,_) => (
<RecentKeyword key={_}>
{v}
<DelImg src={icDel} width={9.096} height={8.901} />
<DelImg src={icDel} width={9.096} height={8.901}
onClick={()=>handleDelKeyword(v)}
/>
</RecentKeyword>
))}
))
: <KeywordSpan>์ตœ๊ทผ ๊ฒ€์ƒ‰ ๋‚ด์—ญ์ด ์—†์Šต๋‹ˆ๋‹ค.</KeywordSpan>
}
</RecentKeywordsBox>
</KeywordBox>
: <></>
}
<KeywordBox>
<KeywordTitle>
<img src={imgVector} width={15} height={15} />
<Span>ํ˜„์žฌ ์ธ๊ธฐ์žˆ๋Š” ๊ฒ€์ƒ‰์–ด</Span>
</KeywordTitle>
<HotKeywordsBox>
{recentKeywords.map((v,_) => (
{hotKeywords.map((v,_) => (
<HotKeyword key={_}>
<IcList width={9} height={9} fill={"rgba(201, 8, 255, 0.20)"} />
{v}
Expand Down Expand Up @@ -172,7 +219,7 @@ export default ResponsiveHeader;
const Wrapper = styled.div`
display: flex;
flex-direction: column;
max-width: 1084px;
width: 1084px;
height: 188px;
box-sizing: border-box;
z-index: 100;
Expand Down Expand Up @@ -317,15 +364,16 @@ const SearchIcon = styled.img`
`;

const KeywordContainer = styled.div<{$show:string}>`
// width: 560px;
width: 100%;
height: 386px;
width: 560px;
// width: 100%;
// height: 386px;
border-radius: 18px;
border: 1px solid #E4E4E4;
background-color: #FFF;
position: absolute;
left: 0;
left: 50%;
top: 120%;
transform: translateX(-50%);
padding: 38px 43px 5px 43px;
box-sizing: border-box;
display: ${props => props.$show==='true'
Expand Down Expand Up @@ -384,6 +432,14 @@ const RecentKeyword = styled.div`
cursor: default;
}
`
const KeywordSpan = styled.span`
color: #8F8E94;
font-family: Pretendard;
font-size: 14px;
font-style: normal;
font-weight: 400;
line-height: 36.832px; /* 306.932% */
`
const DelImg = styled.img`
&:hover {
cursor: pointer;
Expand Down
3 changes: 0 additions & 3 deletions src/layout/RootLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import styled from 'styled-components';
import Header from '../components/Header';
import { Outlet } from 'react-router-dom';
import HeaderIconMenu from '../components/HeaderIconMenu';
import ResponsiveHeader from '../components/ResponsiveHeader';

const RootLayout = () => {
return (
<Wrapper>
<ResponsiveHeader />
{/* <HeaderIconMenu /> */}
<Outlet />
</Wrapper>
);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/homepage/homePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const HomePage: React.FC = () => {
}
};

fetchHomeData();
// fetchHomeData();
}, []);

if (!homeData) return <div>Loading...</div>;
Expand Down
15 changes: 12 additions & 3 deletions src/pages/raffleList/SearchResultPage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { useState, useEffect, useRef } from 'react';
import { useParams, useLocation } from 'react-router-dom';
import { useParams } from 'react-router-dom';
import styled from 'styled-components';
import ProductCard from '../../components/ProductCard';
import RaffleProps from '../../components/RaffleProps';
import axiosInstance from '../../apis/axiosInstance';
import { useAuth } from '../../context/AuthContext';
import { useIsSearchCompleted } from '../../store/store';

const SearchResultPage: React.FC = () => {
const { type } = useParams<{ type?: string }>();
Expand All @@ -12,15 +14,21 @@ const SearchResultPage: React.FC = () => {
const [page, setPage] = useState(1);
const [hasMore, setHasMore] = useState(true);
const [isLoading, setIsLoading] = useState(false);
const { isAuthenticated } = useAuth();
const setIsCompleted = useIsSearchCompleted(v=>v.setIsSearchCompleted);

const fetchMoreProducts = async () => {
if (!hasMore || isLoading) return;

setIsLoading(true);
try {
const { data } = await axiosInstance.get('/api/permit/search/raffles', {
const apirequest = isAuthenticated ? '/api/member/search/raffles'
: '/api/permit/search/raffles'

const { data } = await axiosInstance.get(apirequest, {
params: { keyword: type },
});
setIsCompleted(true); // Zustand ์ƒํƒœ ์—…๋ฐ์ดํŠธ

const startIndex = (page - 1) * 16;
const endIndex = startIndex + 16;
Expand All @@ -40,7 +48,8 @@ const SearchResultPage: React.FC = () => {
setPage((prev) => prev + 1);
} catch (error) {
console.error('๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ ์‹คํŒจ:', error);
} finally {
}
finally {
setIsLoading(false);
}
};
Expand Down
11 changes: 11 additions & 0 deletions src/store/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { create } from "zustand";

interface IIsSearchCompleted {
isSearchCompleted: boolean;
setIsSearchCompleted: (v:boolean) => void;
}

export const useIsSearchCompleted = create<IIsSearchCompleted>((set) => ({
isSearchCompleted: false,
setIsSearchCompleted: (v) => set({ isSearchCompleted: v }),
}));
9 changes: 9 additions & 0 deletions src/types/searchKeywords.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export type TSearch = {
isSuccess: boolean,
code: string,
message: string,
result: {
recentSearch: string[],
popularSearch: string[]
}
};