Skip to content
Snippets Groups Projects
Commit 707f8942 authored by Yusuf Akgül's avatar Yusuf Akgül :hatching_chick:
Browse files

toast messages

parents 96465ba6 60a445b6
No related branches found
No related tags found
1 merge request!45Email verify
Pipeline #39316 passed
Showing
with 610 additions and 586 deletions
// loading component, this renders when loading in /games happens
export default function Loading() {
return (
<div>
<h1>Game Loading...</h1>
</div>
)
}
\ No newline at end of file
import AddGameDropdown from "@/components/add-game-dropdown";
import AddGameToFavList from "@/components/addGameToFavList";
import { BackHeader } from "@/components/back-header";
import { AspectRatio } from "@/components/ui/aspect-ratio";
import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import { db } from "@/lib/db";
import { getGame } from "@/lib/igdb";
import { getCurrentUser } from "@/lib/session";
import { formatDate } from "@/lib/utils";
import { IGame } from "@/types/igdb-types";
import Image from "next/image";
import AddGameDropdown from "@/components/add-game-dropdown"
import AddGameToFavList from "@/components/addGameToFavList"
import { BackHeader } from "@/components/back-header"
import { GlobalLayout } from "@/components/global-layout"
import { AspectRatio } from "@/components/ui/aspect-ratio"
import { Button } from "@/components/ui/button"
import { Card } from "@/components/ui/card"
import { db } from "@/lib/db"
import { getGame } from "@/lib/igdb"
import { getCurrentUser } from "@/lib/session"
import { formatDate } from "@/lib/utils"
import { IGame } from "@/types/igdb-types"
import Image from "next/image"
// renders a single game detail page
export default async function GameDetail({ params }: { params: { gameid: string } }) {
const data: IGame[] = await getGame(parseInt(params.gameid))
// TODO put to backend
const date = formatDate(data[0].first_release_date * 1000)
const user = await getCurrentUser()
......@@ -32,75 +33,78 @@ export default async function GameDetail({ params }: { params: { gameid: string
})
return (
<div className="main-content h-full">
<Card className="w-full h-full overflow-hidden">
<div className="p-3">
<BackHeader>
<h1 className="font-bold">Game</h1>
</BackHeader>
</div>
<GlobalLayout
mainContent={
<Card className="w-full overflow-hidden">
<div className="p-3">
<BackHeader>
<h1 className="font-bold">Game</h1>
</BackHeader>
</div>
<div className="h-64 overflow-hidden">
<AspectRatio ratio={889 / 500}>
<Image
src={data[0].screenshots[0].url}
alt={data[0].name}
fill
priority
className="object-center" />
</AspectRatio>
</div>
<div className="p-6 md:p-12 ss:flex">
<div className="aspect-[264/374]">
<Card className="aspect-[264/374] relative block group -mt-36 w-52 flex-shrink-0">
<div className="h-64 overflow-hidden">
<AspectRatio ratio={889 / 500}>
<Image
src={data[0].cover.url}
src={data[0].screenshots[0].url}
alt={data[0].name}
fill
priority
className="object-cover rounded-lg" />
</Card>
<div className="flex justify-start p-6">
<AddGameDropdown fullUser={fullUser!} gameid={params.gameid} />
</div>
className="object-center" />
</AspectRatio>
</div>
<div className="p-6 md:p-12 ss:flex">
<div className="aspect-[264/374]">
<Card className="aspect-[264/374] relative block group -mt-36 w-52 flex-shrink-0">
<Image
src={data[0].cover.url}
alt={data[0].name}
fill
priority
className="object-cover rounded-lg" />
</Card>
<div className="flex justify-start p-6">
<AddGameDropdown fullUser={fullUser!} gameid={params.gameid} />
</div>
</div>
<div className="ml-6 md:ml-12 space-y-3">
<h1 className="text-2xl font-bold">{data[0].name}</h1>
<h1>released on{' '}
<span className="font-semibold">{date}</span> by{' '}
<span className="font-semibold">{companies}</span>
</h1>
<h1 className="pt-3">{data[0].summary}</h1>
<div className="ml-6 md:ml-12 space-y-3">
<h1 className="text-2xl font-bold">{data[0].name}</h1>
<h1>released on{' '}
<span className="font-semibold">{date}</span> by{' '}
<span className="font-semibold">{companies}</span>
</h1>
<h1 className="pt-3">{data[0].summary}</h1>
<div className="pt-6">
<div className="pt-6">
<h1 className="mb-2">Genres</h1>
<div className="flex flex-wrap gap-2">
{data[0].genres.map((genre, i) => {
return <Button key={i} variant="outline" size="lg" className="px-6 py-3">{genre.name}</Button>
})}
<h1 className="mb-2">Genres</h1>
<div className="flex flex-wrap gap-2">
{data[0].genres.map((genre, i) => {
return <Button key={i} variant="outline" size="lg" className="px-6 py-3">{genre.name}</Button>
})}
</div>
</div>
</div>
<div className="pt-6">
<h1 className="mb-2">Platforms</h1>
<div className="flex flex-wrap gap-2">
{data[0].platforms.map((platform, i) => {
return <Button key={i} variant="outline" size="lg" className="px-6 py-3">{platform.name}</Button>
})}
<div className="pt-6">
<h1 className="mb-2">Platforms</h1>
<div className="flex flex-wrap gap-2">
{data[0].platforms.map((platform, i) => {
return <Button key={i} variant="outline" size="lg" className="px-6 py-3">{platform.name}</Button>
})}
</div>
</div>
</div>
</div>
</div>
<div className="px-6 md:px-12">
<div className="border-b border-gray-400 dark:border-gray-200" />
<div className="p-6 w-full flex justify-center">
{user && <AddGameToFavList userGameList={fullUser?.favGameList!} gameId={params.gameid} />}
<div className="px-6 md:px-12">
<div className="border-b border-gray-400 dark:border-gray-200" />
<div className="p-6 w-full flex justify-center">
{user && <AddGameToFavList userGameList={fullUser?.favGameList!} gameId={params.gameid} />}
</div>
{/* comments */}
</div>
{/* comments */}
</div>
</Card >
<div className="side-content">
</Card >
}
sideContent={
<Card className="p-6 grid items-start gap-2 bg-secondary">
<h1>Screenshots</h1>
<div className="grid grid-cols-1 gap-4">
......@@ -118,7 +122,7 @@ export default async function GameDetail({ params }: { params: { gameid: string
})}
</div>
</Card>
</div>
</div >
}
/>
)
}
\ No newline at end of file
import { Card } from "@/components/ui/card";
import { Skeleton } from "@/components/ui/skeleton";
export default function Loading() {
return (
<main className="main-content">
<div className="flex justify-center">
<Card className="p-6 w-full">
<div className="grid grid-cols-1 ss:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-4 lg:gap-8">
{Array.from({ length: 18 }, (_, i) => i + 1).map((i) => (
<Skeleton key={i} className="aspect-[264/374] bg-gray-300" />
))}
</div>
</Card>
</div>
<div className="side-content">
<Card className="p-6 grid items-start gap-2 bg-secondary">
<Skeleton className="h-6 w-1/4 bg-gray-400 dark:bg-gray-200" />
<Skeleton className="h-10 bg-background w-full" />
<Skeleton className="h-10 bg-background w-full" />
<Skeleton className="h-10 bg-background w-full" />
<Skeleton className="h-6 w-1/4 mt-6 bg-gray-400 dark:bg-gray-200" />
<Skeleton className="h-10 bg-background w-full" />
<Skeleton className="h-10 w-full bg-gray-300" />
</Card>
</div>
</main>
)
}
\ No newline at end of file
import Sort from "@/components/filter-sort-games";
import { InfiniteScrollGames } from "@/components/infinity-scroll";
import ScrollToTop from "@/components/scroll-to-top";
import Sort from "@/components/filter-sort-games"
import { GlobalLayout } from "@/components/global-layout"
import { InfiniteScrollGames } from "@/components/infinity-scroll"
import ScrollToTop from "@/components/scroll-to-top"
// renders a list of games infinitely
export default async function GamesPage() {
return (
<main className="main-content">
<div className="flex justify-center">
<div className="fixed top-30 z-40">
<ScrollToTop />
</div>
<InfiniteScrollGames />
</div>
<div className="side-content">
<GlobalLayout
mainContent={
<>
<div className="fixed top-30 z-40">
<ScrollToTop />
</div>
<InfiniteScrollGames />
</>
}
sideContent={
<Sort />
</div>
</main>
}
/>
)
}
\ No newline at end of file
import { CreateGweet } from "@/components/create-gweet/components/create-gweet";
import { Gweets } from "@/components/gweets/components/gweets";
import { CreateGweet } from "@/components/create-gweet/components/create-gweet"
import { GlobalLayout } from "@/components/global-layout"
import { Gweets } from "@/components/gweets/components/gweets"
import ScrollToTop from "@/components/scroll-to-top"
import { Trends } from "@/components/trends/components/trends"
import { Card } from "@/components/ui/card"
export default async function HomePage() {
return (
<div className="main-content px-3 pb-3">
<div className="lg:col-span-1">
<CreateGweet />
<Gweets />
</div>
<div className="side-content">
<div className="flex-col">
</div>
</div>
</div>
)
return (
<GlobalLayout
mainContent={
<>
<div className="fixed top-30 z-40">
<ScrollToTop />
</div>
<div className="w-full space-y-6 flex flex-col">
<CreateGweet />
<Gweets />
</div>
</>
}
sideContent={
<Card className="p-5 bg-secondary">
<Trends />
</Card>
}
/>
)
}
\ No newline at end of file
import { BackHeader } from "@/components/back-header"
import { GlobalLayout } from "@/components/global-layout"
import { Trends } from "@/components/trends/components/trends"
import { Card } from "@/components/ui/card"
export default async function TrendsPage() {
return (
<GlobalLayout
mainContent={
<Card className="w-full overflow-hidden">
<div className="p-3">
<BackHeader>
<h1 className="font-bold">Trends</h1>
</BackHeader>
</div>
<div className="px-5">
<Trends title="" />
</div>
</Card>
}
/>
)
}
\ No newline at end of file
import { UserAvatar } from "@/components/user-avatar";
import { db } from "@/lib/db";
import { User } from "@prisma/client";
import { getServerSession } from "next-auth";
import { GlobalLayout } from "@/components/global-layout"
import { UserAvatar } from "@/components/user-avatar"
import { db } from "@/lib/db"
import { User } from "@prisma/client"
import Link from "next/link"
export default async function UserFollowers({ params }: { params: { userid: string } }) {
// const session = await getServerSession(authOptions);
// if (!session) {
// return <div>Loading...</div>;
// }
const fullUser = await db.user.findFirst({
where: {
......@@ -21,7 +17,6 @@ export default async function UserFollowers({ params }: { params: { userid: stri
}
})
const followers = await db.user.findMany({
where: {
following: {
......@@ -38,21 +33,30 @@ export default async function UserFollowers({ params }: { params: { userid: stri
})
return (
<div>
<h1>Followers Page WIP</h1>
{followers?.map((follower: User) => (
<div key={follower.id}> {follower.id} <UserAvatar
user={{ username: follower.name || null, image: follower.image || null }}
className="h-20 w-20 -mt-50" />
<div className="ml-6 md:ml-12 space-y-3">
<h1 className="text-2xl font-bold">{follower.name}</h1>
<h1 className="text-md text-sky-500">@{follower.username}</h1>
</div>
<GlobalLayout
mainContent={
<div className="flex flex-col w-full">
{followers?.map((follower: User) => (
<div className="flex items-center space-y-6" key={follower.id}>
<Link href={`/${follower.username}`} className="flex flex-row">
<UserAvatar
user={{ username: follower.username, image: follower.image }}
className="h-10 w-10"
/>
<div className="flex flex-col ml-3">
<span className="font-bold">{follower.name}</span>
<span className="text-sky-500 text-sm">@{follower.username}</span>
</div>
</Link>
<div className="ml-auto">
{/* Followbutton */}
</div>
</div>
))}
</div>
))}
</div>
}
/>
)
}
}
\ No newline at end of file
import FollowButton from "@/components/following-button"
import GameItem from "@/components/game-item"
import { GlobalLayout } from "@/components/global-layout"
import { AspectRatio } from "@/components/ui/aspect-ratio"
import { Card } from "@/components/ui/card"
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 sessionUser = await db.user.findFirst({
where: {
id: user?.id
},
include: {
following: true,
followers: true
}
})
const fullUser = await db.user.findFirst({
where: {
username: params.userid
},
include: {
following: true,
followers: true
}
})
if (!fullUser) {
redirect('/home')
}
let favoritegames = undefined
let playingGames = undefined
let finishedGames = undefined
let planningGames = undefined
if (fullUser?.favGameList?.length !== 0 && fullUser?.favGameList?.length != undefined) {
favoritegames = await getFavoriteGames(fullUser?.favGameList!)
}
if (fullUser?.playingGameList?.length !== 0) {
playingGames = await getFavoriteGames(fullUser?.playingGameList!)
}
if (fullUser?.finishedGameList?.length !== 0) {
finishedGames = await getFavoriteGames(fullUser?.finishedGameList!)
}
if (fullUser?.planningGameList?.length !== 0) {
planningGames = await getFavoriteGames(fullUser?.planningGameList!)
}
return (
<GlobalLayout
mainContent={
<div className="space-y-6 w-full">
<Card className="overflow-hidden">
<div className="h-64 overflow-hidden">
<AspectRatio ratio={889 / 500} className="bg-slate-600 dark:bg-slate-400">
{/* profile banner */}
{/* <Image
src={ }
alt={ }
fill
priority
className="object-center" /> */}
</AspectRatio>
</div>
<div className="p-6 md:p-12 ss:flex">
<UserAvatar
user={{ username: fullUser.username, image: fullUser.image || null }}
className="h-52 w-52 -mt-36"
/>
<div className="ml-6 md:ml-12 space-y-3">
<h1 className="text-2xl font-bold">{fullUser.name}</h1>
<h1 className="text-md text-sky-500">@{fullUser.username}</h1>
{/* <h1 className="pt-3">{fullUser.bio}</h1> */}
</div>
<div className="flex justify-start ml-6 md:ml-12 space-y-3">
<FollowButton user={sessionUser!} followingId={fullUser?.id!} />
</div>
</div>
<div className="px-6 md:px-12">
{/* <div className="border-b border-gray-400 dark:border-gray-200" /> */}
{/* gweets */}
</div>
</Card >
<Card className="overflow-hidden p-6 md:p-12" >
<h1 className="text-2xl font-bold pb-3">Favorite Games</h1>
<div className="grid grid-cols-1 ss:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-4 lg:gap-8 items-center">
{favoritegames ? favoritegames.map((game: IGame) => (
<GameItem id={game.id} name={game.name} cover={game.cover} key={game.id} />
))
:
<p>No favorites currently...</p>}
</div>
</Card>
<Card className="overflow-hidden p-6 md:p-12" >
<h1 className="text-2xl font-bold pb-3">Currently playing</h1>
<div className="grid grid-cols-1 ss:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-4 lg:gap-8 items-center">
{playingGames ? playingGames.map((game: IGame) => (
<GameItem id={game.id} name={game.name} cover={game.cover} key={game.id} />
))
:
<p>Currently not playing any games...</p>}
</div>
</Card>
<Card className="overflow-hidden p-6 md:p-12" >
<h1 className="text-2xl font-bold pb-3">Planning to play</h1>
<div className="grid grid-cols-1 ss:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-4 lg:gap-8 items-center">
{planningGames ? planningGames.map((game: IGame) => (
<GameItem id={game.id} name={game.name} cover={game.cover} key={game.id} />
))
:
<p>Currently not planning to play any games...</p>}
</div>
</Card>
<Card className="overflow-hidden p-6 md:p-12" >
<h1 className="text-2xl font-bold pb-3">Finished Games</h1>
<div className="grid grid-cols-1 ss:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-4 lg:gap-8 items-center">
{finishedGames ? finishedGames.map((game: IGame) => (
<GameItem id={game.id} name={game.name} cover={game.cover} key={game.id} />
))
:
<p>No finished games...</p>}
</div>
</Card>
</div>
}
sideContent={
<Card className="p-6 grid items-start gap-2 bg-secondary">
<h1>Media</h1>
<div className="grid grid-cols-1 gap-4">
{Array.from({ length: 2 }, (_, i) => i + 1).map((i) => {
return (
<Skeleton key={i} className="aspect-[264/374] bg-gray-300" />
)
})}
</div>
</Card>
}
/>
)
}
\ No newline at end of file
import { Card } from "@/components/ui/card"
import { Skeleton } from "@/components/ui/skeleton"
// loading component, this renders when loading in /games happens
export default function Loading() {
return (
<div className="main-content h-full">
<Card className="w-full h-full overflow-hidden">
<div className="h-64 overflow-hidden">
<Skeleton className="bg-slate-600 dark:bg-slate-400" />
</div>
<div className="p-6 md:p-12 ss:flex">
<Skeleton className="h-52 w-52 -mt-36 rounded-full" />
<div className="ml-6 md:ml-12 space-y-3">
<Skeleton className="h-6 w-1/4 bg-gray-400 dark:bg-gray-200" />
<Skeleton className="h-6 w-1/4 bg-sky-500" />
</div>
</div>
<div className="px-6 md:px-12">
{/* <div className="border-b border-gray-400 dark:border-gray-200" /> */}
{/* gweets */}
</div>
</Card >
<div className="side-content">
<Card className="p-6 grid items-start gap-2 bg-secondary">
<Skeleton className="h-6 w-1/4 bg-gray-400 dark:bg-gray-200" />
<div className="grid grid-cols-1 gap-4">
{Array.from({ length: 2 }, (_, i) => i + 1).map((i) => {
return (
<Skeleton key={i} className="aspect-[264/374] bg-gray-300" />
)
})}
</div>
</Card>
</div>
</div >
)
}
\ No newline at end of file
import FollowButton from "@/components/following-button"
import GameItem from "@/components/game-item"
import { AspectRatio } from "@/components/ui/aspect-ratio"
import { Card } from "@/components/ui/card"
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 sessionUser = await db.user.findFirst({
where: {
id: user?.id
},
include: {
following: true,
followers: true
}
})
const fullUser = await db.user.findFirst({
where: {
username: params.userid
},
include: {
following: true,
followers: true
}
})
if (!fullUser) {
redirect('/home')
}
let favoritegames = undefined
let playingGames = undefined
let finishedGames = undefined
let planningGames = undefined
if (fullUser?.favGameList?.length !== 0 && fullUser?.favGameList?.length != undefined) {
favoritegames = await getFavoriteGames(fullUser?.favGameList!)
}
if (fullUser?.playingGameList?.length !== 0) {
playingGames = await getFavoriteGames(fullUser?.playingGameList!)
}
if (fullUser?.finishedGameList?.length !== 0) {
finishedGames = await getFavoriteGames(fullUser?.finishedGameList!)
}
if (fullUser?.planningGameList?.length !== 0) {
planningGames = await getFavoriteGames(fullUser?.planningGameList!)
}
return (
<>
<div className="main-content h-full">
<Card className="w-full h-full overflow-hidden">
<div className="h-64 overflow-hidden">
<AspectRatio ratio={889 / 500} className="bg-slate-600 dark:bg-slate-400">
{/* profile banner */}
{/* <Image
src={ }
alt={ }
fill
priority
className="object-center" /> */}
</AspectRatio>
</div>
<div className="p-6 md:p-12 ss:flex">
<UserAvatar
user={{ username: fullUser.username, image: fullUser.image || null }}
className="h-52 w-52 -mt-36"
/>
<div className="ml-6 md:ml-12 space-y-3">
<h1 className="text-2xl font-bold">{fullUser.name}</h1>
<h1 className="text-md text-sky-500">@{fullUser.username}</h1>
{/* <h1 className="pt-3">{fullUser.bio}</h1> */}
</div>
<div className="flex justify-start ml-6 md:ml-12 space-y-3">
<FollowButton user={sessionUser!} followingId={fullUser?.id!} />
</div>
</div>
<div className="px-6 md:px-12">
{/* <div className="border-b border-gray-400 dark:border-gray-200" /> */}
{/* gweets */}
</div>
</Card >
<div className="side-content">
<Card className="p-6 grid items-start gap-2 bg-secondary">
<h1>Media</h1>
<div className="grid grid-cols-1 gap-4">
{Array.from({ length: 2 }, (_, i) => i + 1).map((i) => {
return (
<Skeleton key={i} className="aspect-[264/374] bg-gray-300" />
)
})}
</div>
</Card>
</div>
</div >
<div className="main-content">
<Card className="w-full h-full overflow-hidden p-6 md:p-12" >
<h1 className="text-2xl font-bold pb-3">Favorite Games</h1>
<div className="grid grid-cols-1 ss:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-4 lg:gap-8 items-center">
{favoritegames ? favoritegames.map((game: IGame) => (
<GameItem id={game.id} name={game.name} cover={game.cover} key={game.id} />
))
:
<p>No favorites currently...</p>}
</div>
</Card>
<Card className="w-full h-full overflow-hidden p-6 md:p-12" >
<h1 className="text-2xl font-bold pb-3">Currently playing</h1>
<div className="grid grid-cols-1 ss:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-4 lg:gap-8 items-center">
{playingGames ? playingGames.map((game: IGame) => (
<GameItem id={game.id} name={game.name} cover={game.cover} key={game.id} />
))
:
<p>Currently not playing any games...</p>}
</div>
</Card>
<Card className="w-full h-full overflow-hidden p-6 md:p-12" >
<h1 className="text-2xl font-bold pb-3">Planning to play</h1>
<div className="grid grid-cols-1 ss:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-4 lg:gap-8 items-center">
{planningGames ? planningGames.map((game: IGame) => (
<GameItem id={game.id} name={game.name} cover={game.cover} key={game.id} />
))
:
<p>Currently not planning to play any games...</p>}
</div>
</Card>
<Card className="w-full h-full overflow-hidden p-6 md:p-12" >
<h1 className="text-2xl font-bold pb-3">Finished Games</h1>
<div className="grid grid-cols-1 ss:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-4 lg:gap-8 items-center">
{finishedGames ? finishedGames.map((game: IGame) => (
<GameItem id={game.id} name={game.name} cover={game.cover} key={game.id} />
))
:
<p>No finished games...</p>}
</div>
</Card>
</div>
</>
)
}
\ No newline at end of file
import { BackHeader } from "@/components/back-header";
import { GweetDetails } from "@/components/gweets/components/gweet-details";
import { Card } from "@/components/ui/card";
import { BackHeader } from "@/components/back-header"
import { GlobalLayout } from "@/components/global-layout"
import { GweetDetails } from "@/components/gweets/components/gweet-details"
import { Card } from "@/components/ui/card"
export default async function GweetDetailPage() {
return (
<Card className="w-full h-full p-3 xl:p-6 ">
<BackHeader>
<h1 className="font-bold">Gweet</h1>
</BackHeader>
<GlobalLayout
mainContent={
<Card className="w-full h-full p-3 xl:p-6 ">
<BackHeader>
<h1 className="font-bold">Gweet</h1>
</BackHeader>
<GweetDetails />
</Card>
);
};
\ No newline at end of file
<GweetDetails />
</Card>
}
/>
)
}
\ No newline at end of file
import { MainNav } from "@/components/header"
import DashboardNav from "@/components/nav"
import SearchInput from "@/components/search-input"
import { SiteFooter } from "@/components/site-footer"
import { UserAccountNav } from "@/components/user-nav"
import { Header } from "@/components/nav-header"
import { Sidebar } from "@/components/nav-sidebar"
import { dashboardConfig } from "@/lib/config/dashboard"
import { getCurrentUser } from "@/lib/session"
......@@ -15,30 +12,17 @@ export default async function ContentLayout({
const user = await getCurrentUser()
return (
<div className="flex min-h-screen flex-col space-y-6">
<header className="sticky top-0 z-50 border-b bg-background">
<div className="container flex h-16 items-center justify-between py-4">
<MainNav />
<SearchInput className="p-3 md:w-2/3 2xl:w-1/3" />
{user && <UserAccountNav
user={{
name: user?.name,
image: user?.image,
username: user?.username,
}}
/>}
{!user && <p className="w-8"></p>}
</div>
</header>
<div className="container grid flex-1 gap-12 md:grid-cols-[200px_1fr]">
<aside className="hidden w-[200px] flex-col md:flex">
<DashboardNav items={dashboardConfig.sidebarNav} />
<main className="flex min-h-screen flex-col space-y-6 align-middle">
<Header user={user} />
<div className="container grid flex-1 gap-12 grid-cols-5">
<aside className="self-start sticky top-[89px] col-span-1">
<Sidebar items={dashboardConfig.sidebarNav} user={user} />
</aside>
<main className="flex w-full flex-1 flex-col overflow-hidden">
<div className="flex flex-1 flex-col w-full h-full col-span-4 pb-6">
{children}
</main>
</div>
</div>
<SiteFooter className="border-t" />
</div>
</main>
)
}
\ No newline at end of file
......@@ -4,4 +4,3 @@ import NextAuth from 'next-auth'
const handler = NextAuth(authOptions)
export { handler as GET, handler as POST }
import { db } from "@/lib/db";
import { getCurrentUser } from "@/lib/session";
import { User } from "@prisma/client";
import { revalidatePath } from "next/cache";
import { NextRequest, NextResponse } from "next/server";
import { db } from "@/lib/db"
import { getCurrentUser } from "@/lib/session"
import { revalidatePath } from "next/cache"
import { NextRequest, NextResponse } from "next/server"
export async function GET(req: NextRequest) {
const sessionUser = await getCurrentUser();
const sessionUser = await getCurrentUser()
if (!sessionUser) {
return NextResponse.json({ status: 401, message: 'Unauthorized' });
return NextResponse.json({ status: 401, message: 'Unauthorized' })
}
let follows = undefined;
let follows = undefined
try {
follows = await db.follows.findMany({
where: {
followerId: sessionUser.id
}
});
})
} catch (error) {
console.log("error", error)
}
......@@ -26,12 +25,12 @@ export async function GET(req: NextRequest) {
}
export async function PUT(req: NextRequest) {
const sessionUser = await getCurrentUser();
const sessionUser = await getCurrentUser()
const data = await req.json()
if (!sessionUser) {
return NextResponse.json({ status: 401, message: 'Unauthorized' });
return NextResponse.json({ status: 401, message: 'Unauthorized' })
}
try {
......@@ -39,14 +38,14 @@ export async function PUT(req: NextRequest) {
where: {
id: sessionUser.id
}
});
})
const follow = await db.follows.findFirst({
where: {
followerId: sessionUser.id,
followingId: data.followingId
}
});
})
console.log("follow", follow)
if (follow) {
......@@ -70,16 +69,14 @@ export async function PUT(req: NextRequest) {
followerId: sessionUser.id,
followingId: data.followingId
},
});
})
}
} catch (error) {
console.log("err", error)
}
const path = req.nextUrl.searchParams.get('path') || '/';
revalidatePath(path);
const path = req.nextUrl.searchParams.get('path') || '/'
revalidatePath(path)
return NextResponse.json({ status: 200, message: 'Follow handled' })
}
\ No newline at end of file
import { db } from "@/lib/db";
import { getCurrentUser } from "@/lib/session";
import { User } from "@prisma/client";
import { revalidatePath } from "next/cache";
import { NextRequest, NextResponse } from "next/server";
import { db } from "@/lib/db"
import { getCurrentUser } from "@/lib/session"
import { User } from "@prisma/client"
import { revalidatePath } from "next/cache"
import { NextRequest, NextResponse } from "next/server"
export async function PUT(req: NextRequest) {
const sessionUser = await getCurrentUser();
const sessionUser = await getCurrentUser()
const data: User = await req.json()
console.log("userid", sessionUser!.id, "formdataid", data.id)
if (!sessionUser || sessionUser.id != data.id) {
return NextResponse.json({ status: 401, message: 'Unauthorized' });
return NextResponse.json({ status: 401, message: 'Unauthorized' })
}
console.log("put list")
try {
......@@ -23,7 +23,7 @@ export async function PUT(req: NextRequest) {
playingGameList: true,
finishedGameList: true
},
});
})
if (dbUser) {
if (!data.finishedGameList) data.finishedGameList = dbUser?.finishedGameList
......@@ -44,10 +44,8 @@ export async function PUT(req: NextRequest) {
} catch (error) {
}
const path = req.nextUrl.searchParams.get('path') || '/';
revalidatePath(path);
const path = req.nextUrl.searchParams.get('path') || '/'
revalidatePath(path)
return NextResponse.json({ status: 201, message: 'Game Hinzugefügt' })
}
\ No newline at end of file
import { platforms } from "@/lib/config/platform";
import { getGames } from "@/lib/igdb";
import { EGameCategory, EGameGenres, EGamePlatform } from "@/types/constants";
import { IPlatformCategrory } from "@/types/igdb-types";
import { platforms } from "@/lib/config/platform"
import { getGames } from "@/lib/igdb"
import { EGameCategory, EGameGenres, EGamePlatform } from "@/types/constants"
import { IPlatformCategrory } from "@/types/igdb-types"
import { NextRequest, NextResponse } from "next/server";
import { NextRequest, NextResponse } from "next/server"
export async function GET(req: NextRequest) {
const p = req.nextUrl.searchParams;
const p = req.nextUrl.searchParams
try {
const page = parseInt(p.get('page') as string)
......@@ -17,16 +17,16 @@ export async function GET(req: NextRequest) {
const sortby = p.get('sortby')
const order = p.get('order')
let filteredPlatforms: EGamePlatform[] | undefined;
let filteredPlatforms: EGamePlatform[] | undefined
if (platform) {
const selectedCategory = platforms.find(
(platformCategory: IPlatformCategrory) =>
platformCategory.category === platform
);
)
filteredPlatforms = selectedCategory
? selectedCategory.platforms
: undefined;
: undefined
}
const games = await getGames(page,
......@@ -36,9 +36,9 @@ export async function GET(req: NextRequest) {
filteredPlatforms,
sortby ? sortby : undefined,
order ? order : undefined
);
return NextResponse.json(games);
)
return NextResponse.json(games)
} catch (error) {
return NextResponse.json(error, { status: 500 });
return NextResponse.json(error, { status: 500 })
}
}
\ No newline at end of file
import { NextResponse } from "next/server";
import { z } from "zod";
import { NextResponse } from "next/server"
import { z } from "zod"
import { db } from "@/lib/db";
import { db } from "@/lib/db"
// get a single gweet
export async function GET(request: Request, { params }: { params: { id: string } }) {
const { id } = params;
const { id } = params
const gweetIdSchema = z.string().cuid();
const gweetIdSchema = z.string().cuid()
const zod = gweetIdSchema.safeParse(id);
const zod = gweetIdSchema.safeParse(id)
if (!zod.success) {
return NextResponse.json(
{
message: "Invalid request body",
error: zod.error.formErrors,
}, { status: 400 },
);
}
if (!zod.success) {
return NextResponse.json(
{
message: "Invalid request body",
error: zod.error.formErrors,
}, { status: 400 },
)
}
try {
const gweet = await db.gweet.findUnique({
where: {
id,
},
include: {
author: true,
likes: {
include: {
user: {
include: {
followers: true,
},
},
},
orderBy: {
createdAt: "desc",
},
},
media: true,
regweets: {
include: {
user: {
include: {
followers: true,
},
try {
const gweet = await db.gweet.findUnique({
where: {
id,
},
},
orderBy: {
createdAt: "desc",
},
},
quote: {
include: {
author: true,
media: true,
},
},
allQuotes: {
include: {
likes: true,
regweets: true,
author: true,
quote: {
include: {
author: true,
},
include: {
author: {
select: {
id: true,
username: true,
name: true,
image: true,
},
},
likes: {
include: {
user: {
include: {
followers: true,
},
},
},
orderBy: {
createdAt: "desc",
},
},
media: true,
regweets: {
include: {
user: {
include: {
followers: true,
},
},
},
orderBy: {
createdAt: "desc",
},
},
quote: {
include: {
author: true,
media: true,
},
},
allQuotes: {
include: {
likes: true,
regweets: true,
author: true,
quote: {
include: {
author: true,
},
},
},
orderBy: {
createdAt: "desc",
},
},
comment: {
include: {
author: {
select: {
id: true,
username: true,
},
},
},
},
allComments: true,
},
},
})
orderBy: {
createdAt: "desc",
},
},
allComments: true,
},
});
if (!gweet) {
return NextResponse.json(
{
message: "Gweet not found",
}, { status: 404 },
)
}
if (!gweet) {
return NextResponse.json(
{
message: "Gweet not found",
}, { status: 404 },
);
return NextResponse.json(gweet, { status: 200 })
} catch (error) {
return NextResponse.json(
{
message: "Something went wrong",
error,
}, { status: 500 },
)
}
return NextResponse.json(gweet, { status: 200 });
} catch (error) {
return NextResponse.json(
{
message: "Something went wrong",
error,
}, { status: 500 },
);
}
}
}
\ No newline at end of file
import { NextResponse } from "next/server";
import { z } from "zod";
import { NextResponse } from "next/server"
import { z } from "zod"
import { db } from "@/lib/db";
import { db } from "@/lib/db"
// get likes from user
export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const user_id = searchParams.get("user_id") || undefined;
const { searchParams } = new URL(request.url)
const user_id = searchParams.get("user_id") || undefined
const userIdSchema = z.string().cuid();
const zod = userIdSchema.safeParse(user_id);
const userIdSchema = z.string().cuid()
const zod = userIdSchema.safeParse(user_id)
if (!zod.success) {
return NextResponse.json(
{
message: "Invalid request body",
error: zod.error.formErrors,
}, { status: 400 },
);
}
if (!zod.success) {
return NextResponse.json(
{
message: "Invalid request body",
error: zod.error.formErrors,
}, { status: 400 },
)
}
try {
const gweets = await db.gweet.findMany({
where: {
likes: {
some: {
userId: user_id,
},
},
},
try {
const gweets = await db.gweet.findMany({
where: {
likes: {
some: {
userId: user_id,
},
},
},
include: {
author: true,
media: true,
likes: true,
regweets: true,
allComments: true,
},
});
include: {
author: true,
media: true,
likes: true,
regweets: true,
allComments: true,
},
})
return NextResponse.json(gweets, { status: 200 });
} catch (error: any) {
return NextResponse.json(
{
message: "Something went wrong",
error: error.message,
}, { status: error.errorCode || 500 },
);
}
return NextResponse.json(gweets, { status: 200 })
} catch (error: any) {
return NextResponse.json(
{
message: "Something went wrong",
error: error.message,
}, { status: error.errorCode || 500 },
)
}
}
// like and dislike
export async function POST(request: Request) {
const { gweet_id, user_id } = await request.json();
const { gweet_id, user_id } = await request.json()
const likeSchema = z
.object({
gweet_id: z.string().cuid(),
user_id: z.string().cuid(),
})
.strict();
const likeSchema = z
.object({
gweet_id: z.string().cuid(),
user_id: z.string().cuid(),
})
.strict()
const zod = likeSchema.safeParse({ gweet_id, user_id });
const zod = likeSchema.safeParse({ gweet_id, user_id })
if (!zod.success) {
return NextResponse.json(
{
message: "Invalid request body",
error: zod.error.formErrors,
}, { status: 400 },
);
}
if (!zod.success) {
return NextResponse.json(
{
message: "Invalid request body",
error: zod.error.formErrors,
}, { status: 400 },
)
}
try {
const like = await db.like.findFirst({
where: {
gweetId: gweet_id,
userId: user_id,
},
});
try {
const like = await db.like.findFirst({
where: {
gweetId: gweet_id,
userId: user_id,
},
})
if (like) {
await db.like.delete({
where: {
id: like.id,
},
});
if (like) {
await db.like.delete({
where: {
id: like.id,
},
})
return NextResponse.json({ message: "Gweet unliked" });
} else {
await db.like.create({
data: {
gweetId: gweet_id,
userId: user_id,
},
});
return NextResponse.json({ message: "Gweet unliked" })
} else {
await db.like.create({
data: {
gweetId: gweet_id,
userId: user_id,
},
})
return NextResponse.json({ message: "Gweet liked" });
return NextResponse.json({ message: "Gweet liked" })
}
} catch (error: any) {
return NextResponse.json({
message: "Something went wrong",
error: error.message,
})
}
} catch (error: any) {
return NextResponse.json({
message: "Something went wrong",
error: error.message,
});
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment