-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: 피드페이지 리팩토링 #193
Refactor: 피드페이지 리팩토링 #193
Changes from all commits
5da2589
9b70300
60ac2da
9549726
32ea591
768ad38
716ffd6
363e136
4487cd3
7f9fe09
13154a7
a0ae6d0
6e16b38
d7fac51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
import { useEffect, useState } from 'react'; | ||
import { FieldErrors, FormProvider, useForm } from 'react-hook-form'; | ||
import { useMutation, useQuery } from '@tanstack/react-query'; | ||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; | ||
import { useRouter, useParams } from 'next/navigation'; | ||
|
||
import CreateItem from '@/app/list/create/_components/CreateItem'; | ||
|
@@ -20,6 +20,7 @@ export type FormErrors = FieldErrors<ListEditType>; | |
|
||
export default function EditPage() { | ||
const router = useRouter(); | ||
const queryClient = useQueryClient(); | ||
const param = useParams<{ listId: string }>(); | ||
const { user } = useUser(); | ||
|
||
|
@@ -144,6 +145,9 @@ export default function EditPage() { | |
} = useMutation({ | ||
mutationFn: updateList, | ||
onSettled: () => { | ||
queryClient.invalidateQueries({ | ||
queryKey: [QUERY_KEYS.getAllList, user.id + ''], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 수정에서는 생성페이지에서 사용했던 키인 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
서영님 맞습니다~!, 쿼리키를 다 넣을 수도 있지만 수정페이지에서는 타입도 변할 가능성이 있기 때문에 (예를 들어, 마이리스트에서 수정할때 콜라보를 넣어서 콜라보를 넣는 경우 또는 그 반대의 경우 등) 정확한 쿼리키를 넣으면 그 반대의 경우도 넣어줘야 하므로 여러가지 조건을 고려해야 했습니다, 그래서 수정할때는 유저아이디에 해당하는 리스트를 다시 무효화하는 방법이 더 맞다고 판단하여 적용했습니다!✍️ |
||
}); | ||
router.replace(`/list/${param?.listId}`); | ||
}, | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,22 @@ | ||
'use client'; | ||
|
||
/** | ||
TODO | ||
- [ ] 클릭했을때 로직 (상위요소에 핸들러 고민) (리팩토링) | ||
*/ | ||
|
||
import { useQuery } from '@tanstack/react-query'; | ||
import { Skeleton } from '@mui/material'; | ||
|
||
import * as styles from './Categories.css'; | ||
|
||
import getCategories from '@/app/_api/category/getCategories'; | ||
import { CategoryType } from '@/lib/types/categoriesType'; | ||
import { QUERY_KEYS } from '@/lib/constants/queryKeys'; | ||
|
||
import CategoriesSkeleton from './CategoriesSkeleton'; | ||
|
||
interface CategoriesProps { | ||
handleFetchListsOnCategory: (category: string) => void; | ||
selectedCategory: string; | ||
} | ||
|
||
export default function Categories({ handleFetchListsOnCategory, selectedCategory }: CategoriesProps) { | ||
const { data, isFetching } = useQuery<CategoryType[]>({ | ||
const { data, isLoading } = useQuery<CategoryType[]>({ | ||
queryKey: [QUERY_KEYS.getCategories], | ||
queryFn: getCategories, | ||
staleTime: Infinity, // 카테고리는 자주 변하는 데이터가 아니므로 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍👍👍👍👍 |
||
}); | ||
|
||
const handleChangeCategory = (category: string) => () => { | ||
|
@@ -32,8 +25,12 @@ export default function Categories({ handleFetchListsOnCategory, selectedCategor | |
|
||
return ( | ||
<div className={styles.container}> | ||
{isFetching ? ( | ||
<CategoriesSkeleton /> | ||
{isLoading ? ( | ||
<div className={styles.skeletonContainer}> | ||
{new Array(4).fill(0).map((_, index) => ( | ||
<Skeleton key={index} variant="rounded" width={100} height={35} animation="wave" /> | ||
))} | ||
</div> | ||
) : ( | ||
data?.map((category) => ( | ||
<button | ||
|
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
소현님, 공백 추가하신 이유가 궁금합니다!! 뒤에 공백을 추가하지 않으면 인식되지 않는 걸까요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
서영님, 맞습니다🥰 getAllList의 쿼리키 중 userId가 string이기 때문에 동일한 키로 인식하기 위해 number타입의 user.id를 문자열로 변환하기 위한 방법을 넣은 것입니다! 문자열로 변환하기 위한 여러 방법이 있겠지만 저는 위처럼 작성하는 편입니다,
혹시 추가로 궁금하신 점 있으시면 말씀 부탁드립니다!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ParkSohyunee 소현님! 늦은 확인 죄송합니다..!! 🥹 쿼리 무효화 해주신 부분 잘 확인했습니다! 정말 감사합니다!! 🙇♀️