Skip to content

Commit

Permalink
[FE] feat: 랭킹 상대 시간 추가 (#826)
Browse files Browse the repository at this point in the history
* feat: 꿀조합 랭킹 상대 날짜 추가

* feat: 리뷰 랭킹 상대 시간 추가
  • Loading branch information
Leejin-Yang authored Oct 19, 2023
1 parent 9b00964 commit a5b52e7
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import styled from 'styled-components';
import RecipePreviewImage from '@/assets/plate.svg';
import { Skeleton, SvgIcon } from '@/components/Common';
import type { RecipeRanking } from '@/types/ranking';
import { getRelativeDate } from '@/utils/date';

interface RecipeRankingItemProps {
rank: number;
Expand All @@ -18,6 +19,7 @@ const RecipeRankingItem = ({ rank, recipe }: RecipeRankingItemProps) => {
title,
author: { nickname, profileImage },
favoriteCount,
createdAt,
} = recipe;
const [isImageLoading, setIsImageLoading] = useState(true);

Expand Down Expand Up @@ -49,6 +51,10 @@ const RecipeRankingItem = ({ rank, recipe }: RecipeRankingItemProps) => {
<Text as="span" size="sm" weight="bold">
{favoriteCount}
</Text>
<Spacing direction="horizontal" size={4} />
<Text size="sm" color={theme.textColors.info}>
{getRelativeDate(createdAt)}
</Text>
</FavoriteWrapper>
</TitleFavoriteWrapper>
</RankingRecipeWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const meta: Meta<typeof ReviewRankingItem> = {
rating: 4.0,
favoriteCount: 1256,
categoryType: 'food',
createdAt: '2021-08-01T00:00:00.000Z',
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import styled from 'styled-components';

import { SvgIcon } from '@/components/Common';
import type { ReviewRanking } from '@/types/ranking';
import { getRelativeDate } from '@/utils/date';

interface ReviewRankingItemProps {
reviewRanking: ReviewRanking;
Expand All @@ -12,7 +13,7 @@ interface ReviewRankingItemProps {
const ReviewRankingItem = ({ reviewRanking }: ReviewRankingItemProps) => {
const theme = useTheme();

const { productName, content, rating, favoriteCount } = reviewRanking;
const { productName, content, rating, favoriteCount, createdAt } = reviewRanking;

return (
<ReviewRankingItemContainer>
Expand All @@ -36,6 +37,9 @@ const ReviewRankingItem = ({ reviewRanking }: ReviewRankingItemProps) => {
{rating.toFixed(1)}
</Text>
</RatingIconWrapper>
<ReviewDate size="sm" color={theme.textColors.info}>
{getRelativeDate(createdAt)}
</ReviewDate>
</FavoriteStarWrapper>
</ReviewRankingItemContainer>
);
Expand Down Expand Up @@ -80,3 +84,7 @@ const RatingIconWrapper = styled.div`
padding-bottom: 2px;
}
`;

const ReviewDate = styled(Text)`
margin-left: auto;
`;
9 changes: 6 additions & 3 deletions frontend/src/mocks/data/recipeRankingList.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"profileImage": "https://github.com/woowacourse-teams/2023-fun-eat/assets/78616893/991f7b69-53bf-4d03-96e1-988c34d010ed",
"nickname": "funeat"
},
"favoriteCount": 153
"favoriteCount": 153,
"createdAt": "2023-08-09T10:10:10"
},
{
"id": 2,
Expand All @@ -18,7 +19,8 @@
"profileImage": "https://github.com/woowacourse-teams/2023-fun-eat/assets/78616893/991f7b69-53bf-4d03-96e1-988c34d010ed",
"nickname": "funeat"
},
"favoriteCount": 153
"favoriteCount": 153,
"createdAt": "2023-08-09T10:10:10"
},
{
"id": 3,
Expand All @@ -28,7 +30,8 @@
"profileImage": "https://github.com/woowacourse-teams/2023-fun-eat/assets/78616893/991f7b69-53bf-4d03-96e1-988c34d010ed",
"nickname": "funeat"
},
"favoriteCount": 153
"favoriteCount": 153,
"createdAt": "2023-08-09T10:10:10"
}
]
}
6 changes: 4 additions & 2 deletions frontend/src/mocks/data/reviewRankingList.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"content": "할머니가 먹을 거 같은 맛입니다. 1960년 전쟁 때 맛 보고 싶었는데 그때는 너무 가난해서 먹을 수 없었는데요 이것보다 긴 리뷰도 잘려 보인답니다",
"rating": 4.0,
"favoriteCount": 1256,
"categoryType": "food"
"categoryType": "food",
"createdAt": "2023-08-09T10:10:10"
},
{
"reviewId": 1,
Expand All @@ -16,7 +17,8 @@
"content": "하얀 짜파게티라니 말이 안된다고 생각했었죠. 실제로 맛을 보니까 까만 짜파게티랑 맛이 뭔가 다를게 없네요.",
"rating": 4.4,
"favoriteCount": 870,
"categoryType": "food"
"categoryType": "food",
"createdAt": "2023-08-09T10:10:10"
}
]
}
2 changes: 2 additions & 0 deletions frontend/src/types/ranking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface ReviewRanking {
rating: number;
favoriteCount: number;
categoryType: CategoryVariant;
createdAt: string;
}

export interface RecipeRanking {
Expand All @@ -20,4 +21,5 @@ export interface RecipeRanking {
title: string;
author: Member;
favoriteCount: number;
createdAt: string;
}

0 comments on commit a5b52e7

Please sign in to comment.