From 149a86214dbbb253719049496af0355db3b057e3 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Tue, 29 Jul 2025 01:42:39 +0200 Subject: [PATCH] Move prisma calls to server side --- README.md | 6 ++-- app/api/profiles/route.ts | 5 ++-- app/profiles/page.tsx | 60 ++++++++++++++++++++++++--------------- 3 files changed, 44 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index c8b6c1a2..426efb9a 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,9 @@ To contribute, please submit a pull request or issue, or fill out this [form](ht ## To Do - [x] Authentication (user/password and Google Sign In) -- [ ] Set up PostgreSQL in Production with supabase (can stick with SQLite in dev / local) -- [ ] Set up domain name and hosting (vercel?) +- [x] Set up PostgreSQL in Production with supabase (can stick with SQLite in dev / local) +- [ ] Set up hosting (vercel) +- [ ] Set up domain name and - [ ] Ask for detailed info per profile upon registration (intellectual interests, location, cause areas, personality type, conflict style, desired type of connection, prompt answers, gender, etc.) - [ ] Set up page listing all the profiles - [ ] Search through all the profile variables @@ -26,6 +27,7 @@ Any action item is open to anyone for collaboration, but the following ones are - [ ] Clean up privacy notice - [ ] Clean up learn more page - [ ] Add dark theme +- [ ] Cover with tests ## Implementation diff --git a/app/api/profiles/route.ts b/app/api/profiles/route.ts index ab770cfd..0415f11a 100644 --- a/app/api/profiles/route.ts +++ b/app/api/profiles/route.ts @@ -4,7 +4,7 @@ import { NextResponse } from "next/server"; export async function GET(request: Request) { const url = new URL(request.url); const page = parseInt(url.searchParams.get("page") || "1"); - const profilesPerPage = 5; + const profilesPerPage = 20; const offset = (page - 1) * profilesPerPage; // Fetch paginated posts @@ -18,5 +18,6 @@ export async function GET(request: Request) { const totalProfiles = await prisma.user.count(); const totalPages = Math.ceil(totalProfiles / profilesPerPage); - return NextResponse.json({ posts: profiles, totalPages }); + console.log({ profiles, totalPages }); + return NextResponse.json({ profiles, totalPages }); } diff --git a/app/profiles/page.tsx b/app/profiles/page.tsx index d28a9239..c15bd305 100644 --- a/app/profiles/page.tsx +++ b/app/profiles/page.tsx @@ -1,35 +1,49 @@ -import {redirect} from "next/navigation"; +'use client'; + import Link from "next/link"; -import { prisma }from "@/lib/prisma"; -import {checkUserTableExists} from "@/lib/db-utils"; +import {useEffect, useState} from "react"; +import {notFound} from "next/navigation"; // Disable static generation export const dynamic = "force-dynamic"; +type Profile = { + id: string; + name: string; + createdAt: string; +}; -export default async function PostsPage() { - // Check if the post table exists - const tableExists = await checkUserTableExists(); - // If the post table doesn't exist, redirect to setup page - if (!tableExists) { - redirect("/setup"); - } +export default function ProfilePage() { - const profiles = await prisma.user.findMany({ - orderBy: { - createdAt: "desc", - }, - // take: 20, - // include: { - // author: { - // select: { - // name: true, - // }, - // }, - // }, - }); + const [profiles, setProfiles] = useState([]); + + + useEffect(() => { + const fetchProfile = async () => { + try { + const response = await fetch('/api/profiles'); + console.log(response) + + const data = await response.json(); + console.log(data) + + if (!response.ok) { + throw new Error(data.error || 'Failure'); + } + + const p = data['profiles']; + setProfiles(p); + } catch (error) { + console.error('Upload error:', error); + } + }; + + fetchProfile(); + }, []); + + if (!profiles) return

Loading...

; return (