-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: 보관한 편지 이미지 다운로드 기능 추가 (#303)
* ✨ feat: 보관한 편지 이미지 다운로그 기능 추가 * 🔨 refactor: 이미지 다운로드 유틸로 분리 * 🚚 rename: 함수명 imageDownload에서 downloadImage 로 변경
- Loading branch information
1 parent
7e0579a
commit fca9e57
Showing
6 changed files
with
76 additions
and
70 deletions.
There are no files selected for viewing
20 changes: 2 additions & 18 deletions
20
src/pages/LetterReceptionPage/NormalReception/components/ReceptionPolaroid.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
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
38 changes: 38 additions & 0 deletions
38
src/pages/LetterStoragePage/ReplyStorage/ReplyPolaroidModal.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { css } from '@emotion/react'; | ||
import PolaroidModal from '@/components/PolaroidModal'; | ||
import Button from '@/components/Button'; | ||
import IconButton from '@/components/IconButton'; | ||
import { Download } from '@/assets/icons'; | ||
import { downloadImage } from '@/utils/downloadUtils'; | ||
|
||
interface ReplyPolaroidModalProps { | ||
imagePath: string; | ||
} | ||
|
||
const ReplyPolaroidModal = ({ imagePath }: ReplyPolaroidModalProps) => { | ||
return ( | ||
<PolaroidModal | ||
img={imagePath} | ||
headerRightContent={ | ||
<IconButton | ||
css={style.download} | ||
onClick={() => downloadImage(imagePath)} | ||
> | ||
<Download color="white" height={20} width={20} /> | ||
</IconButton> | ||
} | ||
> | ||
<Button variant="secondary" size="sm"> | ||
닫기 | ||
</Button> | ||
</PolaroidModal> | ||
); | ||
}; | ||
|
||
export default ReplyPolaroidModal; | ||
|
||
const style = { | ||
download: css` | ||
margin-right: 2px; | ||
`, | ||
}; |
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,26 @@ | ||
import axios from 'axios'; | ||
|
||
/** | ||
* 이미지 다운로드 | ||
* @param imagePath 이미지 경로 | ||
* @returns | ||
*/ | ||
export const downloadImage = async (imagePath: string) => { | ||
if (!imagePath) { | ||
return; | ||
} | ||
|
||
const response = await axios.get(imagePath, { | ||
responseType: 'blob', | ||
}); | ||
|
||
const url = window.URL.createObjectURL(new Blob([response.data])); | ||
|
||
const link = document.createElement('a'); | ||
link.href = url; | ||
link.download = 'image.jpg'; | ||
document.body.appendChild(link); | ||
link.click(); | ||
|
||
window.URL.revokeObjectURL(url); | ||
}; |