From 80c80a0350a96f22ed336c00b97ba323f149d02d Mon Sep 17 00:00:00 2001 From: Caner <s86215@bht-berlin.de> Date: Wed, 28 Jun 2023 23:35:24 +0200 Subject: [PATCH] UserPage fix und link --- app/(content)/(user)/[userid]/page.tsx | 23 +++++++++++-------- components/gweets/components/gweet-author.tsx | 4 +++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/app/(content)/(user)/[userid]/page.tsx b/app/(content)/(user)/[userid]/page.tsx index 2698ce4..35f635b 100644 --- a/app/(content)/(user)/[userid]/page.tsx +++ b/app/(content)/(user)/[userid]/page.tsx @@ -5,38 +5,43 @@ import { Skeleton } from "@/components/ui/skeleton" import { UserAvatar } from "@/components/user-avatar" import { db } from "@/lib/db" import { getFavoriteGames } from "@/lib/igdb" -import { getCurrentUser } from "@/lib/session" import { IGame } from "@/types/igdb-types" import { redirect } from "next/navigation" + export default async function User({ params }: { params: { userid: string } }) { - const user = await getCurrentUser() + + const user = await db.user.findFirst({ + where: { + username: params.userid + } + }) - if (user?.username !== params.userid) { + if(!user){ redirect('/') } + const fullUser = await db.user.findFirst({ where: { - id: user?.id + id: user.id } }) - let favoritegames = undefined let playingGames = undefined let finishedGames = undefined let planningGames = undefined - if (fullUser?.favGameList?.length !== 0) { + if (fullUser?.favGameList?.length !== 0 && fullUser?.favGameList?.length != undefined) { favoritegames = await getFavoriteGames(fullUser?.favGameList!) } - if (fullUser?.favGameList?.length !== 0) { + if (fullUser?.playingGameList?.length !== 0) { playingGames = await getFavoriteGames(fullUser?.playingGameList!) } - if (fullUser?.favGameList?.length !== 0) { + if (fullUser?.finishedGameList?.length !== 0) { finishedGames = await getFavoriteGames(fullUser?.finishedGameList!) } - if (fullUser?.favGameList?.length !== 0) { + if (fullUser?.planningGameList?.length !== 0) { planningGames = await getFavoriteGames(fullUser?.planningGameList!) } return ( diff --git a/components/gweets/components/gweet-author.tsx b/components/gweets/components/gweet-author.tsx index c086804..632b8c8 100644 --- a/components/gweets/components/gweet-author.tsx +++ b/components/gweets/components/gweet-author.tsx @@ -1,15 +1,17 @@ import { UserAvatar } from "@/components/user-avatar"; import { IGweet } from "../types"; import { GweetOptions } from "./gweet-options"; +import Link from "next/link"; export const GweetAuthor = ({ gweet }: { gweet: IGweet }) => { return ( <div className="flex items-center"> + <Link href={`/${gweet.author.username}`}> <UserAvatar user={{ username: gweet.author.username, image: gweet.author.image }} className="h-10 w-10" /> - + </Link> <div className="flex flex-col ml-3"> <span className="font-bold">{gweet.author.name}</span> <span className="text-sky-500 text-sm">@{gweet.author.username}</span> -- GitLab