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

[JR-899] 검색 페이지 리팩토링 #220

Merged
merged 8 commits into from
Jul 28, 2024
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useToggle } from '@monorepo/hooks';
import Chip from 'components/Chip';
import Loading from 'components/Loading';
import ReplaceLoginPageModal from 'components/ReplaceLoginPagemModal/ReplaceLoginPageModal';
import { ReplaceLoginPageModal } from 'components/ReplaceLoginPageModal';
import VoteHeader from 'components/VoteHeader';
import { Button } from 'components/button';
import Path from 'lib/Path';
Expand Down
4 changes: 2 additions & 2 deletions apps/jurumarble/src/app/main/components/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function Carousel({ hotDrinkList }: Props) {
>
<Box>
<DrinkImageContainer>
<RankginMark>{index + 1}</RankginMark>
<RankingMark>{index + 1}</RankingMark>
<DrinkImageWrapper
alt={name}
src={image}
Expand Down Expand Up @@ -119,7 +119,7 @@ const DrinkImageContainer = styled.div`
left: 20px;
`;

const RankginMark = styled.div`
const RankingMark = styled.div`
${({ theme }) =>
css`
background-color: ${theme.colors.main_01};
Expand Down
2 changes: 1 addition & 1 deletion apps/jurumarble/src/app/map/components/MapContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useEffect, useRef, useState } from 'react';
import { useToggle } from '@react-hookz/web';
import DrinkItem from 'app/stamp/components/DrinkItem';
import Loading from 'components/Loading';
import ReplaceLoginPageModal from 'components/ReplaceLoginPagemModal/ReplaceLoginPageModal';
import { ReplaceLoginPageModal } from 'components/ReplaceLoginPageModal';
import { Button } from 'components/button';
import Path from 'lib/Path';
import Image from 'next/image';
Expand Down
4 changes: 2 additions & 2 deletions apps/jurumarble/src/app/my/components/VoteCountContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use client';

import { TAB_LIST, TabList } from 'src/types/my';
import styled, { css } from 'styled-components';

import { TAB_LIST, TabList } from '../constants';
import useGetTheNumberOfMyVoteService from '../services/useGetCountedVoteService';

interface Props {
Expand Down Expand Up @@ -31,7 +31,7 @@ function VoteCountContainer({ selectedTab, onClickSelectedTab }: Props) {
<VoteCount>
{id === 'created-vote'
? writtenVoteCnt
: id === 'paticipated-vote'
: id === 'participated-vote'
? joinedVoteCnt
: id === 'bookmarked-vote'
? bookmarkedVoteCnt
Expand Down
4 changes: 2 additions & 2 deletions apps/jurumarble/src/app/my/components/VoteListContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import { useCreateQueryString } from 'hooks/useCreateQueryString';
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
import { TabList } from 'src/types/my';
import styled, { css } from 'styled-components';

import VoteCountContainer from './VoteCountContainer';
import VoteItem from './VoteItem';
import { TabList } from '../constants';
import useGetMyBookmarkedVoteListService from '../services/useGetMyBookmarkedVoteListService';
import useGetMyCreatedVoteListService from '../services/useGetMyCreatedVoteListService';
import useGetMyParticipatedVoteListService from '../services/useGetMyParticipatedVoteListService';
Expand All @@ -18,7 +18,7 @@ import useGetMyParticipatedVoteListService from '../services/useGetMyParticipate
const MY_VOTE_LIST_SERVICE = {
'created-vote': useGetMyCreatedVoteListService,
'bookmarked-vote': useGetMyBookmarkedVoteListService,
'paticipated-vote': useGetMyParticipatedVoteListService,
'participated-vote': useGetMyParticipatedVoteListService,
};

function VoteListContainer() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const TAB_LIST = [
{ id: 'created-vote', name: '작성한 투표' },
{ id: 'paticipated-vote', name: '참여한 투표' },
{ id: 'participated-vote', name: '참여한 투표' },
{ id: 'bookmarked-vote', name: '북마크 투표' },
] as const;

Expand Down
42 changes: 42 additions & 0 deletions apps/jurumarble/src/app/search/components/DrinkInfoList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import Path from 'lib/Path';
import { useRouter } from 'next/navigation';
import styled from 'styled-components';

import DrinkItem from './DrinkItem';
import { useSearchChangeContext, useSearchValueContext } from '../context';

function DrinkInfoList() {
const router = useRouter();

const { drinkList, selectedTab } = useSearchValueContext();

const { onToggleReplaceLoginPageModal, drinkSubscribe } =
useSearchChangeContext();

const onClickDrinkItem = (id: number) => {
router.push(`${Path.DRINK_INFO_PAGE}/${id}`);
};

return (
<Container>
{drinkList.map((drinkInfo) => (
<DrinkItem
key={drinkInfo.id}
drinkInfo={drinkInfo}
onClickDrinkItem={() => onClickDrinkItem(drinkInfo.id)}
onToggleReplaceLoginPageModal={onToggleReplaceLoginPageModal}
/>
))}
{selectedTab === 'drinkInfo' && <div ref={drinkSubscribe} />}
</Container>
);
}

const Container = styled.div`
display: flex;
flex-direction: column;
gap: 8px;
margin-top: 24px;
`;

export default DrinkInfoList;
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { DRINK_INFO_SORT_LIST } from 'lib/constants';
import styled from 'styled-components';

import DrinkInfoList from './DrinkInfoList';
import RegionSmallSelect from './RegionSmallSelect';
import SortSelect from './SortSelect';
import { useSearchChangeContext, useSearchValueContext } from '../context';

function DrinkInfoTopSectionItem() {
const { drinkInfoSortOption } = useSearchValueContext();
const { onChangeDrinkInfoSortOption } = useSearchChangeContext();

return (
<>
<SelectContainer>
<SortSelect
defaultOption={drinkInfoSortOption}
onChangeSortOption={onChangeDrinkInfoSortOption}
options={DRINK_INFO_SORT_LIST}
/>
<RegionSmallSelect />
</SelectContainer>
<DrinkInfoList />
</>
);
}

const SelectContainer = styled.div`
display: flex;
margin-top: 40px;
gap: 4px;
`;

export default DrinkInfoTopSectionItem;
65 changes: 0 additions & 65 deletions apps/jurumarble/src/app/search/components/DrinkList.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { DRINK_VOTE_SORT_LIST } from 'lib/constants';
import styled from 'styled-components';

import DrinkVoteList from './DrinkVoteList';
import RegionSmallSelect from './RegionSmallSelect';
import SortSelect from './SortSelect';
import { useSearchChangeContext, useSearchValueContext } from '../context';

function DrinkVoteBottomSectionItem() {
const { drinkVoteSortOption } = useSearchValueContext();
const { onChangeDrinkVoteSortOption } = useSearchChangeContext();

return (
<>
<SelectContainer>
<SortSelect
defaultOption={drinkVoteSortOption}
onChangeSortOption={onChangeDrinkVoteSortOption}
options={DRINK_VOTE_SORT_LIST}
/>
<RegionSmallSelect />
</SelectContainer>
<DrinkVoteList />
</>
);
}

const SelectContainer = styled.div`
display: flex;
margin-top: 40px;
gap: 4px;
`;

export default DrinkVoteBottomSectionItem;
32 changes: 7 additions & 25 deletions apps/jurumarble/src/app/search/components/DrinkVoteList.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,17 @@
import { useSearchParams } from 'next/navigation';
import styled from 'styled-components';

import DrinkVoteItem from './DrinkVoteItem';
import useVoteDrinkService from '../services/useVoteDrinkService';
import { useSearchChangeContext, useSearchValueContext } from '../context';

interface Props {
searchText: string;
sortOption: string;
regionOption: string;
isSelectedTab: boolean;
onToggleReplaceLoginPageModal: () => void;
}
function DrinkVoteList({
searchText,
sortOption,
regionOption,
onToggleReplaceLoginPageModal,
}: Props) {
const searchParams = useSearchParams();
const selectedTab = searchParams.get('selectedTab');
function DrinkVoteList() {
const { voteDrinkList, selectedTab } = useSearchValueContext();
const { onToggleReplaceLoginPageModal, drinkVoteSubscribe } =
useSearchChangeContext();

const { voteDrinkList, subscribe } = useVoteDrinkService({
page: 0,
size: 3,
keyword: searchText,
region: regionOption,
sortBy: sortOption,
});
if (!voteDrinkList) {
return <></>;
}

return (
<Container>
{voteDrinkList.map((voteDrink, index) => (
Expand All @@ -39,7 +21,7 @@ function DrinkVoteList({
onToggleReplaceLoginPageModal={onToggleReplaceLoginPageModal}
/>
))}
{selectedTab === 'drinkVote' && <div ref={subscribe} />}
{selectedTab === 'drinkVote' && <div ref={drinkVoteSubscribe} />}
</Container>
);
}
Expand Down
25 changes: 25 additions & 0 deletions apps/jurumarble/src/app/search/components/NoSearchResult.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Image from 'next/image';
import { noSearchResult } from 'public/images';
import styled from 'styled-components';

function NoSearchResult() {
return (
<Container>
<Image
alt="검색 결과가 없습니다."
src={noSearchResult}
width={140}
height={140}
/>
<Text>검색 결과가 없어요. 다른 검색어를 입력해보세요.</Text>
</Container>
);
}

const Container = styled.div`
display: flex;
`;

const Text = styled.p``;

export default NoSearchResult;
14 changes: 7 additions & 7 deletions apps/jurumarble/src/app/search/components/RegionSmallSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import { REGION_LIST } from 'lib/constants';
import SvgIcExpandMore from 'src/assets/icons/components/IcExpandMore';
import styled, { css } from 'styled-components';

interface Props {
defaultOption: string;
onChangeSortOption: (id: string) => void;
}
import { useSearchChangeContext, useSearchValueContext } from '../context';

function RegionSmallSelect({ defaultOption, onChangeSortOption }: Props) {
function RegionSmallSelect() {
const [isOpen, onToggleOpen] = useToggle();

const { regionOption } = useSearchValueContext();
const { onChangeRegionOption } = useSearchChangeContext();

return (
<SelectStyled isOpen={isOpen}>
<Select
defaultValue={defaultOption}
onChangeSelectedOption={onChangeSortOption}
defaultValue={regionOption}
onChangeSelectedOption={onChangeRegionOption}
options={[
{ value: '', label: '지역', lat: 0, long: 0 },
...REGION_LIST,
Expand Down
Loading
Loading