-
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.
* chore: Browser Image Compression install * chore: import order 옵션 변경 * feat: Browser Image 업로드 압축 설정 및 기능 추가 * feat: 이미지 업로드 및 상태 관리 * feat: 이미지 업로드 api 구현 및 연동 서버 에러 확인중 * chore: vscode setting json 추가 사용하지 않는 import 저장 시 자동 제거 import 누락 자동 import 기능 추가 * refactor: test data 제거 * feat: 글 수정 시 사진 수정 기능 추가 --------- Co-authored-by: yogjin <[email protected]>
- Loading branch information
1 parent
f93c708
commit e18743c
Showing
16 changed files
with
916 additions
and
231 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
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 |
---|---|---|
|
@@ -13,7 +13,6 @@ dist-ssr | |
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
|
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"eslint.workingDirectories": [ | ||
{ | ||
"mode": "auto" | ||
} | ||
], | ||
"editor.formatOnSave": true, | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll": "explicit", | ||
"source.fixAll.eslint": "explicit", | ||
"source.organizeImports": "explicit", | ||
"source.addMissingImports": "explicit" | ||
} | ||
} |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import styled from '@emotion/styled'; | ||
import { Box, Flex, SVGCancel, theme } from 'concept-be-design-system'; | ||
import { useState } from 'react'; | ||
import useAlert from '../../../hooks/useAlert'; | ||
import useCompressImage from '../hooks/useCompressImage'; | ||
|
||
interface Props { | ||
images: File[]; | ||
setImages: React.Dispatch<React.SetStateAction<File[]>>; | ||
} | ||
|
||
const AddImages = ({ images, setImages }: Props) => { | ||
const [imageUrls, setImageUrls] = useState<string[]>([]); | ||
const openAlert = useAlert(); | ||
const { compressImages } = useCompressImage(); | ||
|
||
const onChangeImage = async (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const currentImages = e.target.files; | ||
|
||
if (!currentImages) return; | ||
if (images.length + currentImages.length > 3) { | ||
openAlert({ content: '이미지는 최대 3개까지 업로드 가능합니다.' }); | ||
return; | ||
} | ||
|
||
const compressedImages = await compressImages(currentImages); | ||
const imageObjectUrls = compressedImages.map((image) => URL.createObjectURL(image)); | ||
|
||
setImages([...images, ...compressedImages]); | ||
setImageUrls([...imageUrls, ...imageObjectUrls]); | ||
}; | ||
|
||
const onClickDeleteImage = (index: number) => { | ||
setImages(images.filter((_, idx) => idx !== index)); | ||
setImageUrls(imageUrls.filter((_, idx) => idx !== index)); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Wrapper width="100%" height="100%" padding="22px" overflow="scroll" boxSizing="border-box"> | ||
<Flex gap={8}> | ||
<AddImageLabel htmlFor="add-image">+</AddImageLabel> | ||
<AddImageInput id="add-image" type="file" multiple onChange={onChangeImage}></AddImageInput> | ||
{imageUrls.map((imageUrl, index) => ( | ||
<Box position="relative" key={index}> | ||
<Flex | ||
position="absolute" | ||
top="0" | ||
right="0" | ||
width={32} | ||
height={32} | ||
justifyContent="center" | ||
alignItems="center" | ||
backgroundColor="b6" | ||
cursor="pointer" | ||
> | ||
<SVGCancel color="white" onClick={() => onClickDeleteImage(index)} /> | ||
</Flex> | ||
<Image src={imageUrl} alt={`이미지 ${index + 1}`} /> | ||
</Box> | ||
))} | ||
</Flex> | ||
</Wrapper> | ||
</> | ||
); | ||
}; | ||
|
||
const Wrapper = styled(Flex)` | ||
&::-webkit-scrollbar { | ||
display: none; | ||
} | ||
`; | ||
|
||
const Image = styled.img` | ||
width: 120px; | ||
height: 120px; | ||
object-fit: cover; | ||
`; | ||
|
||
const AddImageLabel = styled.label` | ||
width: 120px; | ||
height: 120px; | ||
background-color: ${theme.color.b4}; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
font-size: 32px; | ||
font-weight: 100; | ||
color: ${theme.color.w1}; | ||
cursor: pointer; | ||
`; | ||
|
||
const AddImageInput = styled.input` | ||
display: none; | ||
`; | ||
|
||
export default AddImages; |
Oops, something went wrong.