-
Notifications
You must be signed in to change notification settings - Fork 6
Feat: 이미지 저장 기능 구현 완료 #295
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
Open
Eugene-A-01
wants to merge
2
commits into
8-Sprinters:dev
Choose a base branch
from
Eugene-A-01:feature/image-save
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
139 changes: 139 additions & 0 deletions
139
src/app/list/[listId]/_components/ListDetailInner/SaveImageModal.css.ts
This file contains hidden or 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,139 @@ | ||
| import { style } from '@vanilla-extract/css'; | ||
| import { vars } from '@/styles/__theme.css'; | ||
|
|
||
| export const modalOverlay = style({ | ||
| position: 'fixed', | ||
| top: 0, | ||
| left: 0, | ||
| width: '100vw', | ||
| height: '100vh', | ||
| backgroundColor: 'rgba(0, 0, 0, 0.7)', | ||
| display: 'flex', | ||
| justifyContent: 'center', | ||
| alignItems: 'center', | ||
| zIndex: 1000, | ||
| }); | ||
|
|
||
| export const modalContent = style({ | ||
| backgroundColor: vars.color.white, | ||
| padding: '2rem', | ||
| borderRadius: '20px', | ||
| width: '375px', | ||
| textAlign: 'center', | ||
| }); | ||
|
|
||
| export const captureContent = style({ | ||
| backgroundColor: vars.color.white, | ||
| width: '100%', | ||
| borderRadius: '0px', | ||
| }); | ||
|
|
||
| export const profileImageContainer = style({ | ||
| width: '36px', | ||
| height: '36px', | ||
| position: 'relative', | ||
|
|
||
| cursor: 'pointer', | ||
| }); | ||
|
|
||
| export const profileImage = style({ | ||
| width: '40px', | ||
| height: '40px', | ||
| borderRadius: '50%', | ||
| marginRight: '12px', | ||
| }); | ||
|
|
||
| export const header = style({ | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| marginBottom: '15px', | ||
| }); | ||
|
|
||
| export const headerContent = style({ | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| justifyContent: 'center', | ||
| alignItems: 'flex-start', | ||
| marginLeft: '10px', | ||
| }); | ||
|
|
||
| export const NicknameText = style({ | ||
| color: vars.color.gray9, | ||
| fontSize: '1.4rem', | ||
| fontWeight: 'bold', | ||
| }); | ||
|
|
||
| export const dateText = style({ | ||
| fontSize: '1.4rem', | ||
| color: vars.color.gray7, | ||
| }); | ||
|
|
||
| export const divider = style({ | ||
| border: 'none', | ||
| height: '1px', | ||
| backgroundColor: vars.color.gray5, | ||
| marginBottom: '30px', | ||
| }); | ||
|
|
||
| export const listContainer = style({ | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| alignItems: 'center', | ||
| padding: '30px 20px', | ||
| borderRadius: '10px', | ||
| }); | ||
|
|
||
| export const title = style({ | ||
| fontSize: '1.8rem', | ||
| fontWeight: 'bold', | ||
| }); | ||
|
|
||
| export const itemContainer = style({ | ||
| width: '100%', | ||
|
|
||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| gap: '12px', | ||
| padding: '20px', | ||
| }); | ||
|
|
||
| export const listItem = style({ | ||
| height: '6rem', | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| justifyContent: 'space-between', | ||
| padding: '10px 0', | ||
| }); | ||
|
|
||
| export const listIndex = style({ | ||
| fontSize: '1.6rem', | ||
| fontWeight: 'bold', | ||
| marginRight: '8px', | ||
| }); | ||
|
|
||
| export const listText = style({ | ||
| fontSize: '1.6rem', | ||
| flexGrow: 1, | ||
| textAlign: 'left', | ||
| }); | ||
|
|
||
| export const simpleImageWrapper = style({ | ||
| width: '5rem', | ||
| height: '5rem', | ||
|
|
||
| display: 'flex', | ||
| justifyContent: 'center', | ||
| alignItems: 'center', | ||
|
|
||
| textAlign: 'center', | ||
| }); | ||
|
|
||
| export const simpleImage = style({ | ||
| width: '5rem', | ||
| height: '5rem', | ||
|
|
||
| borderRadius: '10px', | ||
| boxShadow: '0px 4px 10px rgba(0, 0, 0, 0.15)', | ||
|
|
||
| objectFit: 'cover', | ||
| }); |
126 changes: 126 additions & 0 deletions
126
src/app/list/[listId]/_components/ListDetailInner/SaveImageModal.tsx
This file contains hidden or 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,126 @@ | ||
| 'use client'; | ||
|
|
||
| import { useEffect, useRef } from 'react'; | ||
| import { toPng } from 'html-to-image'; | ||
| import toasting from '@/lib/utils/toasting'; | ||
| import * as styles from './SaveImageModal.css'; | ||
| import Image from 'next/image'; | ||
| import fallbackProfile from '/public/images/fallback_profileImage.webp'; | ||
| import { BACKGROUND_COLOR_READ } from '@/styles/Color'; | ||
| import { ItemType } from '@/lib/types/listType'; | ||
|
|
||
| interface SaveImageModalProps { | ||
| data: { | ||
| title: string; | ||
| ownerNickname: string; | ||
| ownerProfileImageUrl: string; | ||
| lastUpdatedDate: Date; | ||
| items: ItemType[]; | ||
| backgroundColor: string; | ||
| }; | ||
| onClose: () => void; | ||
| } | ||
|
|
||
| const SaveImageModal = ({ data, onClose }: SaveImageModalProps) => { | ||
| const captureRef = useRef<HTMLDivElement | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| const timer = setTimeout(() => { | ||
| if (captureRef.current) { | ||
| const clonedCapture = captureRef.current.cloneNode(true) as HTMLDivElement; | ||
| clonedCapture.style.width = `${window.innerWidth}px`; | ||
| clonedCapture.style.height = `${window.innerHeight}px`; | ||
| clonedCapture.style.padding = '50px 30px'; | ||
|
|
||
| document.body.appendChild(clonedCapture); | ||
|
|
||
| toPng(clonedCapture, { backgroundColor: '#fff' }) | ||
| .then((dataUrl) => { | ||
| const link = document.createElement('a'); | ||
| link.download = `listywave_${data.title}.png`; | ||
| link.href = dataUrl; | ||
| link.click(); | ||
| toasting({ type: 'success', txt: '이미지를 저장하였습니다' }); | ||
| }) | ||
| .catch((err) => { | ||
| console.error('이미지 저장 오류:', err); | ||
| toasting({ type: 'error', txt: '이미지 저장을 실패했습니다.' }); | ||
| }) | ||
| .finally(() => { | ||
| document.body.removeChild(clonedCapture); | ||
| onClose(); | ||
| }); | ||
| } | ||
| }, 1000); | ||
|
|
||
| return () => clearTimeout(timer); | ||
| }, [data.title, onClose]); | ||
|
|
||
| return ( | ||
| <div className={styles.modalOverlay}> | ||
| <div className={styles.modalContent}> | ||
| <div className={styles.captureContent} ref={captureRef}> | ||
| <div className={styles.header}> | ||
| <div className={styles.profileImageContainer}> | ||
| {data?.ownerProfileImageUrl !== '' ? ( | ||
| <Image | ||
| src={data?.ownerProfileImageUrl} | ||
| className={styles.profileImage} | ||
| width={40} | ||
| height={40} | ||
| style={{ objectFit: 'cover', borderRadius: '50%' }} | ||
| alt="profile" | ||
| /> | ||
| ) : ( | ||
| <Image | ||
| src={fallbackProfile} | ||
| alt="profile" | ||
| className={styles.profileImage} | ||
| width={40} | ||
| height={40} | ||
| style={{ objectFit: 'cover', borderRadius: '50%' }} | ||
| /> | ||
| )} | ||
| </div> | ||
| <div className={styles.headerContent}> | ||
| <div className={styles.NicknameText}>{data.ownerNickname}</div> | ||
| <div className={styles.dateText}>{new Date(data.lastUpdatedDate).toLocaleString()}</div> | ||
| </div> | ||
| </div> | ||
| <hr className={styles.divider} /> | ||
|
|
||
| <div | ||
| className={styles.listContainer} | ||
| style={{ | ||
| backgroundColor: BACKGROUND_COLOR_READ[data?.backgroundColor as keyof typeof BACKGROUND_COLOR_READ], | ||
| }} | ||
| > | ||
| <div className={styles.title}>{data.title}</div> | ||
|
|
||
| <div className={styles.itemContainer}> | ||
| {data.items.map((item, idx) => ( | ||
| <div key={idx} className={styles.listItem}> | ||
| <span className={styles.listIndex}>{idx + 1}.</span> | ||
| <span className={styles.listText}>{item.title}</span> | ||
| {item.imageUrl && ( | ||
| <div className={styles.simpleImageWrapper}> | ||
| <Image | ||
| className={styles.simpleImage} | ||
| src={item.imageUrl} | ||
| alt={item.title} | ||
| width={70} | ||
| height={72} | ||
| /> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default SaveImageModal; | ||
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.
모달로 띄워지고 자동으로 닫히고 저장까지 너무 완벽하게 구현해주셔서 놀랐어요!!🥹 ver2때 만들어 둔 디자인은 있는데 ver3용은 없네요ㅠ, ver3에 맞게 어떻게 바꿀 수 있을지 고민해보겠습니다!!
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.
참고로 ver2 디자인 후보가 아래와 같았는데요! 최대 10개까지 아이템이 있고, 아이템당 100자까지 작성 가능한 점을 고려하여 아래와 같은 조건을 세웠습니다.
[조건]