From 1ed0fc3605ccef798077e67763db010304f273de Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Yusuf=20Akg=C3=BCl?= <s86116@bht-berlin.de>
Date: Thu, 1 Jun 2023 00:31:09 +0200
Subject: [PATCH] merge fix

---
 app/(content)/followers/page.tsx |  2 +-
 components/filter-sort-games.tsx | 18 ++++-----
 components/following-button.tsx  | 69 ++++++++++++++++----------------
 components/following-users.tsx   | 35 ++++++++--------
 4 files changed, 63 insertions(+), 61 deletions(-)

diff --git a/app/(content)/followers/page.tsx b/app/(content)/followers/page.tsx
index 7d8778f..7fbb300 100644
--- a/app/(content)/followers/page.tsx
+++ b/app/(content)/followers/page.tsx
@@ -12,7 +12,7 @@ export default async function Followers() {
     return (
         <div>
             <h1>Followers Page WIP</h1>
-            <FollowersList userId={session.user?.id} />
+            <FollowersList userId={parseFloat(session.user?.id)} />
         </div>
     )
 }
\ No newline at end of file
diff --git a/components/filter-sort-games.tsx b/components/filter-sort-games.tsx
index b7a736d..caa9c36 100644
--- a/components/filter-sort-games.tsx
+++ b/components/filter-sort-games.tsx
@@ -2,7 +2,7 @@
 
 import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue } from "@/components/ui/select";
 import { usePathname, useRouter, useSearchParams } from "next/navigation";
-import { useLayoutEffect, useState } from "react";
+import { useEffect, useState } from "react";
 import { Icons } from "./icons";
 import { Button } from "./ui/button";
 import { Card } from "./ui/card";
@@ -25,8 +25,8 @@ export default function Sort() {
     category: selectedCategory ? `category=${selectedCategory}` : '',
     genre: selectedGenre ? `genre=${selectedGenre}` : '',
     platform: selectedPlatform ? `platform=${selectedPlatform}` : '',
-    sortMethod: selectedSortMethod == 'total_rating_count' ? '' : `sortby=${selectedSortMethod}`,
-    sortOrder: selectedSortOrder == 'desc' ? '' : `order=${selectedSortOrder}`,
+    sortMethod: selectedSortMethod ? `sortby=${selectedSortMethod}` : '',
+    sortOrder: selectedSortOrder ? `order=${selectedSortOrder}` : '',
   };
 
   const queryParamString = Object.values(urlParams)
@@ -36,11 +36,11 @@ export default function Sort() {
 
   const url = `${pathname}${queryParamString ? `${queryParamString}` : ''}`;
 
-  useLayoutEffect(() => {
-    if (queryParamString) {
-      router.replace(url);
-    }
-  }, [queryParamString, router, url]);
+  // useEffect(() => {
+  //   if (queryParamString) {
+  router.replace(url);
+  //   }
+  // }, [queryParamString, router, url]);
 
   function toggleSortOrder() {
     const newSortOrder = selectedSortOrder === 'desc' ? 'asc' : 'desc';
@@ -137,7 +137,7 @@ export default function Sort() {
             </SelectGroup>
           </SelectContent>
         </Select>
-        <Button variant="ghost" onClick={() => toggleSortOrder}>
+        <Button variant="ghost" onClick={() => toggleSortOrder()}>
           <Icons.arrowdown className={`h-4 w-4 transition-all transform ${selectedSortOrder === 'asc' ? 'rotate-180' : ''}`} />
         </Button>
       </div>
diff --git a/components/following-button.tsx b/components/following-button.tsx
index af3f477..420ecdc 100644
--- a/components/following-button.tsx
+++ b/components/following-button.tsx
@@ -1,49 +1,50 @@
 "use client"
 
-import { PrismaClient } from '@prisma/client';
+// import { PrismaClient } from '@prisma/client';
 import { useState } from 'react';
 import { Button } from './ui/button';
 
-const prisma = new PrismaClient();
+// Muss in die API route
+// const prisma = new PrismaClient();
 
-async function getFollower(userId: number, followerId: number) {
-  const follower = await prisma.follows.findFirst({
-    where: {
-      followerId: followerId,
-      followingId: userId,
-    },
-  });
+// async function getFollower(userId: number, followerId: number) {
+//   const follower = await prisma.follows.findFirst({
+//     where: {
+//       followerId: followerId,
+//       followingId: userId,
+//     },
+//   });
 
-  return follower;
-}
+//   return follower;
+// }
 
 export default function FollowButton({ userId, followerId }: { userId: number; followerId: number }) {
   const [isFollowing, setIsFollowing] = useState(false);
 
   const handleFollow = async () => {
-    const follower = await getFollower(userId, followerId);
-
-    if (follower) {
-      // User is already following, so unfollow
-      await prisma.follows.delete({
-        where: {
-          followerId_followingId: {
-            followerId: followerId,
-            followingId: userId,
-          },
-        },
-      });
-      setIsFollowing(false);
-    } else {
-      // User is not following, so follow
-      await prisma.follows.create({
-        data: {
-          followerId: followerId,
-          followingId: userId,
-        },
-      });
-      setIsFollowing(true);
-    }
+    // const follower = await getFollower(userId, followerId);
+
+    // if (follower) {
+    //   // User is already following, so unfollow
+    //   await prisma.follows.delete({
+    //     where: {
+    //       followerId_followingId: {
+    //         followerId: followerId,
+    //         followingId: userId,
+    //       },
+    //     },
+    //   });
+    //   setIsFollowing(false);
+    // } else {
+    //   // User is not following, so follow
+    //   await prisma.follows.create({
+    //     data: {
+    //       followerId: followerId,
+    //       followingId: userId,
+    //     },
+    //   });
+    //   setIsFollowing(true);
+    // }
   };
 
   return (
diff --git a/components/following-users.tsx b/components/following-users.tsx
index be7c652..44408c1 100644
--- a/components/following-users.tsx
+++ b/components/following-users.tsx
@@ -1,9 +1,10 @@
 "use client"
 
-import { PrismaClient } from '@prisma/client';
+// import { PrismaClient } from '@prisma/client';
 import { useEffect, useState } from 'react';
 
-const prisma = new PrismaClient();
+// Muss in die API route
+// const prisma = new PrismaClient();
 
 interface Follower {
   id: number;
@@ -16,21 +17,21 @@ export default function FollowersList({ userId }: { userId: number }) {
 
   useEffect(() => {
     async function fetchFollowers() {
-      const followersList = await prisma.follows.findMany({
-        where: {
-          followingId: userId,
-        },
-        include: {
-          follower: true,
-        },
-      });
-
-      const filteredFollowers = followersList.map((follow) => {
-        const { id, name, email } = follow.follower;
-        return { id, name: name ?? "", email };
-      });
-
-      setFollowers(filteredFollowers);
+      // const followersList = await prisma.follows.findMany({
+      //   where: {
+      //     followingId: userId,
+      //   },
+      //   include: {
+      //     follower: true,
+      //   },
+      // });
+
+      // const filteredFollowers = followersList.map((follow: any) => {
+      //   const { id, name, email } = follow.follower;
+      //   return { id, name: name ?? "", email };
+      // });
+
+      // setFollowers(filteredFollowers);
     }
 
     fetchFollowers();
-- 
GitLab