Skip to content

Commit ff02efa

Browse files
committed
[chore] 충돌사항 수정
1 parent bc6d1a9 commit ff02efa

File tree

4 files changed

+21
-28
lines changed

4 files changed

+21
-28
lines changed

src/domains/recipe/api/fetchRecipe.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { useInfiniteQuery, useQuery, useQueryClient } from '@tanstack/react-quer
44
import { Cocktail, Sort } from '../types/types';
55
import { useEffect, useRef } from 'react';
66

7-
87
interface CocktailResponse {
98
data: Cocktail[];
109
}
@@ -43,9 +42,9 @@ const fetchKeep = async (): Promise<Set<number>> => {
4342
};
4443

4544
const fetchRecipe = async (
46-
pageParam:PageParam|null,
45+
pageParam: PageParam | null,
4746
size: number,
48-
sortBy?: Sort,
47+
sortBy?: Sort
4948
): Promise<Cocktail[]> => {
5049
const url = new URL(`${getApi}/cocktails`);
5150
url.searchParams.set('size', String(size));
@@ -137,7 +136,6 @@ export const useCocktailsInfiniteQuery = (size: number = 20, sortBy?: Sort) => {
137136
const lastItem = lastPage[lastPage.length - 1];
138137
if (!lastItem) return undefined;
139138

140-
141139
let lastValue: number | string;
142140

143141
switch (sortBy) {
@@ -207,17 +205,17 @@ export const useCocktails = (
207205
}
208206

209207
const allCocktails = infiniteQuery.data?.pages.flatMap((page) => page) ?? [];
210-
const uniqueCocktails = allCocktails.filter(
211-
(cocktail, index, self) => index === self.findIndex((c) => c.cocktailId === cocktail.cocktailId)
212-
);
213-
214-
const hasDuplicates = allCocktails.length !== uniqueCocktails.length;
208+
const uniqueCocktails = allCocktails.filter(
209+
(cocktail, index, self) => index === self.findIndex((c) => c.cocktailId === cocktail.cocktailId)
210+
);
211+
212+
const hasDuplicates = allCocktails.length !== uniqueCocktails.length;
215213
return {
216214
data: uniqueCocktails,
217215
noResults: false,
218216
isSearchMode: false,
219217
fetchNextPage: infiniteQuery.fetchNextPage,
220-
hasNextPage: hasDuplicates ? false: infiniteQuery.hasNextPage,
218+
hasNextPage: hasDuplicates ? false : infiniteQuery.hasNextPage,
221219
isFetchingNextPage: infiniteQuery.isFetchingNextPage,
222220
};
223221
};

src/domains/recipe/api/useRecipeComment.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { useToast } from '@/shared/hook/useToast';
55
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
66

77
interface Comment {
8-
9-
userNickName: string
8+
userNickName: string;
109
}
1110

1211
export const postRecipeComment = async (cocktailId: number, content: string) => {
@@ -23,8 +22,7 @@ export const postRecipeComment = async (cocktailId: number, content: string) =>
2322
body: JSON.stringify(body),
2423
});
2524

26-
27-
if (res.status === 401) throw new Error('unauth')
25+
if (res.status === 401) throw new Error('unauth');
2826

2927
const text = await res.text();
3028
const data = JSON.parse(text);
@@ -80,15 +78,15 @@ export function useRecipeComment({ cocktailId }: { cocktailId: number }) {
8078
queryFn: () => getRecipeComment(cocktailId),
8179
staleTime: 30_000,
8280
});
83-
84-
const hasComment = comments.some((c:Comment) => c.userNickName === user?.nickname);
81+
82+
const hasComment = comments.some((c: Comment) => c.userNickName === user?.nickname);
8583
const createMut = useMutation({
8684
mutationFn: (content: string) => {
8785
if (!user?.id) {
8886
toastInfo('로그인 후 이용 가능합니다.');
89-
return Promise.resolve(null)
87+
return Promise.resolve(null);
9088
} else if (hasComment) {
91-
toastInfo('댓글은 한 개만 작성 가능합니다.')
89+
toastInfo('댓글은 한 개만 작성 가능합니다.');
9290
}
9391
return postRecipeComment(cocktailId, content);
9492
},

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@ import { Sort } from '../../types/types';
1313

1414
function Cocktails() {
1515
const searchParams = useSearchParams();
16-
const sortByParam = searchParams.get('sortBy') || 'recent'
16+
const sortByParam = searchParams.get('sortBy') || 'recent';
1717
const [keyword, setKeyword] = useState('');
1818
const [input, setInput] = useState('');
1919

20-
const [sortBy,setSortBy] = useState<Sort>(sortByParam as Sort)
20+
const [sortBy, setSortBy] = useState<Sort>(sortByParam as Sort);
2121
const [alcoholStrengths, setAlcoholStrengths] = useState<string[]>([]);
2222
const [alcoholBaseTypes, setAlcoholBaseTypes] = useState<string[]>([]);
2323
const [cocktailTypes, setCocktailTypes] = useState<string[]>([]);
2424

25-
26-
2725
const { data, fetchNextPage, hasNextPage, noResults, isSearchMode } = useCocktails(
2826
{
2927
keyword,
@@ -45,17 +43,16 @@ function Cocktails() {
4543
}
4644
}, [inView, hasNextPage, fetchNextPage]);
4745

48-
useEffect(() => {
49-
setSortBy(sortByParam as Sort);
50-
}, [sortByParam]);
46+
useEffect(() => {
47+
setSortBy(sortByParam as Sort);
48+
}, [sortByParam]);
5149

5250
const debounceKeyword = useMemo(() => debounce((v: string) => setKeyword(v), 300), []);
5351
const handleSearch = (v: string) => {
5452
setInput(v);
5553
debounceKeyword(v);
5654
};
5755

58-
5956
return (
6057
<section>
6158
<div className="flex flex-col-reverse items-start gap-6 md:flex-row md:justify-between md:items-center ">
@@ -67,7 +64,7 @@ function Cocktails() {
6764
<CocktailSearchBar keyword={input} onChange={handleSearch} />
6865
</div>
6966

70-
<CocktailFilter cocktailsEA={data.length} />
67+
<CocktailFilter cocktailsEA={data.length} />
7168

7269
<section className="mt-5">
7370
{noResults ? <div>검색 결과가 없습니다.</div> : <CocktailList cocktails={data} />}

src/domains/recipe/types/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface Cocktail {
66
cocktailNameKo: string;
77
isKeep: boolean;
88
keepCount?: number;
9-
commentCount?: number;
9+
commentCount?: number;
1010
}
1111

1212
export interface RecommendCocktail {

0 commit comments

Comments
 (0)