Skip to content

Commit

Permalink
📬 API(#118): hp 쿼리 ,api 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
rhehfl committed Jan 23, 2025
1 parent d2e09df commit 9f4bcaf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/common/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import HeaderItem from '@common/ui/HeaderItem';
import Login from '@features/auth/ui/Login';
import ProfileImage from '@features/user/ui/ProfileImage';
import { authQuery } from '@features/auth/queries';
import { userHpQuery } from '@/features/user/queries';

export default function Header() {
const { user, clearUser } = useUserStore();
const { mutate: logout } = authQuery.logout();
const { data: userHp } = userHpQuery.getHp();

const { isShow, openModal, closeModal, Modal } = useModal();
const navigate = useNavigate();
Expand Down Expand Up @@ -55,7 +57,7 @@ export default function Header() {
/>
<HeaderItem
icon={getImageUrl('과일바구니.svg')}
point={5}
point={userHp.hp}
color={'#FE0F0F'}
/>
</>
Expand Down
4 changes: 2 additions & 2 deletions src/features/quiz/ui/Result.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isMobile } from '@modern-kit/utils';
import { AnswerDiv, NextPageButton, ScoreSection } from './styles';
import { progressQuery } from '@features/user/queries';
import { userProgressQuery } from '@features/user/queries';
import { useClientQuizStore } from '@store/useClientQuizStore';
import useUserStore from '@store/useUserStore';
import type { PartStatus } from '@features/learn/types';
Expand All @@ -25,7 +25,7 @@ export default function Result({
}: ResultProps) {
const { nextPage, resetUserResponseAnswer } = useClientQuizStore();
const { user } = useUserStore();
const { mutate: progressUpdate } = progressQuery.put();
const { mutate: progressUpdate } = userProgressQuery.updatePartProgress();

const handleOnClick = () => {
resetUserResponseAnswer();
Expand Down
4 changes: 4 additions & 0 deletions src/features/user/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ const usersApis = {
status: partStatus,
});
},
getHp: async () => {
const response = await api.get('users/user-hp');
return response.data;
},
};

export default usersApis;
14 changes: 12 additions & 2 deletions src/features/user/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,20 @@ const userKeys = {
...userKeys.quizzes(userId),
partId,
],
hp: () => [...userKeys.all, 'hp'] as const,
};

export const progressQuery = {
put: () => {
export const userHpQuery = {
getHp: () => {
return useSuspenseQuery({
queryKey: userKeys.hp(),
queryFn: usersApis.getHp,
});
},
};

export const userProgressQuery = {
updatePartProgress: () => {
return useMutation({ mutationFn: usersApis.putQuizzesProgress });
},
};
Expand Down

0 comments on commit 9f4bcaf

Please sign in to comment.