Skip to content

Commit

Permalink
hotfix: useQueryClient로 수정하고 invalidateQuries 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
dooohun committed Dec 4, 2024
1 parent 3a6c3ca commit 32c951f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
12 changes: 5 additions & 7 deletions packages/client/src/pages/quiz-list/index.lazy.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import { CustomButton } from '@/shared/ui/buttons';
import Modal from '@/shared/ui/modal';
import { useEffect, useState } from 'react';
import { useState } from 'react';
import QuizTitleModal from './ui/QuizTitleModal';
import { useGetClasses } from '@/shared/hooks/classes';
import ClassItem from './ui/ClassItem';
import EmptyQuizList from './ui/EmptyClassList';

export default function QuizListLazyPage() {
const { data: classList, refetch } = useGetClasses();
const { data: classList } = useGetClasses();
const [openModal, setOpenModal] = useState(false);

useEffect(() => {
refetch();
}, []);
const sortedClassListById = classList.data.sort((a, b) => a.id - b.id);

return (
<div className="w-full min-h-[calc(100vh-80px)] px-8 flex flex-col gap-6 mt-6 mx-auto">
{classList.data.map((item, index) => {
{sortedClassListById.map((item, index) => {
return <ClassItem key={item.id} quizList={item} index={index} />;
})}
{classList.data.length === 0 && <EmptyQuizList />}
{sortedClassListById.length === 0 && <EmptyQuizList />}
<div className="self-end ">
<CustomButton
type="outline"
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/shared/hooks/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { createClass, deleteClass, getClasses } from '@/shared/api/classes';
import { toastController } from '@/features/toast/model/toastController';

export const useGetClasses = () => {
const { data, refetch } = useSuspenseQuery({
const { data } = useSuspenseQuery({
queryKey: ['classes'],
queryFn: () => getClasses(),
});
return { data, refetch };
return { data };
};

export const useCreateClass = () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/client/src/shared/hooks/quizzes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMutation } from '@tanstack/react-query';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { createQuiz } from '../api/quizzes';
import { QuizData } from '@/pages/quiz-create';
import { toastController } from '@/features/toast/model/toastController';
Expand All @@ -16,10 +16,14 @@ interface CreateQuizParams {
export const useCreateQuiz = () => {
const toast = toastController();
const navigate = useNavigate();
const queryClient = useQueryClient();
return useMutation({
mutationKey: ['quiz'],
mutationFn: ({ quizData, classId }: CreateQuizParams) => createQuiz(quizData, classId),
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: ['classes'],
});
navigate('/quiz-list');
toast.success('퀴즈가 생성되었습니다.');
},
Expand Down

0 comments on commit 32c951f

Please sign in to comment.