-
Notifications
You must be signed in to change notification settings - Fork 0
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
[FEAT] 테스트 결과 이미지 저장 기능 구현 #131
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
291fa5a
:sparkles: downloadFile 유틸 구현
CodyMan0 1fc7298
:lipstick: ImageBox 컴포넌트 분리
CodyMan0 61e6922
:white_check_mark: 서버 이미지 이전 Mock Image를 위한 도메인 설정
CodyMan0 1c7e53d
:hammer_and_wrench: modern-screenshot 라이브러리 설치
CodyMan0 04d98f6
:sparkles: canva 엘리먼트의 dataURL을 활용하는 라이브러리를 사용하여 이미지 저장 기능 구현
CodyMan0 768208e
Merge branch 'main' into feat/#18-image
CodyMan0 56f69ee
:zap: SVG 확장자 이미지를 활용하여 추출 이미지 화질 개선
CodyMan0 9bbdc86
:sparkles: 이미지 저장시 Spinner 추가 구현
CodyMan0 3e1a067
Merge branch 'main' into feat/#18-image
CodyMan0 9b565c9
:lipstick: 변경된 색상 및 로딩 제거, 저장시 토스트 메세지 등장하도록 구현
CodyMan0 c3ec5a5
:recycle: 리뷰 반영하여 수정
CodyMan0 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
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,43 @@ | ||
'use client'; | ||
|
||
import { useRef } from 'react'; | ||
|
||
import FirstResultType from '@/assets/images/result/firstResultType.svg'; | ||
import ForthResultType from '@/assets/images/result/forthResultType.svg'; | ||
import SecondResultType from '@/assets/images/result/secondResultType.svg'; | ||
import ThirdResultType from '@/assets/images/result/thirdResultType.svg'; | ||
import { Button } from '@/components/common/button'; | ||
import { Typography } from '@/foundations/typography'; | ||
import { useDownloadImage } from '@/hooks/useDownloadImage'; | ||
import { TestResultType } from '@/types/test'; | ||
|
||
// TODO : 백엔드와 논의하여 resultTypeId 프로퍼티 결정 | ||
const ImageBox = ({ resultTypeId = 100 }: { resultTypeId: TestResultType['ResultTypeid'] }) => { | ||
const imageRef = useRef<HTMLDivElement>(null); | ||
const { onDownloadImage } = useDownloadImage({ imageRef }); | ||
|
||
const handleDownloadImage = async () => { | ||
await onDownloadImage(); | ||
}; | ||
return ( | ||
<> | ||
<div ref={imageRef}>{resultTypeMap[resultTypeId]}</div> | ||
<div className="flex items-center gap-5xs py-xs"> | ||
<Button variant="empty" onClick={handleDownloadImage} className="h-[30px]"> | ||
<Typography type="body2" className=" border-b-2 border-[#5382FF] text-[#5382FF]"> | ||
이미지 저장하기 | ||
</Typography> | ||
</Button> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default ImageBox; | ||
|
||
const resultTypeMap = { | ||
0: <FirstResultType />, | ||
36: <SecondResultType />, | ||
70: <ThirdResultType />, | ||
100: <ForthResultType />, | ||
}; |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { default as ImageBox } from './ImageBox'; | ||
export { default as ResultContents } from './ResultContents'; | ||
export { default as TempertaureBox } from './TempertaureBox'; | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
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,57 @@ | ||
|
||
import { domToJpeg } from 'modern-screenshot'; | ||
import { RefObject, useState } from 'react'; | ||
|
||
import { downloadFile } from '@/utils/image'; | ||
|
||
import useToast from './useToast'; | ||
|
||
type DownloadImageOption = { | ||
imageRef: RefObject<HTMLElement>; | ||
} | ||
|
||
// TODO : 필요한 옵션 알아봐서 추가할 예정 | ||
const defaultDownloadOption = { | ||
scale: 2, | ||
}; | ||
|
||
export const useDownloadImage = ({ imageRef }: DownloadImageOption) => { | ||
|
||
const [isDownloading, setIsDownloading] = useState(false); | ||
const toast = useToast(); | ||
|
||
const downloadOption = { | ||
height: 700, | ||
...defaultDownloadOption, | ||
}; | ||
|
||
const onDownloadImage = async () => { | ||
const image = imageRef.current; | ||
|
||
if (!image) return; | ||
|
||
try { | ||
setIsDownloading(true); | ||
|
||
const imageOption = downloadOption | ||
const imageUrl = await domToJpeg(image, imageOption); | ||
|
||
// TODO: 동적으로 4개의 유형의 이름을 할당할 예정 | ||
const IMAGE_FILE_NAME = '돈워리_결과_사진'; | ||
|
||
|
||
downloadFile(imageUrl, IMAGE_FILE_NAME); | ||
toast({ type: 'default', message: '이미지를 저장하였습니다.' }) | ||
} catch (error) { | ||
console.log(error,'error') | ||
toast({message:'IMAGE_SAVE_FAIL'}) | ||
} finally { | ||
setIsDownloading(false); | ||
} | ||
}; | ||
|
||
return { | ||
isDownloading, | ||
onDownloadImage, | ||
}; | ||
}; |
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 +1,2 @@ | ||
export * from './result'; | ||
export * from './test'; |
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,19 @@ | ||
|
||
|
||
// TODO : 엄격한 타입 설정하기 | ||
export type TestResultType = { | ||
id: number | ||
age: '20대' | '30대' | '40대' | ||
gender: '남자' | '여자' | ||
buddy: string | ||
trust: number | ||
love : number | ||
talk : number | ||
temperature: number | ||
ResultTypeid : 0 | 36| 70 | 100 | ||
imageUrl: string | ||
description : string | ||
title: string | ||
createdAt : string | ||
} | ||
|
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,9 @@ | ||
|
||
export const downloadFile = (url: string, filename: string) => { | ||
const link = document.createElement('a'); | ||
|
||
link.download = filename; | ||
link.href = url; | ||
|
||
link.click(); | ||
}; |
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.
button에 isLoading 프롭이 있긴해요! 필요하심 사용하셔도 되고 아니면 지금 유지하셔도 됩니닷
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.
디자인이 변경돼서 로딩하지 않기로 이야기했어요! disable 처리하려고 하는데 isLoading props 사용해서 구현할게요~