-
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.
* feat: 에러 이미지 대응 * refactor: Comment 컴포넌트에 Avatar 컴포넌트 적용
- Loading branch information
1 parent
f5be4b6
commit 1beeb37
Showing
4 changed files
with
39 additions
and
17 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,23 +1,33 @@ | ||
import Image from 'next/image'; | ||
import type { SyntheticEvent } from 'react'; | ||
import Link from 'next/link'; | ||
|
||
import UserIcon from '@/assets/icons/user.svg'; | ||
import DefaultProfileImage from '@/assets/images/default-profile.png'; | ||
|
||
interface AvatarProps { | ||
size?: number; | ||
profileImage?: string; | ||
href?: string; | ||
} | ||
|
||
export const Avatar = ({ size = 24, profileImage }: AvatarProps) => { | ||
export const Avatar = ({ size = 24, profileImage, href }: AvatarProps) => { | ||
const handleAddDefaultImg = (e: SyntheticEvent<HTMLImageElement, Event>) => { | ||
e.currentTarget.src = DefaultProfileImage.src; | ||
}; | ||
|
||
return ( | ||
<div | ||
style={{ width: size, height: size }} | ||
className="flex justify-center items-center rounded-xl overflow-hidden bg-white" | ||
> | ||
{!profileImage ? ( | ||
<UserIcon width={`calc(${size} / 1.5)`} height={`calc(${size} / 1.5)`} /> | ||
) : ( | ||
<Image src={profileImage} width={size} height={size} alt="profile_image" /> | ||
)} | ||
</div> | ||
<Link href={{ pathname: href }}> | ||
<div | ||
style={{ width: size, height: size }} | ||
className="flex justify-center items-center rounded-xl overflow-hidden bg-white" | ||
> | ||
{!profileImage ? ( | ||
<UserIcon width={`calc(${size} / 1.5)`} height={`calc(${size} / 1.5)`} /> | ||
) : ( | ||
// eslint-disable-next-line @next/next/no-img-element | ||
<img src={profileImage} width={size} height={size} alt="profile_image" onError={handleAddDefaultImg} /> | ||
)} | ||
</div> | ||
</Link> | ||
); | ||
}; |
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