refactor: profile components
why did I do it like that???
This commit is contained in:
parent
09c2448116
commit
c4a8e82313
3 changed files with 14 additions and 18 deletions
|
|
@ -77,8 +77,8 @@ export default async function ProfilePage({ params }: Props) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<ProfileInformation user={user} createdAt={user.createdAt} />
|
<ProfileInformation userId={user.id} />
|
||||||
<MiiList isLoggedIn={session?.user != null} userId={user?.id} sessionUserId={Number(session?.user.id ?? -1)} />
|
<MiiList isLoggedIn={session?.user != null} userId={user.id} sessionUserId={Number(session?.user.id ?? -1)} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ import { Metadata } from "next";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
import { auth } from "@/lib/auth";
|
import { auth } from "@/lib/auth";
|
||||||
import { prisma } from "@/lib/prisma";
|
|
||||||
|
|
||||||
import ProfileSettings from "@/components/profile-settings";
|
import ProfileSettings from "@/components/profile-settings";
|
||||||
import ProfileInformation from "@/components/profile-information";
|
import ProfileInformation from "@/components/profile-information";
|
||||||
|
|
@ -21,11 +20,9 @@ export default async function ProfileSettingsPage() {
|
||||||
|
|
||||||
if (!session) redirect("/login");
|
if (!session) redirect("/login");
|
||||||
|
|
||||||
const userExtra = await prisma.user.findUnique({ where: { id: Number(session.user.id) } });
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<ProfileInformation createdAt={userExtra!.createdAt} inSettings />
|
<ProfileInformation inSettings />
|
||||||
<ProfileSettings />
|
<ProfileSettings />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,30 @@
|
||||||
|
import Link from "next/link";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { User } from "@prisma/client";
|
|
||||||
import { Icon } from "@iconify/react";
|
import { Icon } from "@iconify/react";
|
||||||
|
|
||||||
import { auth } from "@/lib/auth";
|
import { auth } from "@/lib/auth";
|
||||||
import { prisma } from "@/lib/prisma";
|
import { prisma } from "@/lib/prisma";
|
||||||
import Link from "next/link";
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
user?: User;
|
userId?: number;
|
||||||
createdAt: Date;
|
|
||||||
inSettings?: boolean;
|
inSettings?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function ProfileInformation({ user: userData, createdAt, inSettings }: Props) {
|
export default async function ProfileInformation({ userId, inSettings }: Props) {
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
|
|
||||||
const id = userData && userData.id ? userData.id : Number(session?.user.id);
|
const id = userId ? userId : Number(session?.user.id);
|
||||||
const user = userData ? userData : session?.user;
|
const user = await prisma.user.findUnique({ where: { id } });
|
||||||
|
|
||||||
const likedMiis = await prisma.like.count({ where: { userId: id } });
|
const likedMiis = await prisma.like.count({ where: { userId: id } });
|
||||||
|
|
||||||
|
if (!user) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex gap-4 mb-2 max-md:flex-col">
|
<div className="flex gap-4 mb-2 max-md:flex-col">
|
||||||
<div className="flex w-full gap-4 overflow-x-scroll">
|
<div className="flex w-full gap-4 overflow-x-scroll">
|
||||||
{/* Profile picture */}
|
{/* Profile picture */}
|
||||||
<Image
|
<Image
|
||||||
src={user?.image ?? "/guest.webp"}
|
src={user.image ?? "/guest.webp"}
|
||||||
alt="profile picture"
|
alt="profile picture"
|
||||||
width={128}
|
width={128}
|
||||||
height={128}
|
height={128}
|
||||||
|
|
@ -34,7 +33,7 @@ export default async function ProfileInformation({ user: userData, createdAt, in
|
||||||
{/* User information */}
|
{/* User information */}
|
||||||
<div className="flex flex-col w-full relative">
|
<div className="flex flex-col w-full relative">
|
||||||
<h1 className="text-4xl font-extrabold w-full break-words flex items-center gap-2">
|
<h1 className="text-4xl font-extrabold w-full break-words flex items-center gap-2">
|
||||||
{user?.name}
|
{user.name}
|
||||||
{id === Number(process.env.NEXT_PUBLIC_ADMIN_USER_ID) && (
|
{id === Number(process.env.NEXT_PUBLIC_ADMIN_USER_ID) && (
|
||||||
<div data-tooltip="Admin" className="font-normal text-orange-400">
|
<div data-tooltip="Admin" className="font-normal text-orange-400">
|
||||||
<Icon icon="mdi:shield-moon" />
|
<Icon icon="mdi:shield-moon" />
|
||||||
|
|
@ -51,8 +50,8 @@ export default async function ProfileInformation({ user: userData, createdAt, in
|
||||||
<h4 className="mt-auto text-sm">
|
<h4 className="mt-auto text-sm">
|
||||||
Liked <span className="font-bold">{likedMiis}</span> Miis
|
Liked <span className="font-bold">{likedMiis}</span> Miis
|
||||||
</h4>
|
</h4>
|
||||||
<h4 className="text-sm" title={`${createdAt.toLocaleTimeString("en-GB", { timeZone: "UTC" })} UTC`}>
|
<h4 className="text-sm" title={`${user.createdAt.toLocaleTimeString("en-GB", { timeZone: "UTC" })} UTC`}>
|
||||||
Created: {createdAt.toLocaleDateString("en-GB", { month: "long", day: "2-digit", year: "numeric" })}
|
Created: {user.createdAt.toLocaleDateString("en-GB", { month: "long", day: "2-digit", year: "numeric" })}
|
||||||
</h4>
|
</h4>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue