Skip to content
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

내 랭킹 조회 기능 구현 #189

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/apis/my-rank/my-rank.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { MyRankResponse } from './my-rank.response';
import { axiosClient } from '@/apis/AxiosClient';
import { useQuery } from '@tanstack/react-query';

const getMyRankPath = () => '/api/user/my-ranking';

const UserQueryKey = [getMyRankPath()];

const getMyRank = async (): Promise<MyRankResponse> => {
const response = await axiosClient.get(getMyRankPath());
return response.data;
};

export const useGetMyRank = () => {
return useQuery<MyRankResponse, Error>({
queryKey: UserQueryKey,
queryFn: getMyRank,
});
};
17 changes: 17 additions & 0 deletions src/apis/my-rank/my-rank.response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import ApiResponse from '../ApiResponse';

export type MyRankData = {
id: number;
nickname: string;
profileImageUrl: string;
email: string;
tierInfo: {
tier: string;
totalExp: number;
currentExp: number;
};
role: 'USER' | 'ADMIN';
rank: number;
};

export type MyRankResponse = ApiResponse<MyRankData>;
1 change: 0 additions & 1 deletion src/pages/rank/components/all/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const AllRank = () => {
}));
setUserRanks(allUserData);
setLoading(false);
// console.log('rank data: ', allUserData);
};

fetchUserRanking();
Expand Down
79 changes: 47 additions & 32 deletions src/pages/rank/components/my/index.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,64 @@
import { TextContainer } from '../../styles';
import * as S from './styles';
import { useGetMyRank } from '@/apis/my-rank/my-rank.api';
import Profile from '@/assets/main/ZZAN-Profile.png';
import { getTierDetails } from '@/constants/data/tierSchema';
import { useInfoStore } from '@/store/useInfoStore';
import * as Base from '@/styles/baseStyles';
import { Box, Image, Text } from '@chakra-ui/react';
import styled from '@emotion/styled';

const MyRank = () => {
const { userInfo } = useInfoStore();
const { data } = useGetMyRank();

const tierDetails = userInfo?.tierInfo
? getTierDetails(userInfo?.tierInfo.tier)
const tierDetails = data?.data.tierInfo
? getTierDetails(data?.data.tierInfo.tier)
: { color: 'var(--color-class-02)' };
return (
<>
<S.MyRankLayout>
<Base.Text
fontSize='var(--font-size-xl)'
fontWeight='700'
color='#457A82'
>
<MyRankLayout>
<Text fontSize='var(--font-size-xl)' fontWeight='700' color='#457A82'>
내 순위
</Base.Text>
<S.RankInfoContainer>
<S.RankPosition>
<Base.Text fontWeight='700'>1위</Base.Text>
</S.RankPosition>
<S.RankProfile>
<S.RankProfileImg width='4.5rem' src={Profile} />
</S.RankProfile>
</Text>
<RankInfoContainer>
<RankPosition>
<Text fontWeight='700'>{data?.data.rank}위</Text>
</RankPosition>
<Box display='flex'>
<Image width='4.5rem' src={Profile} />
</Box>
<TextContainer>
<Base.Text fontSize='var(--font-size-xl)' fontWeight='650'>
{userInfo?.nickname}
</Base.Text>
<Base.Text
color={tierDetails?.color}
fontWeight='700'
fontSize='1.2rem'
>
{userInfo?.tierInfo.tier}
</Base.Text>
<Text fontSize='var(--font-size-xl)' fontWeight='650'>
{data?.data.nickname}
</Text>
<Text color={tierDetails?.color} fontWeight='700' fontSize='1.2rem'>
{data?.data.tierInfo.tier}
</Text>
</TextContainer>
</S.RankInfoContainer>
</S.MyRankLayout>
</RankInfoContainer>
</MyRankLayout>
</>
);
};

export default MyRank;

export const MyRankLayout = styled.div`
display: flex;
flex-direction: column;
background-color: var(--color-green-06);
border-bottom: 1px solid #bdc5cd;
`;

export const RankInfoContainer = styled.div`
display: flex;
flex-direction: row;
align-items: center;

justify-content: space-between;
gap: 0.6rem;
padding: 1rem 0.5rem;
`;

export const RankPosition = styled.div`
width: 3rem;
text-align: center;
white-space: nowrap;
`;
5 changes: 2 additions & 3 deletions src/pages/rank/components/user/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const UserRank: React.FC<UserRankProps> = ({ user, index }) => {
<S.UserRankContainer>
<Box
display='flex'
// justifyContent='space-between'
alignItems='center'
textAlign='center'
bgColor='#fff'
Expand Down Expand Up @@ -52,14 +51,14 @@ const UserRank: React.FC<UserRankProps> = ({ user, index }) => {
gap='1rem'
>
<Text
maxWidth='150px'
maxWidth='170px'
fontWeight='700'
fontSize='0.8rem'
color={tierColor}
>
{tierInfo}
</Text>
<Text maxWidth='150px' fontSize='0.8rem' color={tierColor}>
<Text maxWidth='200px' fontSize='0.7rem' color={tierColor}>
{currentExp}
</Text>
</Box>
Expand Down