Skip to content

Commit

Permalink
[ feat ] 상세 페이지 구현
Browse files Browse the repository at this point in the history
1. 상세 페이지 퍼블리싱
2. 상세 페이지 API 연결

related to: #10
  • Loading branch information
eonseok-jeon committed Jan 1, 2024
1 parent a010a79 commit 34c82f0
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Error from '@components/Error';
import Onboarding from '@pages/Onboarding';
import Search from '@pages/Search';
import App from './App';
import Detail from '@pages/Detail';

export const router = createBrowserRouter([
{
Expand All @@ -13,7 +14,13 @@ export const router = createBrowserRouter([
{ index: true, element: <Onboarding /> },
{
path: '/search',
element: <Search />,
children: [
{
index: true,
element: <Search />,
},
{ path: ':title', element: <Detail /> },
],
},
],
},
Expand Down
65 changes: 65 additions & 0 deletions src/pages/Detail/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/** @jsxImportSource @emotion/react */

import { useParams } from 'react-router-dom';
import useSWR from 'swr';
import { fetcher } from '@utils/fetcher';
import styled from '@emotion/styled';
import { css } from '@emotion/react';

/** 상세 페이지 */
export default function Detail() {
const { title } = useParams();
const { data } = useSWR(`https://dapi.kakao.com/v3/search/book?query=${title}`, fetcher);

return (
<DetailWrapper>
{data && (
<DetailBox>
<img src={data[0].thumbnail} alt="book-cover" width={270} height={400} />
<article>
<h1 css={mainTitle}>{data[0].title}</h1>
<div css={bookInfo}>
<span>{data[0].authors}</span>
<span>{data[0].publisher}</span>
<span>{data[0].price}</span>
</div>
<p css={bookContent}>{data[0].contents}</p>
</article>
</DetailBox>
)}
</DetailWrapper>
);
}

const mainTitle = css`
font-size: 3rem;
margin-bottom: 1rem;
`;

const bookInfo = css`
display: flex;
gap: 3rem;
font-size: 1.4rem;
margin-bottom: 2rem;
`;

const bookContent = css`
font-size: 2.4rem;
`;

const DetailWrapper = styled.div`
width: 100%;
height: 100vh;
background-color: ${({ theme }) => theme.colors.bgColor};
padding: 0 12rem;
margin: 0 auto;
`;

const DetailBox = styled.div`
display: flex;
gap: 4.5rem;
max-width: 120rem;
margin: 50vh auto;
color: ${({ theme }) => theme.colors.textColor01};
transform: translateY(-50%);
`;
3 changes: 2 additions & 1 deletion src/pages/Search/components/Books.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export default function Books(props: Book) {

const Container = styled.article`
${commonFlex}
gap: 4rem
gap: 4rem;
cursor: pointer;
`;

const BookImg = styled.img`
Expand Down

0 comments on commit 34c82f0

Please sign in to comment.