-
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
Changes from all commits
174ce28
411d303
60b6185
02ea86f
6d398aa
8d3dc98
6e5ba0a
96adafc
b24b287
cc5e0e7
8e4cfdc
20d374d
4dba235
a16c2e8
56a273a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,80 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'use client' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import Image from 'next/image' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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">사용자</span> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+50
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
- <Image
- src="/images/profile.gif"
- fill
- alt="프로필 이미지"
- className="size-full object-cover"
- />
+ <Image
+ src={imageUrl}
+ fill
+ alt={`${nickname} 프로필 이미지`}
+ className="size-full object-cover"
+ />
...
- <span className="text-sm font-semibold">사용자</span>
+ <span className="text-sm font-semibold">{nickname}</span>또한 컨테이너에 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) : ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // 프로필 이미지가 없을 때 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <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> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
|
||
Uh oh!
There was an error while loading. Please reload this page.