123
This commit is contained in:
@@ -10,12 +10,53 @@ import { RankIcon3rd } from "@/app/components/RankIcon3rd";
|
||||
import { UserAvatar } from "@/app/components/UserAvatar";
|
||||
import { ImagePlaceholderIcon } from "@/app/components/ImagePlaceholderIcon";
|
||||
import { BoardPanelClient } from "@/app/components/BoardPanelClient";
|
||||
import { GradeIcon, getGradeName } from "@/app/components/GradeIcon";
|
||||
import prisma from "@/lib/prisma";
|
||||
import { headers } from "next/headers";
|
||||
|
||||
export default async function Home({ searchParams }: { searchParams: Promise<{ sort?: "recent" | "popular" } | undefined> }) {
|
||||
const sp = await searchParams;
|
||||
const sort = sp?.sort ?? "recent";
|
||||
|
||||
// 로그인된 사용자 정보 가져오기 (기본값: 어드민)
|
||||
let currentUser: {
|
||||
userId: string;
|
||||
nickname: string;
|
||||
profileImage: string | null;
|
||||
points: number;
|
||||
level: number;
|
||||
grade: number;
|
||||
} | null = null;
|
||||
|
||||
try {
|
||||
const h = await headers();
|
||||
const cookieHeader = h.get("cookie") || "";
|
||||
const uid = cookieHeader
|
||||
.split(";")
|
||||
.map((s) => s.trim())
|
||||
.find((pair) => pair.startsWith("uid="))
|
||||
?.split("=")[1];
|
||||
|
||||
if (uid) {
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { userId: decodeURIComponent(uid) },
|
||||
select: { userId: true, nickname: true, profileImage: true, points: true, level: true, grade: true },
|
||||
});
|
||||
if (user) currentUser = user;
|
||||
}
|
||||
} catch (e) {
|
||||
// 에러 무시
|
||||
}
|
||||
|
||||
// 로그인되지 않은 경우 어드민 사용자 가져오기
|
||||
if (!currentUser) {
|
||||
const admin = await prisma.user.findUnique({
|
||||
where: { nickname: "admin" },
|
||||
select: { userId: true, nickname: true, profileImage: true, points: true, level: true, grade: true },
|
||||
});
|
||||
if (admin) currentUser = admin;
|
||||
}
|
||||
|
||||
// 메인페이지 설정 불러오기
|
||||
const SETTINGS_KEY = "mainpage_settings" as const;
|
||||
const settingRow = await prisma.setting.findUnique({ where: { key: SETTINGS_KEY } });
|
||||
@@ -94,7 +135,7 @@ export default async function Home({ searchParams }: { searchParams: Promise<{ s
|
||||
|
||||
if (isSpecialRank) {
|
||||
specialRankUsers = await prisma.user.findMany({
|
||||
select: { userId: true, nickname: true, points: true, profileImage: true },
|
||||
select: { userId: true, nickname: true, points: true, profileImage: true, grade: true },
|
||||
where: { status: "active" },
|
||||
orderBy: { points: "desc" },
|
||||
take: 3,
|
||||
@@ -106,6 +147,7 @@ export default async function Home({ searchParams }: { searchParams: Promise<{ s
|
||||
id: true,
|
||||
title: true,
|
||||
createdAt: true,
|
||||
content: true,
|
||||
attachments: {
|
||||
where: { type: "image" },
|
||||
orderBy: { sortOrder: "asc" },
|
||||
@@ -187,50 +229,52 @@ export default async function Home({ searchParams }: { searchParams: Promise<{ s
|
||||
<div className="h-[120px] flex items-center justify-center relative z-10">
|
||||
<div className="flex items-center justify-center gap-[8px]">
|
||||
<UserAvatar
|
||||
src={null}
|
||||
alt="프로필"
|
||||
src={currentUser?.profileImage || null}
|
||||
alt={currentUser?.nickname || "프로필"}
|
||||
width={120}
|
||||
height={120}
|
||||
className="rounded-full"
|
||||
/>
|
||||
<div className="w-[62px] h-[62px] rounded-full bg-neutral-200 flex items-center justify-center text-[11px] text-neutral-700">
|
||||
Lv
|
||||
</div>
|
||||
{currentUser && (
|
||||
<div className="w-[62px] h-[62px] flex items-center justify-center">
|
||||
<GradeIcon grade={currentUser.grade} width={62} height={62} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="h-[120px] flex flex-col items-center relative z-10">
|
||||
<div className="text-[18px] text-[#5c5c5c] font-[700] truncate text-center mb-[20px]">홍길동</div>
|
||||
<div className="text-[18px] text-[#5c5c5c] font-[700] truncate text-center mb-[20px]">{currentUser?.nickname || "사용자"}</div>
|
||||
<div className="w-[300px] pl-[67px] flex flex-col gap-[12px]">
|
||||
<div className="grid grid-cols-[64px_auto] gap-x-[24px] items-center h-[16px]">
|
||||
<div className="w-[64px] flex items-center">
|
||||
<ProfileLabelIcon width={16} height={16} />
|
||||
<span className="ml-[8px] text-[12px] text-[#8c8c8c] font-[700]">레벨</span>
|
||||
</div>
|
||||
<div className="text-[16px] text-[#5c5c5c] font-[700]">Lv. 79</div>
|
||||
<div className="text-[16px] text-[#5c5c5c] font-[700]">Lv. {currentUser?.level || 1}</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-[64px_auto] gap-x-[24px] items-center h-[16px]">
|
||||
<div className="w-[64px] flex items-center">
|
||||
<ProfileLabelIcon width={16} height={16} />
|
||||
<span className="ml-[8px] text-[12px] text-[#8c8c8c] font-[700]">등급</span>
|
||||
</div>
|
||||
<div className="text-[16px] text-[#5c5c5c] font-[700]">Iron</div>
|
||||
<div className="text-[16px] text-[#5c5c5c] font-[700]">{getGradeName(currentUser?.grade || 0)}</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-[64px_auto] gap-x-[24px] items-center h-[16px]">
|
||||
<div className="w-[64px] flex items-center">
|
||||
<ProfileLabelIcon width={16} height={16} />
|
||||
<span className="ml-[8px] text-[12px] text-[#8c8c8c] font-[700]">포인트</span>
|
||||
</div>
|
||||
<div className="text-[16px] text-[#5c5c5c] font-[700]">1,600,000</div>
|
||||
<div className="text-[16px] text-[#5c5c5c] font-[700]">{(currentUser?.points || 0).toLocaleString()}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col gap-[12px] relative z-10">
|
||||
<button className="relative w-[300px] h-[32px] rounded-full bg-[#8c8c8c] hover:bg-[#7a7a7a] text-white text-[12px] font-[700] flex items-center">
|
||||
<span className="absolute left-[100px] inline-flex items-center">
|
||||
<Link href="/my-page" className="relative w-[300px] h-[32px] rounded-full bg-[#8c8c8c] hover:bg-[#7a7a7a] text-white text-[12px] font-[700] flex items-center justify-center">
|
||||
<span className="inline-flex items-center">
|
||||
<SearchIcon width={16} height={16} />
|
||||
<span className="ml-[8px]">내 정보 페이지</span>
|
||||
</span>
|
||||
</button>
|
||||
</Link>
|
||||
<button className="relative w-[300px] h-[32px] rounded-full bg-[#8c8c8c] hover:bg-[#7a7a7a] text-white text-[12px] font-[700] flex items-center">
|
||||
<span className="absolute left-[100px] inline-flex items-center">
|
||||
<SearchIcon width={16} height={16} />
|
||||
|
||||
Reference in New Issue
Block a user