From b63e3ae77fa6e171e18eae62d65e0b66f23f0fb8 Mon Sep 17 00:00:00 2001 From: zaremate <0.zaremate@gmail.com> Date: Fri, 9 May 2025 08:55:45 +0000 Subject: [PATCH] revert 99397e774c41980ef13b3155e13330ad4eaa7753 revert WIP: implement public file visibility feature and enhance search functionality --- prisma/schema.prisma | 13 ++- src/app/_components/ActionButtons.tsx | 47 +-------- src/app/_components/FileGrid.tsx | 4 +- src/app/api/files/search/route.ts | 25 ----- src/app/api/files/share/route.ts | 1 - src/app/api/files/update-public/route.ts | 22 ----- src/app/page.tsx | 45 +++------ src/app/search/page.tsx | 121 ----------------------- src/app/share/page.tsx | 3 - tailwind.config.ts | 6 ++ 10 files changed, 33 insertions(+), 254 deletions(-) delete mode 100644 src/app/api/files/search/route.ts delete mode 100644 src/app/api/files/update-public/route.ts delete mode 100644 src/app/search/page.tsx create mode 100644 tailwind.config.ts diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 80636c9..97f9ba3 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -15,6 +15,17 @@ datasource db { url = env("DATABASE_URL") } +model Post { + id Int @id @default(autoincrement()) + name String + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + createdBy User @relation(fields: [createdById], references: [id]) + createdById String + + @@index([name]) +} // Necessary for Next auth model Account { @@ -52,6 +63,7 @@ model User { image String? accounts Account[] sessions Session[] + posts Post[] files File[] // Relation to the File model } @@ -73,5 +85,4 @@ model File { description String @default("") uploadedBy User? @relation(fields: [uploadedById], references: [id], onDelete: SetNull) uploadedById String? - public Boolean @default(false) // Indicates if the file is public or private } diff --git a/src/app/_components/ActionButtons.tsx b/src/app/_components/ActionButtons.tsx index 2253ca9..fc975ab 100644 --- a/src/app/_components/ActionButtons.tsx +++ b/src/app/_components/ActionButtons.tsx @@ -1,4 +1,4 @@ -"use client"; +'use client'; import { useRef, useState } from "react"; import { useFileActions } from "~/app/_components/FileActions"; @@ -7,13 +7,11 @@ export function FileActionsContainer({ fileName, fileUrl, isOwner, - isPublic, }: { fileId: string; fileName: string; fileUrl: string; isOwner: boolean; - isPublic: boolean; }) { const { handleDownload, handleCopyUrl, handleRemove} = useFileActions(() => fileId, (description: string) => { if (isOwner) { @@ -38,55 +36,14 @@ export function FileActionsContainer({ > Copy URL + {/* Remove Button */} - {isOwner && ( - )} - {isOwner && ( -
- - -
- )} ); } diff --git a/src/app/_components/FileGrid.tsx b/src/app/_components/FileGrid.tsx index 091566f..e98bc9b 100644 --- a/src/app/_components/FileGrid.tsx +++ b/src/app/_components/FileGrid.tsx @@ -15,7 +15,6 @@ interface FileDetails { description: string; extension: string; isOwner: boolean; // Indicates if the user owns the file - isPublic: boolean; // Indicates if the file is public } interface FileGridProps { @@ -117,8 +116,7 @@ export default function FileGrid({ session }: FileGridProps) { fileId={file.id} fileName={file.name} fileUrl={file.url} - isOwner={true} - isPublic={file.isPublic} + isOwner={file.isOwner} /> diff --git a/src/app/api/files/search/route.ts b/src/app/api/files/search/route.ts deleted file mode 100644 index d1c4144..0000000 --- a/src/app/api/files/search/route.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { NextResponse } from "next/server"; -import { db } from "~/server/db"; - -export async function GET(req: Request) { - const url = new URL(req.url); - const query = url.searchParams.get("query") || ""; - - try { - // if query is empty, return no files - const files = await db.file.findMany({ - where: { - OR: [ - { name: { contains: query } }, - { description: { contains: query } }, - ], - public: true, - }, - }); - - return NextResponse.json({ files }); - } catch (error) { - console.error("Error fetching files:", error); - return NextResponse.json({ error: "Failed to fetch files" }, { status: 500 }); - } -} \ No newline at end of file diff --git a/src/app/api/files/share/route.ts b/src/app/api/files/share/route.ts index fd7f25e..6b92650 100644 --- a/src/app/api/files/share/route.ts +++ b/src/app/api/files/share/route.ts @@ -32,7 +32,6 @@ export async function GET(req: Request) { type: file.extension, url: file.url, description: file.description, - isPublic: file.public, // Ensure this is included }); } catch (error) { console.error("Error fetching file details:", error); diff --git a/src/app/api/files/update-public/route.ts b/src/app/api/files/update-public/route.ts deleted file mode 100644 index 7d675e0..0000000 --- a/src/app/api/files/update-public/route.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { NextResponse } from "next/server"; -import { db } from "~/server/db"; - -export async function POST(req: Request) { - try { - const { fileId, isPublic } = await req.json(); - - if (!fileId) { - return NextResponse.json({ error: "File ID is required" }, { status: 400 }); - } - - await db.file.update({ - where: { id: fileId }, - data: { public: isPublic }, - }); - - return NextResponse.json({ success: true }); - } catch (error) { - console.error("Error updating public status:", error); - return NextResponse.json({ error: "Failed to update public status" }, { status: 500 }); - } -} \ No newline at end of file diff --git a/src/app/page.tsx b/src/app/page.tsx index 534bb04..37629a1 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -8,35 +8,14 @@ import { Toaster } from "react-hot-toast"; export default async function Home() { const session = await auth(); + return (
{/* Top-right corner sign-out button */} {session?.user && ( -
- {/* Search Button */} - - - - - - +
- + ) : (

@@ -62,16 +41,16 @@ export default async function Home() {

)} {!session?.user && ( -
-
- - {session ? "Sign out" : "Sign in"} - -
+
+
+ + {session ? "Sign out" : "Sign in"} +
+
)}
diff --git a/src/app/search/page.tsx b/src/app/search/page.tsx deleted file mode 100644 index a778de6..0000000 --- a/src/app/search/page.tsx +++ /dev/null @@ -1,121 +0,0 @@ -"use client"; -import { useEffect, useState } from "react"; -import { useRouter } from "next/navigation"; -import { env } from "~/env.js"; -import { FilePreview } from "~/app/_components/FilePreview"; -import { FileActionsContainer } from "~/app/_components/ActionButtons"; -import { HomeButton } from "~/app/_components/HomeButton"; - -interface FileDetails { - name: string; - size: number; - owner: string; - ownerAvatar: string | null; - uploadDate: string; - id: string; - isOwner: boolean; - extension: string; - url: string; - description: string; - isPublic: boolean; -} - -export default function SearchFile() { - const [searchQuery, setSearchQuery] = useState(""); - const [files, setFiles] = useState([]); - const [error, setError] = useState(null); - const pageUrl = env.NEXT_PUBLIC_PAGE_URL; - const router = useRouter(); - - useEffect(() => { - const fetchFiles = async () => { - try { - const response = await fetch( - `/api/files/search?query=${encodeURIComponent(searchQuery)}` - ); - if (!response.ok) { - throw new Error("Failed to fetch files"); - } - const data = await response.json(); - setFiles(data.files); - } catch (err) { - console.error(err); - setError("Failed to load files."); - } - }; - - fetchFiles(); - }, [searchQuery]); - - return ( -
-
- -
- {/* Search Bar */} -
-
- setSearchQuery(e.target.value)} - className="w-full p-3 pl-12 text-white bg-[#3b0764] rounded-full shadow-md focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent placeholder-gray-400" - /> - - - -
-
- - {/* File Grid */} -
- {error &&
{error}
} -
- {files.map((file) => { - return ( -
-
- -
- - - {file.description && ( -

- Description: {file.description} -

- )} - -
- -
-
- ); - })} -
-
-
- ); -} diff --git a/src/app/share/page.tsx b/src/app/share/page.tsx index fe0ea4c..88891f5 100644 --- a/src/app/share/page.tsx +++ b/src/app/share/page.tsx @@ -16,7 +16,6 @@ interface FileDetails { type: string; url: string; description: string; - isPublic: boolean; } async function fetchFileDetails(fileId: string): Promise { @@ -52,7 +51,6 @@ export default async function FilePreviewContainer({ } const fileDetails = await fetchFileDetails(fileId); - if (!fileDetails) { return ( @@ -156,7 +154,6 @@ export default async function FilePreviewContainer({ fileName={fileDetails.name} fileUrl={fileDetails.url} isOwner={fileDetails.isOwner} - isPublic={fileDetails.isPublic} /> diff --git a/tailwind.config.ts b/tailwind.config.ts new file mode 100644 index 0000000..3d83e5c --- /dev/null +++ b/tailwind.config.ts @@ -0,0 +1,6 @@ +module.exports = { + content: [ + "./src/**/*.{js,ts,jsx,tsx}", // Ensure your paths are correct + ], + plugins: [require("@tailwindcss/typography")], +}; \ No newline at end of file