diff --git a/app/(root)/adt/[id]/page.tsx b/app/(root)/adt/[id]/page.tsx index 205b5ad..0b709e0 100644 --- a/app/(root)/adt/[id]/page.tsx +++ b/app/(root)/adt/[id]/page.tsx @@ -1,15 +1,19 @@ +// "use client" + import React from 'react'; // import { useParams } from 'next/navigation'; import { MapPin, Calendar, Phone, MessageCircle, Share2, Flag, Heart } from 'lucide-react'; import { prisma } from '@/prisma/prisma-client'; import { notFound } from 'next/navigation'; +import { ShowNumberModal } from '@/components/shared/modals/show-number'; type Params = Promise<{ id: string }> export default async function AdtPage(props: { params: Params }) { + // const [ openShowNumberModal, setOpenShowNumberModal ] = React.useState(false) const params = await props.params; - const adt = await prisma.adt.findUnique({ + const adt = await prisma.adt.findFirst({ where: { id: Number(params.id), }, @@ -29,6 +33,7 @@ export default async function AdtPage(props: { params: Params }) { return ( <> + {/* setOpenShowNumberModal(false)} /> */}
@@ -54,8 +59,7 @@ export default async function AdtPage(props: { params: Params }) {

Description

- This is a detailed description of the listing. It includes all the important information - about the item, its condition, and any special features or considerations. + {adt.description}

@@ -87,9 +91,10 @@ export default async function AdtPage(props: { params: Params }) {
- {/* TODO всплывающее окно для показа номера */} - - diff --git a/app/(root)/page.tsx b/app/(root)/page.tsx index 81b0295..aabd2dc 100644 --- a/app/(root)/page.tsx +++ b/app/(root)/page.tsx @@ -2,11 +2,26 @@ import Categories from "@/components/Categories"; import ListingCard from "@/components/ListingCard"; +import { getUserSession } from "@/lib/get-user-session"; import { prisma } from "@/prisma/prisma-client"; export default async function Home() { const adts = await prisma.adt.findMany() + const session = await getUserSession() + // if (!session) { + // return redirect('/not-auth') + // } + + // const user = await prisma.user.findFirst({ + // where: { + // id: Number(session?.id) + // } + // }) + + // console.log(user) + console.log("session",session) + return ( <>
diff --git a/app/api/adt/route.ts b/app/api/adt/route.ts index 9d62885..1f580c8 100644 --- a/app/api/adt/route.ts +++ b/app/api/adt/route.ts @@ -5,6 +5,63 @@ import { getUserSession } from '@/lib/get-user-session'; const prisma = new PrismaClient(); + +// GET функция для получения списка объявлений с пагинацией +export async function GET(request: Request) { + try { + // Получаем параметры из URL + const { searchParams } = new URL(request.url); + + // Параметры пагинации (по умолчанию: страница 1, 10 элементов на странице) + const page = Number(searchParams.get('page')) || 1; + const limit = Number(searchParams.get('limit')) || 10; + const skip = (page - 1) * limit; + + // Получаем общее количество объявлений для пагинации + const total = await prisma.adt.count(); + + // Получаем объявления с учетом пагинации + const adts = await prisma.adt.findMany({ + skip, + take: limit, + include: { + categories: true, + user: { + select: { + id: true, + name: true, + email: true + } + } + }, + orderBy: { + createdAt: 'desc' // Сортировка по дате создания (новые первыми) + } + }); + + // Формируем метаданные для пагинации + const meta = { + currentPage: page, + itemsPerPage: limit, + totalItems: total, + totalPages: Math.ceil(total / limit) + }; + + return NextResponse.json({ + data: adts, + meta + }); + + } catch (error) { + console.error('Error fetching adts:', error); + return NextResponse.json( + { error: 'Ошибка при получении объявлений' }, + { status: 500 } + ); + } +} + + export async function POST(request: Request) { try { const session = await getUserSession(); diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts index c447fa0..9918f43 100644 --- a/app/api/auth/[...nextauth]/route.ts +++ b/app/api/auth/[...nextauth]/route.ts @@ -1,7 +1,7 @@ import NextAuth from "next-auth" import { authOptions } from "@/constants/auth-options" -const handler = NextAuth(authOptions) +export const handler = NextAuth(authOptions) // Экспортируем напрямую функции GET и POST, без промежуточной переменной export const GET = handler diff --git a/components/Header.tsx b/components/Header.tsx index 967aa4b..b1c9a01 100644 --- a/components/Header.tsx +++ b/components/Header.tsx @@ -1,4 +1,4 @@ -"use client" +"use client" import React from 'react'; import { Search, PlusCircle, Bell, User } from 'lucide-react'; import Link from 'next/link'; @@ -9,19 +9,21 @@ import { AuthModal } from './shared/modals/auth-modal/auth-modal'; export default function Header() { const [openAuthModal, setOpenAuthModal] = React.useState(false) + const [mobileSearchOpen, setMobileSearchOpen] = React.useState(false) return (
-
+
- - MarketSpot + + Bazar
-
-
+ {/* Desktop Search */} +
+
-
+ {/* Mobile Actions */} +
+ + - - Post Ad + -
+ + {/* Desktop Navigation */} +
+ + + + {/* + */} setOpenAuthModal(false)} /> setOpenAuthModal(true)} /> - - {/* - - */}
+ + {/* Mobile Search */} + {mobileSearchOpen && ( +
+
+ + +
+
+ )}
); diff --git a/components/shared/modals/auth-modal/forms/login-form.tsx b/components/shared/modals/auth-modal/forms/login-form.tsx index 6fc8561..116df32 100644 --- a/components/shared/modals/auth-modal/forms/login-form.tsx +++ b/components/shared/modals/auth-modal/forms/login-form.tsx @@ -31,8 +31,6 @@ export const LoginForm: React.FC = ({onClose}) => { throw Error(); } - - onClose?.() } catch (error) { console.error('Error [LOGIN]', error) diff --git a/components/shared/modals/show-number.tsx b/components/shared/modals/show-number.tsx new file mode 100644 index 0000000..b5e6889 --- /dev/null +++ b/components/shared/modals/show-number.tsx @@ -0,0 +1,45 @@ +import { Dialog } from "@/components/ui/dialog"; +import { getUserSession } from "@/lib/get-user-session"; +import React from "react"; + +interface Props { + open: boolean; + onClose: () => void; +} + +export const ShowNumberModal: React.FC = ({ open, onClose}) => { + + const [ session, setSession ] = React.useState(null) + + React.useEffect(() => { + const getSession = async () => { + const userSession = await getUserSession() + setSession(userSession) + } + getSession() + }, []) + // const session = await getUserSession() + // const handleClose = () => { + // onClose() + // } + + return ( + + {/* */} + {/* { + // session && ( + //

892348924823

+ // ) + } */} + + {/*

892348924823

*/} +
+
+ + +
+ {/*
*/} + +
+ ) +} \ No newline at end of file diff --git a/constants/auth-options.ts b/constants/auth-options.ts index c09f912..8ffd801 100644 --- a/constants/auth-options.ts +++ b/constants/auth-options.ts @@ -22,7 +22,7 @@ export const authOptions: AuthOptions = { } }), CredentialsProvider({ - name: 'Credentials', + name: 'credentials', credentials: { email: {label: 'Email', type: 'text'}, password: {label: 'Password', type: 'password'}, @@ -71,7 +71,7 @@ export const authOptions: AuthOptions = { callbacks: { async signIn({ user, account}) { try { - if (account?.provaider === 'credentials') { + if (account?.provider === 'credentials') { return true } diff --git a/package.json b/package.json index 6595073..faa8eba 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "prisma:push": "prisma db push", "prisma:studio": "prisma studio", "prisma:seed": "prisma db seed", - "postinstall": "prisma generate" + "postinstall": "" }, "prisma": { "seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts"