Skip to content

Commit

Permalink
Feat: 상담사 카테고리 페이지의 쿼리 파라미터 구분을 통하여 뒤로가기 눌렀을 때 이동하는 페이지를 홈 화면과 검색 페이지…
Browse files Browse the repository at this point in the history
…로 이원화 #233
  • Loading branch information
rmdnps10 committed Apr 21, 2024
1 parent 28571c6 commit 88a3a90
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 16 deletions.
16 changes: 11 additions & 5 deletions src/components/Buyer/BuyerCategoryResult/CategoryResultHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@ import { Grey1, Grey6, White } from 'styles/color';
import { Heading } from 'styles/font';
import { ReactComponent as Back } from 'assets/icons/icon-back.svg';
import { useNavigate } from 'react-router-dom';
import { useCallback, useMemo } from 'react';
interface ResultHeaderProps {
categoryType: string;
}
export const CategoryResultHeader = ({ categoryType }: ResultHeaderProps) => {
const url = new URL(window.location.href);
const params = useMemo(() => new URLSearchParams(url.search), [url.search]);
const navigate = useNavigate();
const handleClickBackIcon = useCallback(() => {
if (params.has('from', 'search')) {
navigate('/search');
} else {
navigate('/share');
}
}, [navigate, params]);
return (
<Wrapper>
<BackIcon
onClick={() => {
navigate(-1);
}}
/>
<BackIcon onClick={handleClickBackIcon} />
<Heading color={Grey1}>{categoryType}</Heading>
</Wrapper>
);
Expand Down
52 changes: 42 additions & 10 deletions src/components/Buyer/Common/CartegorySearch.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useNavigate } from 'react-router-dom';
import { useLocation, useNavigate } from 'react-router-dom';
import { useSetRecoilState } from 'recoil';
import styled from 'styled-components';
import { Grey6 } from 'styles/color';
import { Characters } from 'utils/Characters';
import { searchKeywordState } from 'utils/atom';

export const CartegorySearch = () => {
const { pathname } = useLocation();
const navigate = useNavigate();
const setSearchKeyword = useSetRecoilState(searchKeywordState);
return (
Expand All @@ -16,7 +16,11 @@ export const CartegorySearch = () => {
number={1}
onClick={() => {
setSearchKeyword('연애갈등');
navigate('/categorySearch');
if (pathname === '/search') {
navigate('/categorySearch?from=search');
} else {
navigate('/categorySearch');
}
}}
/>
<Text>연애갈등</Text>
Expand All @@ -26,7 +30,11 @@ export const CartegorySearch = () => {
number={2}
onClick={() => {
setSearchKeyword('이별/재회');
navigate('/categorySearch');
if (pathname === '/search') {
navigate('/categorySearch?from=search');
} else {
navigate('/categorySearch');
}
}}
/>
<Text>이별/재회</Text>
Expand All @@ -36,7 +44,11 @@ export const CartegorySearch = () => {
number={3}
onClick={() => {
setSearchKeyword('여자심리');
navigate('/categorySearch');
if (pathname === '/search') {
navigate('/categorySearch?from=search');
} else {
navigate('/categorySearch');
}
}}
/>
<Text>여자심리</Text>
Expand All @@ -46,7 +58,11 @@ export const CartegorySearch = () => {
number={4}
onClick={() => {
setSearchKeyword('남자심리');
navigate('/categorySearch');
if (pathname === '/search') {
navigate('/categorySearch?from=search');
} else {
navigate('/categorySearch');
}
}}
/>
<Text>남자심리</Text>
Expand All @@ -58,7 +74,11 @@ export const CartegorySearch = () => {
number={5}
onClick={() => {
setSearchKeyword('썸/연애시작');
navigate('/categorySearch');
if (pathname === '/search') {
navigate('/categorySearch?from=search');
} else {
navigate('/categorySearch');
}
}}
/>
<Text>썸/연애시작</Text>
Expand All @@ -68,7 +88,11 @@ export const CartegorySearch = () => {
number={6}
onClick={() => {
setSearchKeyword('짝사랑');
navigate('/categorySearch');
if (pathname === '/search') {
navigate('/categorySearch?from=search');
} else {
navigate('/categorySearch');
}
}}
/>
<Text>짝사랑</Text>
Expand All @@ -78,7 +102,11 @@ export const CartegorySearch = () => {
number={7}
onClick={() => {
setSearchKeyword('권태기');
navigate('/categorySearch');
if (pathname === '/search') {
navigate('/categorySearch?from=search');
} else {
navigate('/categorySearch');
}
}}
/>
<Text>권태기</Text>
Expand All @@ -88,7 +116,11 @@ export const CartegorySearch = () => {
number={8}
onClick={() => {
setSearchKeyword('기타');
navigate('/categorySearch');
if (pathname === '/search') {
navigate('/categorySearch?from=search');
} else {
navigate('/categorySearch');
}
}}
/>
<Text>기타</Text>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Buyer/BuyerHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const BuyerHome = () => {
navigate('/share');
}
} catch (e) {
console.log(e);
alert(e);
}
};
fectchSearchResults();
Expand Down

0 comments on commit 88a3a90

Please sign in to comment.