-
Notifications
You must be signed in to change notification settings - Fork 0
[✨ Feat/#64] Profile 컴포넌트 구현 #65
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
231af0c
✨ Feat: 사용자 프로필 컴포넌트 추가
Lseojeong f7a4fc9
📝 Docs: 프로필 이미지 호스트 TODO 추가
Lseojeong 568ba54
🐛 Fix: 프로필 스토리 mock 이미지 경로 수정
Lseojeong 9915bd9
🐛 Fix: 프로필 기본 이미지 fallback 지원
Lseojeong 6ce0054
♻️ Refactor: 프로필 컴포넌트 props 정리
Lseojeong a0b9cba
♻️ Refactor: 프로필 이미지 실패 상태 변수명 개선
Lseojeong b12c415
🐛 Fix: PNG 이미지 타입 선언 추가
Lseojeong 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 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
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,2 @@ | ||
| export { Profile } from './ui/Profile'; | ||
| export type { UserProfile } from './model/types'; |
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,4 @@ | ||
| export interface UserProfile { | ||
| name: string; | ||
| profileImageUrl: string; | ||
| } |
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,26 @@ | ||
| import { DefaultProfileImage } from '@/shared/assets/images'; | ||
|
|
||
| import { Profile } from './Profile'; | ||
|
|
||
| import type { Meta, StoryObj } from '@storybook/nextjs'; | ||
|
|
||
| const meta = { | ||
| title: 'Entities/User/Profile', | ||
| component: Profile, | ||
| args: { | ||
| name: '이서정', | ||
| profileImageUrl: DefaultProfileImage.src, | ||
| }, | ||
| } satisfies Meta<typeof Profile>; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| export const Default: Story = {}; | ||
|
|
||
| export const Fallback: Story = { | ||
| args: { | ||
| profileImageUrl: '/invalid-profile-image.png', | ||
| }, | ||
| }; |
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,37 @@ | ||
| import type { ImageProps } from 'next/image'; | ||
|
|
||
| import { DefaultProfileImage } from '@/shared/assets/images'; | ||
|
|
||
| import { ProfileImage } from './ProfileImage'; | ||
|
|
||
| import type { UserProfile } from '../model/types'; | ||
|
|
||
| interface ProfileProps extends UserProfile { | ||
| fallbackImageSrc?: ImageProps['src']; | ||
| imageAlt?: string; | ||
| } | ||
|
|
||
| /** | ||
| * ## Profile | ||
| * | ||
| * @description | ||
| * 로그인 사용자 프로필을 이름과 원형 프로필 이미지로 표시하는 도메인 UI입니다. | ||
| * | ||
| * @param name - 사용자 이름 | ||
| * @param profileImageUrl - 백엔드에서 전달받은 프로필 이미지 URL | ||
| * @param fallbackImageSrc - 프로필 이미지 로딩 실패 시 표시할 대체 이미지 | ||
| * @param imageAlt - 이미지 대체 텍스트. 전달하지 않으면 사용자 이름 기반으로 생성합니다. | ||
| */ | ||
| export function Profile({ | ||
| name, | ||
| profileImageUrl, | ||
| fallbackImageSrc = DefaultProfileImage, | ||
| imageAlt = `${name} 프로필 이미지`, | ||
| }: ProfileProps) { | ||
| return ( | ||
| <div className="flex items-center gap-3"> | ||
| <ProfileImage alt={imageAlt} fallbackSrc={fallbackImageSrc} src={profileImageUrl} /> | ||
| <span className="body-16 truncate font-medium text-white">{name}</span> | ||
| </div> | ||
| ); | ||
| } |
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,38 @@ | ||
| 'use client'; | ||
|
|
||
| import { useState } from 'react'; | ||
|
|
||
| import Image from 'next/image'; | ||
| import type { ImageProps } from 'next/image'; | ||
|
|
||
| interface ProfileImageProps { | ||
| alt: string; | ||
| fallbackSrc: ImageProps['src']; | ||
| src: string; | ||
| } | ||
|
|
||
| export function ProfileImage({ alt, fallbackSrc, src }: ProfileImageProps) { | ||
| const [failedImageSrc, setFailedImageSrc] = useState<string | null>(null); | ||
| const imageSrc = failedImageSrc === src ? fallbackSrc : src; | ||
|
|
||
| const handleError = () => { | ||
| if (imageSrc === fallbackSrc) { | ||
| return; | ||
| } | ||
|
|
||
| setFailedImageSrc(src); | ||
| }; | ||
|
|
||
| return ( | ||
| <Image | ||
| alt={alt} | ||
| className="size-8 shrink-0 rounded-full border border-white object-cover" | ||
| fetchPriority="high" | ||
| height={32} | ||
| loading="eager" | ||
| onError={handleError} | ||
| src={imageSrc} | ||
| width={32} | ||
| /> | ||
| ); | ||
| } |
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 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,3 @@ | ||
| import DefaultProfileImage from './img-default-profile.png'; | ||
|
|
||
| export { DefaultProfileImage }; | ||
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,5 @@ | ||
| declare module '*.png' { | ||
| const content: import('next/image').StaticImageData; | ||
|
|
||
| export default content; | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.