Skip to content

Commit e320cc8

Browse files
committed
[feat]아코디언 박스
1 parent f974d85 commit e320cc8

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

src/domains/recipe/api/RecipeFetch.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getApi } from '@/app/api/config/appConfig';
44
import { Cocktail } from '../types/types';
55
import { Dispatch, SetStateAction, useCallback } from 'react';
66

7+
78
interface Props {
89
setData: React.Dispatch<React.SetStateAction<Cocktail[]>>;
910
lastId: number | null;
@@ -12,7 +13,7 @@ interface Props {
1213
setHasNextPage: Dispatch<SetStateAction<boolean>>;
1314
SIZE?: number;
1415
}
15-
16+
// api/cocktais fetch용
1617
export const RecipeFetch = ({
1718
setData,
1819
lastId,
@@ -21,28 +22,33 @@ export const RecipeFetch = ({
2122
setHasNextPage,
2223
SIZE = 20,
2324
}: Props) => {
25+
26+
2427
const fetchData = useCallback(async () => {
28+
29+
// 쿼리파라미터에 값 넣기
2530
if (!hasNextPage) return;
2631
const url = new URL(`${getApi}/cocktails`);
2732
url.searchParams.set('size', String(SIZE));
2833
if (typeof lastId === 'number') {
2934
url.searchParams.set('lastId', String(lastId));
3035
}
31-
32-
const res = await fetch(url.toString());
36+
37+
const res = await fetch(url.toString(),{method:'GET'});
3338
if (!res.ok) throw new Error('레시피 데이터 요청실패');
3439

3540
const json = await res.json();
3641
const list: Cocktail[] = json.data ?? [];
3742

43+
// 중복 아이디 에러있어서 Map으로 Merge
3844
setData((prev) =>
3945
Array.from(new Map([...prev, ...list].map((i) => [i.cocktailId, i])).values())
4046
);
47+
4148

4249
if (list.length > 0) {
4350
setLastId(list[list.length - 1].cocktailId);
4451
}
45-
4652
setHasNextPage(list.length === SIZE);
4753
}, [hasNextPage, lastId, setData, setLastId, setHasNextPage, SIZE]);
4854
return { fetchData };

src/domains/recipe/components/main/Cocktails.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import CocktailSearchBar from './CocktailSearchBar';
1111
import useSearchControl from '../../hook/useSearchControl';
1212
import CocktailSearch from '../../api/CocktailSearch';
1313

14+
1415
function Cocktails() {
1516
const {
1617
data,

src/domains/recipe/hook/ozToMl.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
// 유니코드 분수 매핑 (소수점 대신 정수 ml로 변환)
1+
// 분수 매핑
22
const FRAC_MAP: Record<string, number> = {
3-
'¼': 8, // 0.25 * 30
4-
'½': 15, // 0.5 * 30
5-
'¾': 23, // 0.75 * 30
6-
'⅓': 10, // 1/3 * 30 ≈ 10
7-
'⅔': 20, // 2/3 * 30 ≈ 20
8-
'⅕': 6, // 1/5 * 30
9-
'⅖': 12, // 2/5 * 30
10-
'⅗': 18, // 3/5 * 30
11-
'⅘': 24, // 4/5 * 30
12-
'⅙': 5, // 1/6 * 30
13-
'⅚': 25, // 5/6 * 30
14-
'⅛': 4, // 1/8 * 30
15-
'⅜': 11, // 3/8 * 30
16-
'⅝': 19, // 5/8 * 30
17-
'⅞': 26, // 7/8 * 30
3+
'¼': 8,
4+
'½': 15,
5+
'¾': 23,
6+
'⅓': 10,
7+
'⅔': 20,
8+
'⅕': 6,
9+
'⅖': 12,
10+
'⅗': 18,
11+
'⅘': 24,
12+
'⅙': 5,
13+
'⅚': 25,
14+
'⅛': 4,
15+
'⅜': 11,
16+
'⅝': 19,
17+
'⅞': 26,
1818
};
1919

20+
// 정규식 분리 용 class
2021
const FRAC_CLASS = Object.keys(FRAC_MAP).join('');
2122

2223
export function ozToMl(input: string): number | '' {

src/domains/shared/hook/useMemoScroll.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// hooks/useScrollRestoration.ts (또는 useMemoScroll.ts)
21
import { useEffect, useRef, useState, useCallback } from 'react';
32

43
interface UseScrollRestorationProps {
@@ -14,18 +13,20 @@ interface ScrollState<T> {
1413
timestamp: number;
1514
}
1615

16+
// 뒤로가기시 스크롤위치 기억 함수
17+
1718
export function useMemoScroll<T>({
1819
storageKey,
1920
eventName = 'resetScroll',
2021
}: UseScrollRestorationProps) {
22+
2123
// 뒤로가기를 통해 목록 복원을 저장해주는 플래그
2224
const NAVIGATION_FLAG_KEY = `${storageKey}_nav_flag`;
2325

2426
// 실제 렌더링 되는 데이터
2527
const [data, setData] = useState<T[]>([]);
2628
const [lastId, setLastId] = useState<number | null>(null);
2729
const [hasNextPage, setHasNextPage] = useState(true);
28-
// fetch필요 여부
2930
const [shouldFetch, setShouldFetch] = useState(false);
3031

3132
// 스크롤 복원중일 때 값이 바뀜

0 commit comments

Comments
 (0)