Skip to content

Commit 3d58855

Browse files
authored
Merge pull request #36 from DeveloperBlog-Devflow/feature/home-page
feat: uid에 따른 랜덤 고유 이모지 생성 기능 구현
2 parents a03db61 + b214917 commit 3d58855

4 files changed

Lines changed: 33 additions & 5 deletions

File tree

app/(with-sidebar)/(home)/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ const Page = () => {
119119
<ProfileSection
120120
className="grid grid-cols-1 gap-4 md:grid-cols-3"
121121
profile={profile}
122+
uid={currentUser.uid}
122123
/>
123124

124125
{/* 2-2. GraphSection */}

components/home/ButtonSection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const ButtonSection = ({ onAddTodo }: ButtonSectionProps) => {
2424
onClick={handleAddClick}
2525
className="flex-1 rounded-xl border border-slate-300 bg-none py-4 text-center text-base font-semibold text-slate-700 transition hover:bg-slate-200 active:bg-slate-300 disabled:cursor-not-allowed disabled:opacity-60"
2626
>
27-
계획 추가하기
27+
플랜 추가하기
2828
</button>
2929
</div>
3030
);

components/home/ProfileSection.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { Profile } from '@/lib/home/profileService';
22
import Card from './Card';
3-
3+
import { getRandomProfileIcon } from '@/utils/getRandomProfileIcon';
44
interface ProfileSectionProps {
55
className?: string;
66
profile: Profile | null;
7+
uid: string;
78
}
89

9-
const ProfileSection = ({ className, profile }: ProfileSectionProps) => {
10+
const ProfileSection = ({ className, profile, uid }: ProfileSectionProps) => {
11+
const icon = getRandomProfileIcon(uid);
1012
return (
1113
<div className={className}>
1214
<div className="md:col-span-2">
1315
<Card className="flex items-center gap-4">
14-
<div className="flex h-16 w-16 items-center justify-center overflow-hidden rounded-full border border-gray-100 bg-purple-100">
15-
<span className="text-3xl">😈</span>
16+
<div className="flex h-16 w-16 items-center justify-center overflow-hidden rounded-full border border-gray-100 bg-purple-100 pt-1">
17+
<span className="text-3xl">{icon}</span>
1618
</div>
1719

1820
<div>

utils/getRandomProfileIcon.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const PROFILE_ICONS = [
2+
'🌱',
3+
'🔥',
4+
'😎',
5+
'😈',
6+
'🖤',
7+
'💀',
8+
'⚡',
9+
'🌸',
10+
'🐣',
11+
] as const;
12+
13+
export type ProfileIcon = (typeof PROFILE_ICONS)[number];
14+
15+
export function getRandomProfileIcon(seed: string): ProfileIcon {
16+
let hash = 0;
17+
18+
for (let i = 0; i < seed.length; i++) {
19+
hash = (hash << 5) - hash + seed.charCodeAt(i);
20+
hash |= 0; // 32bit
21+
}
22+
23+
const index = Math.abs(hash) % PROFILE_ICONS.length;
24+
return PROFILE_ICONS[index];
25+
}

0 commit comments

Comments
 (0)