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

feat: home 컴포넌트 반응형 구현 #50

Merged
merged 1 commit into from
Aug 26, 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
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