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

[Feature] - 메인페이지 skeleton 작업 #221

Merged
merged 6 commits into from
Aug 7, 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
10 changes: 9 additions & 1 deletion frontend/src/components/pages/main/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import TravelogueCard from "@components/pages/main/TravelogueCard/TravelogueCard
import useIntersectionObserver from "@hooks/useIntersectionObserver";

import * as S from "./MainPage.styled";
import TravelogueCardSkeleton from "./TravelogueCard/skeleton/TravelogueCardSkeleton";

const MainPage = () => {
const SKELETON_COUNT = 5;
const { travelogues, status, fetchNextPage } = useInfiniteTravelogues();
const { lastElementRef } = useIntersectionObserver(fetchNextPage);

Expand All @@ -20,7 +22,13 @@ const MainPage = () => {
<h1>지금 뜨고 있는 여행기</h1>
<p>다른 이들의 여행을 한 번 구경해보세요.</p>
</S.MainPageHeaderContainer>
{status === "pending" && <>로딩 ...</>}
{status === "pending" && (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리버 덕분에 로딩 상황에서 스켈레톤 ui를 잘볼 수 있겠네요 👍🥰

<S.MainPageTraveloguesList>
{Array.from({ length: SKELETON_COUNT }, (_, index) => (
<TravelogueCardSkeleton key={index} />
))}
</S.MainPageTraveloguesList>
)}
<S.MainPageTraveloguesList>
{travelogues.map(({ userAvatar, id, title, thumbnail, likes }) => (
<TravelogueCard
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { Meta, StoryObj } from "@storybook/react";

import TravelogueCardSkeleton from "./TravelogueCardSkeleton";

const meta = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

스토리북 까지 👍👍

title: "skeleton/TravelogueCardSkeleton",
component: TravelogueCardSkeleton,
decorators: [
(Story, context) => {
return (
<div style={{ width: "48rem" }}>
<Story args={{ ...context.args }} />
</div>
);
},
],
} satisfies Meta<typeof TravelogueCardSkeleton>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Default: Story = {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { keyframes } from "@emotion/react";
import styled from "@emotion/styled";

const skeletonAnimation = keyframes`
0% {
background-position: -100% 0;
}
100% {
background-position: 100% 0;
}
`;

const SkeletonBase = styled.div`
background-color: ${(props) => props.theme.colors.skeleton.base};
background-image: linear-gradient(
90deg,
${(props) => props.theme.colors.skeleton.base} 6rem,
${(props) => props.theme.colors.skeleton.highlight} 12rem,
${(props) => props.theme.colors.skeleton.base} 18rem
);
background-size: 200% 200%;
background-repeat: no-repeat;

animation: ${skeletonAnimation} 1.2s ease-in-out infinite;
`;
Comment on lines +14 to +25
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 부분이 스켈레톤의 핵심으로 보여지는데 이해하는데 좀 걸렸네요! 스켈레톤은 처음이였는데 학습해볼 수 있었습니다


export const Layout = styled.div`
display: flex;
flex-direction: column;
gap: ${(props) => props.theme.spacing.m};
`;

export const ThumbnailCard = styled(SkeletonBase)`
width: 100%;
height: 25rem;
border-radius: 10px;
`;

export const BottomBarContainer = styled.div`
display: flex;
justify-content: space-between;
width: 100%;
padding: 0 ${(props) => props.theme.spacing.m};
`;

export const TitleContainer = styled.div`
display: flex;
gap: ${(props) => props.theme.spacing.s};
`;

export const ProfileSkeleton = styled(SkeletonBase)`
width: 2.2rem;
height: 2.2rem;
border-radius: 50%;
`;

export const TitleSkeleton = styled(SkeletonBase)`
width: 13rem;
height: 2.2rem;
border-radius: 10px;
`;

export const LikesSkeleton = styled(SkeletonBase)`
width: 5rem;
height: 2.2rem;
border-radius: 10px;
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as S from "./TravelogueCardSkeleton.styled";

const TravelogueCardSkeleton = () => {
return (
<S.Layout>
<S.ThumbnailCard />

<S.BottomBarContainer>
<S.TitleContainer>
<S.ProfileSkeleton />
<S.TitleSkeleton />
</S.TitleContainer>

<S.LikesSkeleton />
</S.BottomBarContainer>
</S.Layout>
);
};

export default TravelogueCardSkeleton;
4 changes: 4 additions & 0 deletions frontend/src/styles/tokens/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ export const SEMANTIC_COLORS = {
danger: "#ea0000",
kakao: "#f9e007",
dimmed: "#0000004d",
skeleton: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

token 추가 감사합니다 :)

base: PRIMITIVE_COLORS.gray[200],
highlight: PRIMITIVE_COLORS.gray[100],
},
} as const;
Loading