Skip to content

Commit

Permalink
feat: 태그 추가 및 검색 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
Namyunha committed Jul 26, 2024
1 parent 5c16a1a commit d137ad0
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 28 deletions.
32 changes: 32 additions & 0 deletions src/app/review/write/_components/ReviewWriteTags.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import FilterTab from '@/components/FilterTab';
import { TAGS } from '@/constants/reviewFilter';
import { reviewStore } from '@/store/userStore';
import { ReviewDetailType, TagsKey } from '@/types/review';

type ReviewDetailTagsProps = Pick<ReviewDetailType, 'tags'>;

export default function ReviewWriteTags({ tags }: ReviewDetailTagsProps) {
const reviewStatus = reviewStore();

const addCategoryHandler = (tag: TagsKey) => {
!reviewStatus.likeCategory.find((el) => el === tag)
? reviewStatus.setLikeCategory([...reviewStatus.likeCategory, tag])
: reviewStatus.setLikeCategory(
reviewStatus.likeCategory.filter((el) => el !== tag)
);
};

return (
<div className="flex flex-wrap gap-8 items-center justify-center">
{tags.map((tag) => (
<FilterTab
onClick={() => addCategoryHandler(tag)}
isActive={!!reviewStatus.likeCategory.find((el) => el === tag)}
key={tag}
value={TAGS[tag]}
iconName={tag}
/>
))}
</div>
);
}
85 changes: 85 additions & 0 deletions src/app/review/write/_components/SearchForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
'use client';

import React, { useEffect, useState } from 'react';
import { useCafeListInfiniteQuery } from '@/api/cafe/queries';
import Icon from '@/components/Icon';
import { useFilterStore } from '@/store/filterStore';
import { reviewStore } from '@/store/userStore';
import { CafeItemType } from '@/types/cafe';

