-
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.
- Loading branch information
Showing
16 changed files
with
198 additions
and
15 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
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