Skip to content

Commit

Permalink
Merge pull request #63 from Team-Lecue/feature/StickerPack
Browse files Browse the repository at this point in the history
[ stickerPack ] dev 머지 PR 입니다!!
  • Loading branch information
eunbeann authored Jan 10, 2024
2 parents 88dc483 + 0280bc2 commit e10db9c
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"noEmptyLineBetween": true,
"properties": [
"display",
"gap",
"justify-content",
"align-items",
"flex-direction",
Expand All @@ -30,6 +31,12 @@
"flex-grow",
"flex-shrink",
"flex-basis",
"grid-template-columns",
"grid-area",
"grid-template-rows",
"grid-column",
"grid-template-areas",
"grid-gap",
"position",
"top",
"right",
Expand Down Expand Up @@ -77,6 +84,8 @@
"border-style",
"background",
"background-color",
"background-position",
"background-size",
"color",
"font-style",
"font-weight",
Expand Down
2 changes: 2 additions & 0 deletions src/Router.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { BrowserRouter, Route, Routes } from 'react-router-dom';

import HomePage from './Home/page/HomePage';
import StickerPack from './StickerPack/page/StickerPack';

function Router() {
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/sticker-pack" element={<StickerPack />} />
</Routes>
</BrowserRouter>
);
Expand Down
12 changes: 12 additions & 0 deletions src/StickerPack/api/getStickerPack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { api } from '../../libs/api';

export async function getStickerPack(bookId: number) {
const data = await api.get(`/api/stickers/${bookId}`, {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${import.meta.env.VITE_APP_TOKEN}`,
},
});

return data.data.data;
}
41 changes: 41 additions & 0 deletions src/StickerPack/components/StickerList/StickerList.style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import styled from '@emotion/styled';

export const Wrapper = styled.section`
display: flex;
flex-direction: column;
`;

export const Title = styled.header`
margin: 1.4rem 0;
color: ${({ theme }) => theme.colors.BG};
${({ theme }) => theme.fonts.Head2_SB_18};
`;

export const StickerGridWrapper = styled.article`
display: grid;
gap: 2.15rem 1.6rem;
grid-template-columns: repeat(3, 1fr);
margin-bottom: 5rem;
`;

export const ImageWrapper = styled.button<{
isSelected: boolean;
}>`
width: 10rem;
height: 10rem;
border: solid 0.1rem
${({ theme, isSelected }) =>
isSelected ? theme.colors.key : theme.colors.background};
border-radius: 0.4rem;
`;

export const ImageComponent = styled.img`
width: 10rem;
height: 10rem;
object-fit: contain;
`;
44 changes: 44 additions & 0 deletions src/StickerPack/components/StickerList/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Fragment } from 'react';

import useGetStickerPack from '../../hooks/useGetStickerPack';
import { stickerPackType } from '../../type/stickerPackType';
import * as S from './StickerList.style';

interface StickerListProps {
isSelectedId: number | null;
handleStickerClick: (stickerId: number) => void;
}

function StickerList(props: StickerListProps) {
const { isSelectedId, handleStickerClick } = props;
//TODO 임시 값 수정
const { stickerPack } = useGetStickerPack(1);

return (
<S.Wrapper>
{stickerPack?.length > 0 &&
stickerPack.map((data: stickerPackType) => (
<Fragment key={data.stickerCategory}>
<S.Title>{data.stickerCategory}</S.Title>
<S.StickerGridWrapper>
{data.stickerList.map((sticker) => (
<S.ImageWrapper
type="button"
key={sticker.stickerId}
onClick={() => handleStickerClick(sticker.stickerId)}
isSelected={sticker.stickerId === isSelectedId}
>
<S.ImageComponent
src={sticker.stickerImage}
alt="스티커 이미지"
/>
</S.ImageWrapper>
))}
</S.StickerGridWrapper>
</Fragment>
))}
</S.Wrapper>
);
}

export default StickerList;
Empty file.
17 changes: 17 additions & 0 deletions src/StickerPack/hooks/useGetStickerPack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useQuery } from 'react-query';

import { getStickerPack } from '../api/getStickerPack';

export default function useGetStickerPack(bookId: number) {
const { data: stickerPack } = useQuery(
['useGetStickerPack'],
() => getStickerPack(bookId),
{
onError: () => {
console.error;
},
},
);

return { stickerPack };
}
18 changes: 18 additions & 0 deletions src/StickerPack/page/StickerPack/StickerPack.style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import styled from '@emotion/styled';

export const Body = styled.article`
padding: 0 1.64rem;
padding-bottom: 5rem;
background-color: ${({ theme }) => theme.colors.background};
`;

export const Wrapper = styled.section`
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
width: 100vw;
height: 100dvh;
`;
41 changes: 41 additions & 0 deletions src/StickerPack/page/StickerPack/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { useState } from 'react';

// component
import Button from '../../../components/common/Button/index.tsx';
import Header from '../../../components/common/Header/index.tsx';
import StickerList from '../../components/StickerList/index.tsx';
// style
import * as S from './StickerPack.style.ts';

function StickerPack() {
const [isSelectedId, setIsSelectedId] = useState<number | null>(null);

const handleStickerClick = (stickerId: number) => {
setIsSelectedId(stickerId);
};

const handleClickDone = () => {
alert(`${isSelectedId}`);
};

return (
<>
<Header headerTitle="스티커팩" />
<S.Body>
<StickerList
isSelectedId={isSelectedId}
handleStickerClick={handleStickerClick}
/>
<Button
variant="choose"
disabled={isSelectedId == null}
onClick={handleClickDone}
>
선택 완료
</Button>
</S.Body>
</>
);
}

export default StickerPack;
9 changes: 9 additions & 0 deletions src/StickerPack/type/stickerPackType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface stickerPackType {
stickerCategory: string;
stickerList: [
{
stickerId: number;
stickerImage: string;
},
];
}
3 changes: 3 additions & 0 deletions src/components/common/Button/Button.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import styled from '@emotion/styled';
export type ButtonStyle = 'choose' | 'complete';

export const CustomButton = styled.button<{ variant: ButtonStyle }>`
position: fixed;
bottom: 2rem;
width: 34.4rem;
height: 6rem;
Expand Down

0 comments on commit e10db9c

Please sign in to comment.