Skip to content

Commit

Permalink
FIX :: Board 로딩 시 Skeleton 표시
Browse files Browse the repository at this point in the history
  • Loading branch information
jsm8109jsm committed Jun 21, 2023
1 parent 756b935 commit 1a95b2a
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 20 deletions.
2 changes: 1 addition & 1 deletion components/Board/BoardItem/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from "styled-components";

export const BoardItem = styled.div`
border-radius: 15px;
width: 260px;
width: 16.25rem;
background-color: white;
box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.25);
cursor: pointer;
Expand Down
8 changes: 8 additions & 0 deletions components/Board/BoardItemSkeleton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from "react";
import * as S from "./style";

function BoardItemSkeleton() {
return <S.BoardItemSkeleton></S.BoardItemSkeleton>;
}

export default BoardItemSkeleton;
10 changes: 10 additions & 0 deletions components/Board/BoardItemSkeleton/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import styled from "styled-components";

export const BoardItemSkeleton = styled.div`
border-radius: 15px;
width: 16.25rem;
height: 24.7656rem;
background-color: white;
box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.25);
animation: ${({ theme }) => theme.animations.Skeleton} 1.5s ease-in-out infinite;
`;
46 changes: 39 additions & 7 deletions components/Board/BoardSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,38 @@ import {
getRecommendBoardQuery,
getTrendingBoardQuery,
} from "@/utils/apis/board";
import { useRecoilState } from "recoil";
import { isLoadingState } from "@/atoms/Etc/isLoading";
import BoardItemSkeleton from "../BoardItemSkeleton";

function BoardSection({ isYellow }: { isYellow?: true }) {
const [isLoading, setIsLoading] = useRecoilState(isLoadingState);
const getTrendingFunc = getTrendingBoardQuery();
const getRecommendFunc = getRecommendBoardQuery();
if (getRecommendFunc.isLoading || getTrendingFunc.isLoading) {
setIsLoading(true);
return (
<S.BoardSection isYellow={isYellow}>
<S.Title isYellow={isYellow}>
{isYellow ? (
<>
최근 떠오르는 레시피
<AiFillFire color="#FFFFFF" />
</>
) : (
<span>
이런 <S.Emphasis>레시피</S.Emphasis> 어떠세요?
</span>
)}
</S.Title>
<S.BoardWrap>
{[...Array(4)].map((item) => {
return <BoardItemSkeleton />;
})}
</S.BoardWrap>
</S.BoardSection>
);
}
if (getTrendingFunc.isSuccess && getRecommendFunc.isSuccess) {
return (
<S.BoardSection isYellow={isYellow}>
Expand All @@ -30,15 +58,19 @@ function BoardSection({ isYellow }: { isYellow?: true }) {
getRecommendFunc.data?.list.length ? (
isYellow ? (
<>
{getTrendingFunc.data?.list.map((item: BoardType) => {
return <BoardItem data={item} />;
})}
{getTrendingFunc.data?.list
.slice(0, 4)
.map((item: BoardType) => {
return <BoardItem data={item} />;
})}
</>
) : (
<>
{getRecommendFunc.data?.list.map((item: BoardType) => {
return <BoardItem data={item} />;
})}
{getRecommendFunc.data?.list
.slice(0, 4)
.map((item: BoardType) => {
return <BoardItem data={item} />;
})}
</>
)
) : (
Expand All @@ -48,7 +80,7 @@ function BoardSection({ isYellow }: { isYellow?: true }) {
</S.BoardSection>
);
}
return<></>;
return <></>;
}

export default BoardSection;
40 changes: 28 additions & 12 deletions styles/theme.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
import { DefaultTheme, keyframes } from "styled-components";

const color = {
lightYellow: "#FFE289",
serveYellow: "#FFF7DE",
mainGrey: "#41414B",
lightGrey: "#535360",
mainYellow: "#FFD760",
grey900: "#85858F",
grey800: "#AAAAB1",
grey700: "#DDDDDF",
grey600: "#EDEDED",
backgroundYellow: "#FFFCF4",
};

const FadeIn = keyframes`
from {
opacity: 0;
Expand All @@ -17,21 +31,23 @@ const FadeOut = keyframes`
}
`;

const Skeleton = keyframes`
from {
background-color: ${color.grey600};
}
50%{
background-color: ${color.grey700};
}
to {
background-color: ${color.grey600};
}
`;

export const theme: DefaultTheme = {
color: {
lightYellow: "#FFE289",
serveYellow: "#FFF7DE",
mainGrey: "#41414B",
lightGrey: "#535360",
mainYellow: "#FFD760",
grey900: "#85858F",
grey800: "#AAAAB1",
grey700: "#DDDDDF",
grey600: "#EDEDED",
backgroundYellow: "#FFFCF4",
},
color,
animations: {
FadeIn,
FadeOut,
Skeleton,
},
};

0 comments on commit 1a95b2a

Please sign in to comment.