-
Notifications
You must be signed in to change notification settings - Fork 2
✨Feat: 공통 사용자 프로필 구현 #33
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
Merged
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
174ce28
🐛Fix: 에러 수정
yuj2n 411d303
🎨Style: global.css의 커스텀 유틸리티 클래스 적용
yuj2n 60b6185
✨Feat: clsx와 twMerge의 병합 구현
yuj2n 02ea86f
✨Feat: clsx + twMerge로 조건부 스타일 간결화
yuj2n 6d398aa
🔧Chore: lib 사용을 위한 alias 설정 추가
yuj2n 8d3dc98
🎨Style: 프로필 이미지 흰 글씨를 위한 커스텀 클래스 추가
yuj2n 6e5ba0a
✨Feat: 공통 사용자 프로필 컴포넌트 구현
yuj2n 96adafc
✨Feat: 공통 프로필 이미지 적용 및 헤더 스타일 일부 수정
yuj2n b24b287
🎨Style: 로직 이해를 위한 주석 추가
yuj2n cc5e0e7
🐛Fix: useUserStore 충돌 방지를 위한 코드 수정
yuj2n 8e4cfdc
🫧Modify: useUserStore 충돌 방지를 위한 코드 수정
yuj2n 20d374d
Merge branch 'feature/Profile' of https://github.com/yuj2n/coplan int…
yuj2n 4dba235
Merge branch 'develop' into feature/Profile
yuj2n a16c2e8
Merge branch 'feature/Profile' of https://github.com/yuj2n/coplan int…
yuj2n 56a273a
🫧modify: useUserStore 삭제
yuj2n 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,81 @@ | ||
| 'use client' | ||
|
|
||
| import Image from 'next/image' | ||
| import { useUserStore } from '@store/useUserStore' | ||
|
|
||
| type ProfileProps = { | ||
| nickname: string | ||
| imageUrl?: string | ||
| size?: number | ||
| } | ||
|
|
||
| const customColors = [ | ||
| '#efaa8d', | ||
| '#FFC85A', | ||
| '#b9ef8d', | ||
| '#8eef8d', | ||
| '#8defd3', | ||
| '#8dcaef', | ||
| '#8d9def', | ||
| '#a58def', | ||
| '#e292e0', | ||
| ] | ||
|
|
||
| // 첫 글자로 사용자 프로필 생성하는 함수 | ||
| function getInitial(nickname: string): string { | ||
| const firstChar = nickname.trim().charAt(0) | ||
|
|
||
| if (/[a-zA-Z]/.test(firstChar)) { | ||
| return firstChar.toUpperCase() // 영어: 대문자 | ||
| } | ||
|
|
||
| if (/[가-힣]/.test(firstChar)) { | ||
| return firstChar // 한글은 그대로 반환 | ||
| } | ||
|
|
||
| return '?' // 기타문자: 물음표 | ||
| } | ||
|
|
||
| // 닉네임으로부터 배경색 생성 함수 | ||
| function getColor(nickname: string): string { | ||
| const hash = nickname | ||
| .split('') | ||
| .reduce((acc, char) => acc + char.charCodeAt(0), 0) | ||
| return customColors[hash % customColors.length] | ||
| } | ||
yuj2n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export function Profile({ nickname, imageUrl, size = 36 }: ProfileProps) { | ||
yuj2n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const initial = getInitial(nickname) | ||
| const bgColor = getColor(nickname) | ||
|
|
||
| const { user } = useUserStore() | ||
|
|
||
| return imageUrl ? ( | ||
| <div className="flex items-center gap-4"> | ||
| <div className="relative size-48 overflow-hidden rounded-full"> | ||
| <Image | ||
| src="/images/profile.gif" | ||
| fill | ||
| alt="프로필 이미지" | ||
| className="size-full object-cover" | ||
| /> | ||
| </div> | ||
| <span className="text-sm font-semibold">사{user?.name}</span> | ||
| </div> | ||
| ) : ( | ||
| <> | ||
| <div | ||
| className="ml-8 flex items-center justify-center rounded-full font-semibold text-white" | ||
| style={{ | ||
| width: size, | ||
| height: size, | ||
| fontSize: size * 0.4, // 글자 크기 조정 | ||
| backgroundColor: bgColor, | ||
| }} | ||
| > | ||
| {initial} | ||
| </div> | ||
| <div className="text-base font-medium">{nickname}</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
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,6 @@ | ||
| import { clsx, type ClassValue } from 'clsx' | ||
| import { twMerge } from 'tailwind-merge' | ||
|
|
||
| export function cn(...inputs: ClassValue[]) { | ||
| return twMerge(clsx(inputs)) | ||
| } | ||
yuj2n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
yuj2n marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
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
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.