Skip to content

Commit

Permalink
refactor: select-mood 페이지를 위한 데이터 재구성 (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoSelf1 committed Aug 24, 2024
1 parent 9625a53 commit cc8fa4b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
8 changes: 5 additions & 3 deletions src/app/photographer/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,18 @@ const RecommendedPhotographers = () => {
)
break;
}
console.log(Array.from(selectedPhotographers));
setData(Array.from(selectedPhotographers));
};

useEffect(() => {
console.log('hello', data);
if (data.length === 0) {
processRecommendation();
const timer = setTimeout(() => {
setIsLoading(false);
}, 1000);

return () => clearTimeout(timer);
}
setIsLoading(false);
}, []);

if (isLoading) {
Expand Down
13 changes: 5 additions & 8 deletions src/app/select-mood/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import { useState } from 'react';
import Link from 'next/link';
import { useSearchParams } from 'next/navigation';
import MoodImageGroup from '@/components/MoodImageGroup';
import {
images_couple,
images_personal,
images_wedding,
} from '@/data/database';
import { arrangedPhotos } from '@/data/database';

const SelectMood = () => {
const searchParams = useSearchParams();
Expand All @@ -17,6 +13,7 @@ const SelectMood = () => {
const [selectedMoods, setSelectedMoods] = useState<number[]>([]);

const toggleMood = (id: number) => {
console.log(id);
setSelectedMoods((prev) =>
prev.includes(id)
? prev.filter((moodId) => moodId !== id)
Expand Down Expand Up @@ -46,17 +43,17 @@ const SelectMood = () => {
<div className="flex-grow px-4 mt-28 mb-20">
<div className="flex flex-row space-x-1 pb-4">
<MoodImageGroup
images={images_personal}
images={arrangedPhotos[0]}
selectedMoods={selectedMoods}
toggleMood={toggleMood}
/>
<MoodImageGroup
images={images_couple}
images={arrangedPhotos[1]}
selectedMoods={selectedMoods}
toggleMood={toggleMood}
/>
<MoodImageGroup
images={images_wedding}
images={arrangedPhotos[2]}
selectedMoods={selectedMoods}
toggleMood={toggleMood}
/>
Expand Down
11 changes: 8 additions & 3 deletions src/data/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,12 @@ export const photoData: SnapImage[] = [
url: 'https://chik.s3.ap-northeast-2.amazonaws.com/photo/usee_pic9%2BB6.png',
},
];
// mood를 기준으로 데이터 정렬
const sortedData = photoData.sort((a, b) => a.mood - b.mood);

export const images_personal = photoData.filter((item) => item.snap_type === 0);
export const images_couple = photoData.filter((item) => item.snap_type === 1);
export const images_wedding = photoData.filter((item) => item.snap_type === 2);
// 3개의 배열로 분할
export const arrangedPhotos: SnapImage[][] = [[], [], []];

sortedData.forEach((item: SnapImage, index) => {
arrangedPhotos[index % 3].push(item);
});

0 comments on commit cc8fa4b

Please sign in to comment.