Skip to content

Commit

Permalink
Merge pull request #50 from GlowTales/feat/#41
Browse files Browse the repository at this point in the history
feat: home 컴포넌트 반응형 구현
  • Loading branch information
cjy3458 authored Aug 26, 2024
2 parents bdfbe7b + af92a5f commit eabff69
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 14 deletions.
46 changes: 42 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-icons": "^5.3.0",
"react-responsive": "^10.0.0",
"react-router-dom": "^6.26.1",
"styled-components": "^6.1.12",
"zustand": "^4.5.5"
Expand Down
15 changes: 12 additions & 3 deletions src/components/home/homeRecentTales/HomeRecentTales.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,24 @@ export const CardWrapper = styled.div`
justify-content: center;
align-items: flex-end;
@media (max-width: 710px) {
flex-direction: column;
align-items: center;
margin-top: 2rem;
flex-wrap: wrap;
gap: 1.5rem;
gap: 1rem;
}
`;

export const ShelfWrapper = styled.div`
width: 100%;
display: flex;
justify-content: center;
margin-top: 1rem;
`;

export const Shelf = styled.img`
@media (max-width: 710px) {
width: 550px;
}
@media (max-width: 450px) {
display: none;
}
`;
36 changes: 29 additions & 7 deletions src/components/home/homeRecentTales/HomeRecentTales.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import { getRecentTale } from "@apis/createTales";
import { useEffect, useState } from "react";
import { CardProps } from "@type/card";
import { useNavigate } from "react-router-dom";
import { getToken } from "@apis/login";
import { useMediaQuery } from "react-responsive";

const HomeRecentTales = () => {
const mediaQuery = useMediaQuery({ query: "(max-width: 710px)" });

getToken();
const [tales, setTales] = useState<CardProps[]>([]);
const navigate = useNavigate();

Expand All @@ -17,6 +22,7 @@ const HomeRecentTales = () => {
};
recentTales();
}, []);
// const sliceTales = tales.slice(0, 9);

const chunkedTales = [];
const sliceTales = tales.slice(0, 9);
Expand All @@ -40,9 +46,25 @@ const HomeRecentTales = () => {
{"더보기 >"}
</div>
</S.TitleWrapper>
{chunkedTales.map((taleGroup, index) => (
<>
<div key={index}>
{mediaQuery ? (
<S.CardWrapper>
{sliceTales.map((tale, index) => (
<>
<Card
taleId={tale.taleId}
title={tale.title}
createdAt={tale.createdAt}
readFunction={() => goRead(tale)}
/>
{(index + 1) % 2 === 0 && index !== sliceTales.length - 1 && (
<S.Shelf src="shelf.png" key={`shelf-${index}`} />
)}
</>
))}
</S.CardWrapper>
) : (
chunkedTales.map((taleGroup) => (
<>
<S.CardWrapper>
{taleGroup.map((tale) => (
<Card
Expand All @@ -54,10 +76,10 @@ const HomeRecentTales = () => {
/>
))}
</S.CardWrapper>
</div>
<S.Shelf src="shelf.png" />
</>
))}
<S.Shelf src="shelf.png" />
</>
))
)}
</S.Wrapper>
);
};
Expand Down

0 comments on commit eabff69

Please sign in to comment.