-
Notifications
You must be signed in to change notification settings - Fork 6
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
[FE] Feature/#435 이미지 압축 기능 구현 #436
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
59b13fc
feat: 이미지 압축하는 기능 custom hook으로 구현
GC-Park 6770957
feat: 지도, 핀 등에 이미지 추가할 시 이미지 압축 기능 추가
GC-Park 7e83f61
refactor: NewTopic, NewPin 텍스트 수정
GC-Park 53b73f8
refactor: 이미지 리사이징 최대 크기 변경
GC-Park adeb1c3
refactor: 지도 추가 페이지에서 이미지와 파일 추가 버튼 사이에 space 추가
GC-Park File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import imageCompression from 'browser-image-compression'; | ||
|
||
const useCompressImage = () => { | ||
const compressImage = async (file: File) => { | ||
const resizingBlob = await imageCompression(file, { | ||
maxSizeMB: 1, | ||
maxWidthOrHeight: 750, | ||
useWebWorker: true, | ||
}); | ||
const resizingFile = new File([resizingBlob], file.name, { | ||
type: file.type, | ||
}); | ||
return resizingFile; | ||
}; | ||
|
||
const compressImageList = async (files: FileList) => { | ||
const compressedImageList: File[] = []; | ||
|
||
for (const file of files) { | ||
const compressedImage = await compressImage(file); | ||
compressedImageList.push(compressedImage); | ||
} | ||
|
||
return compressedImageList; | ||
}; | ||
|
||
return { compressImage, compressImageList }; | ||
}; | ||
|
||
export default useCompressImage; |
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 |
---|---|---|
|
@@ -17,6 +17,7 @@ import { TagContext } from '../context/TagContext'; | |
import usePost from '../apiHooks/usePost'; | ||
import AuthorityRadioContainer from '../components/AuthorityRadioContainer'; | ||
import styled from 'styled-components'; | ||
import useCompressImage from '../hooks/useCompressImage'; | ||
|
||
type NewTopicFormValuesType = Omit<NewTopicFormProps, 'topics'>; | ||
|
||
|
@@ -34,6 +35,7 @@ const NewTopic = () => { | |
description: '', | ||
image: '', | ||
}); | ||
const { compressImage } = useCompressImage(); | ||
|
||
const [isPrivate, setIsPrivate] = useState(false); // 혼자 볼 지도 : 같이 볼 지도 | ||
const [isAll, setIsAll] = useState(true); // 모두 : 지정 인원 | ||
|
@@ -116,7 +118,7 @@ const NewTopic = () => { | |
}); | ||
}; | ||
|
||
const onTopicImageFileChange = ( | ||
const onTopicImageFileChange = async ( | ||
event: React.ChangeEvent<HTMLInputElement>, | ||
) => { | ||
const file = event.target.files && event.target.files[0]; | ||
|
@@ -128,7 +130,9 @@ const NewTopic = () => { | |
return; | ||
} | ||
|
||
setFormImage(file); | ||
const compressedFile = await compressImage(file); | ||
|
||
setFormImage(compressedFile); | ||
setShowImage(URL.createObjectURL(file)); | ||
}; | ||
|
||
|
@@ -143,9 +147,17 @@ const NewTopic = () => { | |
지도 생성 | ||
</Text> | ||
|
||
<Space size={5} /> | ||
|
||
<Text color="black" $fontSize="default" $fontWeight="normal"> | ||
지도 선택 | ||
</Text> | ||
|
||
<Space size={2} /> | ||
|
||
<Flex> | ||
{showImage && <ShowImage src={showImage} alt={`사진 이미지`} />} | ||
<Space size={2} /> | ||
<ImageInputLabel htmlFor="file">파일업로드</ImageInputLabel> | ||
<ImageInputButton | ||
id="file" | ||
|
@@ -241,7 +253,6 @@ const NewTopic = () => { | |
|
||
const ImageInputLabel = styled.label` | ||
height: 40px; | ||
margin-left: 10px; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요 속성은 어떤 이유로 삭제되었을까용?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 사진이 없으면 파일 추가 버튼이 다른 텍스트들과 왼쪽으로 정렬되지 않아 지웠었습니다! 그런데 사진이 있는 경우 버튼과 간격이 필요하니 그 부분은 space로 대체할 수 있을 것 같습니다! 수정하도록 하겠습니다~!! |
||
padding: 10px 10px; | ||
color: ${({ theme }) => theme.color.black}; | ||
background-color: ${({ theme }) => theme.color.lightGray}; | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
재사용 베리 굿~~ 👍👍