From c25eeb9a8897b6e379393b10724efae189abc56b Mon Sep 17 00:00:00 2001 From: Hyeongseok Kim Date: Sun, 25 Aug 2024 22:17:55 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=B6=94=EC=B2=9C=EC=9E=91=EA=B0=80=20?= =?UTF-8?q?mood=EC=97=90=20=EB=A7=9E=EB=8A=94=20=EC=9E=91=ED=92=88?= =?UTF-8?q?=EC=82=AC=EC=A7=84=EB=B6=80=ED=84=B0=20=EB=B3=B4=EC=9D=B4?= =?UTF-8?q?=EA=B2=8C=20=EB=A1=9C=EC=A7=81=EC=88=98=EC=A0=95=20(#8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/photographer/page.tsx | 85 ++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 31 deletions(-) diff --git a/src/app/photographer/page.tsx b/src/app/photographer/page.tsx index 5a298de..ff9f8ea 100644 --- a/src/app/photographer/page.tsx +++ b/src/app/photographer/page.tsx @@ -6,10 +6,12 @@ import Link from 'next/link'; import { useSearchParams } from 'next/navigation'; import Loading from '@/components/Loading'; import { photoData, photographerData, snapTypeChoice } from '@/data/database'; +import Instagram from '@/data/instagram.svg'; import { Photographer } from '@/types'; const RecommendedPhotographers = () => { const [isLoading, setIsLoading] = useState(true); + const [moodData, setMoodData] = useState([]); const [data, setData] = useState([]); const searchParams = useSearchParams(); @@ -24,6 +26,7 @@ const RecommendedPhotographers = () => { ?.split(',') .map((id: string) => photoData.find((item) => item.id === +id)?.mood) .sort(); + setMoodData(moods); if (!types || !moods) return; const filteredPhotographerByType = photographerData.filter((item) => @@ -36,8 +39,8 @@ const RecommendedPhotographers = () => { const photographerMoodCounts = filteredPhotographerByType.map( (photographer) => { - // 모든 사진작가들에 대해, const moodCounts = new Map(); + // 모든 사진작가들에 대해, for (const imageId of photographer.works) { //순회하는 사진작가 작품 이미지의 무드를 const mood = photoMoodMap.get(imageId); @@ -58,9 +61,10 @@ const RecommendedPhotographers = () => { ) .map((item) => item.photographer), ); + console.log('moodSortedPhotographers:', moodSortedPhotographers); const selectedPhotographers = new Set(); - const moodIndices = new Array(moods.length).fill(0); + const moodIndices = [0, 0, 0]; while (selectedPhotographers.size < 3) { for (let i = 0; i < moods.length; i++) { @@ -71,6 +75,7 @@ const RecommendedPhotographers = () => { if (selectedPhotographers.size === 3) break; } } + if ( moodIndices.every( (index, i) => index === moodSortedPhotographers[i].length, @@ -98,16 +103,16 @@ const RecommendedPhotographers = () => { return (
-

칙스냅에서 추천드리는 작가예요!

+

칙스냅에서 추천드리는 작가예요!

-

+

아래 작가분들은 여러분의 선택을 기반으로 칙스냅에서 추천드리는 작가님이에요. 자세히 보기를 통해 작가님의 정보를 확인하고 그리던 사진을 촬영해요

- {data.map((photographer: Photographer) => ( + {data.map((photographer: Photographer, index: number) => (
{ target={'_blank'} href={`https://www.instagram.com/${photographer.instagram_id}`} > -
-
-
- {photographer.name} -
- -
- - {photographer.name} - - - - {`@${photographer.instagram_id}`} - -
+
+
+ {photographer.name} + + + {photographer.name} + + + + {`@${photographer.instagram_id}`} + + + Instagram
-
+
{photographer.price}
+ {photographer.types.map((typeId, index) => (
{ ))}
+
{photographerData .find((item) => item.id === photographer.id) - ?.works.slice(0, 3) + ?.works.sort( + (a, b) => + Math.abs( + photoData.find((item) => item.id === a)!.mood - + moodData[index], + ) - + Math.abs( + photoData.find((item) => item.id === b)!.mood - + moodData[index], + ), + ) + .slice(0, 3) .map((imageId, index) => (
{ photoData.find((item) => item.id === imageId)?.url! } alt="example image" - layout="fill" - className="rounded-[0.25rem] object-cover" + fill + quality={100} + className="rounded-[0.25rem] object-cover w-auto h-auto" />
))}