-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from Read-bird/feature/yj
코드 리팩토링, 정리
- Loading branch information
Showing
18 changed files
with
405 additions
and
451 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
132 changes: 0 additions & 132 deletions
132
src/components/templates/MyPageTemplate/MyEncyclopediaTemplate/EncyclopediaList.tsx
This file was deleted.
Oops, something went wrong.
131 changes: 129 additions & 2 deletions
131
src/components/templates/MyPageTemplate/MyEncyclopediaTemplate/MyEncyclopediaTemplate.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,132 @@ | ||
import { EncyclopediaList } from '@components/templates/MyPageTemplate/MyEncyclopediaTemplate/EncyclopediaList'; | ||
import { TCollection, setCollections, setSelectCollections } from '@/store/reducers'; | ||
import { TRootState } from '@/store/state'; | ||
import { axiosFetch } from '@api/axios'; | ||
import { TResponseCollection } from '@api/types/collection'; | ||
import { IconEmptyBird } from '@assets/icons'; | ||
import { Images } from '@assets/images'; | ||
import { Spacing } from '@components/common/Spacing'; | ||
import { PlanModalTemplate } from '@components/templates/PlanModalTemplate'; | ||
import { Alert } from '@utils/Alert'; | ||
import { convertError } from '@utils/errors'; | ||
import { AxiosError } from 'axios'; | ||
import { useEffect, useState } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import styled from 'styled-components'; | ||
|
||
export const MyEncyclopediaTemplate = () => { | ||
return <EncyclopediaList />; | ||
const { collections } = useSelector((state: TRootState) => state.collectionStore); | ||
const dispatch = useDispatch(); | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const getEncyList = async () => { | ||
try { | ||
const res = await axiosFetch<any, TResponseCollection[]>({ | ||
url: '/api/collection', | ||
method: 'get' | ||
}); | ||
|
||
if (res.status === 200) { | ||
dispatch(setCollections(res.data)); | ||
} | ||
} catch (err) { | ||
if (err instanceof AxiosError) { | ||
Alert.error({ title: convertError(err.response?.data.message) }); | ||
} | ||
} | ||
}; | ||
|
||
const handleClick = (collection: TCollection | TResponseCollection) => () => { | ||
if (collection.characterId === null) { | ||
Alert.warning({ title: '아직 획득하지 못한 캐릭터입니다.' }); | ||
return; | ||
} | ||
|
||
dispatch(setSelectCollections([collection] as TResponseCollection[])); | ||
setIsOpen(true); | ||
}; | ||
|
||
useEffect(() => { | ||
getEncyList(); | ||
}, []); | ||
|
||
return ( | ||
<Wrap> | ||
<Spacing height={30} /> | ||
<StyledUl> | ||
{collections?.map((collection, index) => ( | ||
<li key={index} onClick={handleClick(collection)}> | ||
{collection.characterId === null ? ( | ||
<div className="wrap icon-wrap"> | ||
<IconEmptyBird /> | ||
</div> | ||
) : ( | ||
<div className="wrap image-wrap"> | ||
<Images imgUrl={collection.imageUrl} imgAlt={collection.name} imgWidth={65} /> | ||
</div> | ||
)} | ||
<Spacing height={10} /> | ||
<span>{collection.name}</span> | ||
</li> | ||
))} | ||
<PlanModalTemplate isOpen={isOpen} setIsOpen={setIsOpen} modalIndex={4} /> | ||
</StyledUl> | ||
</Wrap> | ||
); | ||
}; | ||
|
||
const Wrap = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
width: 100%; | ||
height: 100%; | ||
max-height: calc(100vh - 165px); | ||
padding: 0 13px; | ||
`; | ||
|
||
const StyledUl = styled.ul` | ||
width: 100%; | ||
flex: 1; | ||
max-height: calc(100vh - 195px); | ||
display: flex; | ||
justify-content: center; | ||
align-content: flex-start; | ||
flex-wrap: wrap; | ||
overflow: auto; | ||
gap: 0 20px; | ||
li { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
flex: 0 0 96px; | ||
height: 150px; | ||
cursor: pointer; | ||
div.wrap { | ||
width: 96px; | ||
height: 96px; | ||
border-radius: 50%; | ||
border: 2px solid ${({ theme }) => theme.colors.darkGray}; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
.icon-wrap { | ||
background-color: ${({ theme }) => theme.colors.subBlue}; | ||
} | ||
.image-wrap { | ||
background-color: ${({ theme }) => theme.colors.basic}; | ||
} | ||
span { | ||
display: inline-block; | ||
max-width: 60px; | ||
text-align: center; | ||
font-size: 14px; | ||
font-weight: 400; | ||
} | ||
} | ||
`; |
2 changes: 1 addition & 1 deletion
2
...eTemplate/MyLibraryTemplate/Book/Book.tsx → ...MyPageTemplate/MyLibraryTemplate/Book.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/components/templates/MyPageTemplate/MyLibraryTemplate/Book/index.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.