export default function SearchForm() {
const reviewStatus = reviewStore();
const [keyword, setKeyword] = useState('');
const [searchResult, setSearchResult] = useState<CafeItemType[]>();
const onChangeData = (e: React.FormEvent<HTMLInputElement>) => {
setKeyword(e.currentTarget.value);
};

const { activeTags, activeLocation } = useFilterStore();

const { data } = useCafeListInfiniteQuery({
tags: activeTags,
location: activeLocation,
pageSize: 20,
});

const updateResult = () => {
const result = data?.pages[0].data.cafeInfos.filter((el) =>
el.cafeName.includes(keyword)
);
setSearchResult(result);
};

useEffect(() => {
const debounce = setTimeout(() => {
if (keyword) updateResult();
}, 200);
return () => {
clearTimeout(debounce);
};
}, [keyword]);

const setCafeInfoHandler = (cafe: CafeItemType) => {
reviewStatus.setResetPlaceState();
reviewStatus.setCafeName(cafe.cafeName);
reviewStatus.setCafeLoca(cafe.cafeLoca);
reviewStatus.switchSearchLoca();
reviewStatus.setModalState();
};

return (
<>
<div className="py-9">
<div className="flex items-center justify-center gap-5 mb-5 px-5">
<span
onClick={() => reviewStatus.switchSearchLoca()}
className="inline-block cursor-pointer">
<Icon name="arrow_left" />
</span>
<input
onChange={onChangeData}
className="bg-zinc-200 w-[90%] px-3 py-1 focus:outline-none"
placeholder="카페명을 입력하세요"
type="text"
/>
</div>
<ul>
{searchResult?.map((cafe) => (
<>
<div
onClick={() => setCafeInfoHandler(cafe)}
className="py-4 px-7 cursor-pointer hover:bg-primary hover:bg-opacity-30"
key={cafe.cafeId}>
<li className="font-bold">{cafe.cafeName}</li>
<li className="text-text_light_grey text-xs">
{cafe.cafeLoca}
</li>
</div>
<div className="border-[1px] border-bg_disabled" />
</>
))}
</ul>
</div>
</>
);
}
56 changes: 28 additions & 28 deletions src/mocks/data/cafeList.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const mockCafeList = [
{
cafeId: 1,
cafeName: '미뉴트빠삐용',
cafeLoca: '서울 강남구 도산대로 51길 37 지하 1층',
cafeName: '블루보틀 카페',
cafeLoca: '서울 종로구 인사동길 41',
rating: 4.2,
reviewCount: 1,
cafeImageUrls: [
Expand All @@ -23,8 +23,8 @@ export const mockCafeList = [
},
{
cafeId: 2,
cafeName: '미뉴트빠삐용',
cafeLoca: '서울 강남구 도산대로 51길 37 지하 1층',
cafeName: '스타벅스',
cafeLoca: '서울 강남구 테헤란로 152',
rating: 4.2,
reviewCount: 2,
cafeImageUrls: [
Expand All @@ -45,8 +45,8 @@ export const mockCafeList = [
},
{
cafeId: 3,
cafeName: '미뉴트빠삐용',
cafeLoca: '서울 강남구 도산대로 51길 37 지하 1층',
cafeName: '커피빈',
cafeLoca: '서울 용산구 한강대로 292',
rating: 4.2,
reviewCount: 3,
cafeImageUrls: [
Expand All @@ -67,8 +67,8 @@ export const mockCafeList = [
},
{
cafeId: 4,
cafeName: '미뉴트빠삐용',
cafeLoca: '서울 강남구 도산대로 51길 37 지하 1층',
cafeName: '할리스커피',
cafeLoca: '서울 마포구 양화로 45',
rating: 4.2,
reviewCount: 4,
cafeImageUrls: [
Expand All @@ -89,8 +89,8 @@ export const mockCafeList = [
},
{
cafeId: 5,
cafeName: '미뉴트빠삐용',
cafeLoca: '서울 강남구 도산대로 51길 37 지하 1층',
cafeName: '탐앤탐스',
cafeLoca: '서울 서초구 서초대로 78길 23',
rating: 4.2,
reviewCount: 5,
cafeImageUrls: [
Expand All @@ -111,8 +111,8 @@ export const mockCafeList = [
},
{
cafeId: 6,
cafeName: '미뉴트빠삐용',
cafeLoca: '서울 강남구 도산대로 51길 37 지하 1층',
cafeName: '이디야커피',
cafeLoca: '서울 종로구 새문안로 82',
rating: 4.2,
reviewCount: 6,
cafeImageUrls: [
Expand All @@ -133,8 +133,8 @@ export const mockCafeList = [
},
{
cafeId: 7,
cafeName: '미뉴트빠삐용',
cafeLoca: '서울 강남구 도산대로 51길 37 지하 1층',
cafeName: '카페베네',
cafeLoca: '서울 송파구 올림픽로 300',
rating: 4.2,
reviewCount: 7,
cafeImageUrls: [
Expand All @@ -155,8 +155,8 @@ export const mockCafeList = [
},
{
cafeId: 8,
cafeName: '미뉴트빠삐용',
cafeLoca: '서울 강남구 도산대로 51길 37 지하 1층',
cafeName: '메가커피',
cafeLoca: '서울 강동구 성내로 45',
rating: 4.2,
reviewCount: 8,
cafeImageUrls: [
Expand All @@ -177,8 +177,8 @@ export const mockCafeList = [
},
{
cafeId: 9,
cafeName: '미뉴트빠삐용',
cafeLoca: '서울 강남구 도산대로 51길 37 지하 1층',
cafeName: '파스쿠찌',
cafeLoca: '서울 은평구 은평로 155',
rating: 4.2,
reviewCount: 9,
cafeImageUrls: [
Expand All @@ -199,8 +199,8 @@ export const mockCafeList = [
},
{
cafeId: 10,
cafeName: '미뉴트빠삐용',
cafeLoca: '서울 강남구 도산대로 51길 37 지하 1층',
cafeName: '커피나무',
cafeLoca: '서울 노원구 동일로 1700',
rating: 4.2,
reviewCount: 10,
cafeImageUrls: [
Expand All @@ -221,8 +221,8 @@ export const mockCafeList = [
},
{
cafeId: 11,
cafeName: '미뉴트빠삐용',
cafeLoca: '서울 강남구 도산대로 51길 37 지하 1층',
cafeName: '빽다방',
cafeLoca: '서울 성동구 왕십리로 241',
rating: 4.2,
reviewCount: 11,
cafeImageUrls: [
Expand All @@ -243,8 +243,8 @@ export const mockCafeList = [
},
{
cafeId: 12,
cafeName: '미뉴트빠삐용',
cafeLoca: '서울 강남구 도산대로 51길 37 지하 1층',
cafeName: '엔제리너스',
cafeLoca: '서울 동작구 상도로 76',
rating: 4.2,
reviewCount: 12,
cafeImageUrls: [
Expand All @@ -265,8 +265,8 @@ export const mockCafeList = [
},
{
cafeId: 13,
cafeName: '미뉴트빠삐용',
cafeLoca: '서울 강남구 도산대로 51길 37 지하 1층',
cafeName: '더벤티',
cafeLoca: '서울 서대문구 연세로 50',
rating: 4.2,
reviewCount: 13,
cafeImageUrls: [
Expand All @@ -287,8 +287,8 @@ export const mockCafeList = [
},
{
cafeId: 14,
cafeName: '미뉴트빠삐용',
cafeLoca: '서울 강남구 도산대로 51길 37 지하 1층',
cafeName: '투썸플레이스',
cafeLoca: '서울 강서구 강서로 267',
rating: 4.2,
reviewCount: 14,
cafeImageUrls: [
Expand Down

0 comments on commit d137ad0

Please sign in to comment.