From 5ec3e011e14a378d4153cdc0efc36769fd5366bd Mon Sep 17 00:00:00 2001
From: ZareMate <0.zaremate@gmail.com>
Date: Sun, 4 May 2025 06:56:44 +0200
Subject: [PATCH] feat: refactor file handling and enhance client notifications
 across components
---
 src/app/_components/ActionButtons.tsx   |  87 ++++++++++
 src/app/_components/FileActions.tsx     |  24 ++-
 src/app/_components/FilePreview.tsx     |   2 +-
 src/app/_components/HomeButton.tsx      |  12 ++
 src/app/_components/UploadForm.tsx      |   2 +
 src/app/api/{ => files}/remove/route.ts |  14 +-
 src/app/api/{ => files}/serv/route.ts   |   0
 src/app/api/{ => files}/share/route.ts  |  36 +++--
 src/app/share/page.tsx                  | 202 +++++++-----------------
 9 files changed, 213 insertions(+), 166 deletions(-)
 create mode 100644 src/app/_components/ActionButtons.tsx
 create mode 100644 src/app/_components/HomeButton.tsx
 rename src/app/api/{ => files}/remove/route.ts (69%)
 rename src/app/api/{ => files}/serv/route.ts (100%)
 rename src/app/api/{ => files}/share/route.ts (55%)
diff --git a/src/app/_components/ActionButtons.tsx b/src/app/_components/ActionButtons.tsx
new file mode 100644
index 0000000..336a711
--- /dev/null
+++ b/src/app/_components/ActionButtons.tsx
@@ -0,0 +1,87 @@
+'use client';
+import {useFileActions} from "~/app/_components/FileActions";
+
+export function FileActionsContainer({
+  fileId,
+  fileName,
+  fileUrl,
+  isOwner,
+}: {
+  fileId: string;
+  fileName: string;
+  fileUrl: string;
+  isOwner: boolean;
+}) {
+  const { handleDownload, handleCopyUrl, handleRemove } = useFileActions(() => fileId, (description: string) => {
+    if (isOwner) {
+      console.log(description);
+    }
+  });
+
+  return (
+    
+      {/* Download Button */}
+      
+
+      {/* Copy URL Button */}
+      
+
+      {/* Remove Button */}
+      
+    
{error}
;
+    return response.json();
+  } catch (err) {
+    console.error("Failed to fetch file details:", err);
+    return null;
   }
+}
+
+export default async function FilePreviewContainer({
+  searchParams,
+}: {
+  searchParams: { id?: string };
+}) {
+  const fileId = searchParams.id;
+
+  if (!fileId) {
+    notFound();
+  }
+
+  const fileDetails = await fetchFileDetails(fileId);
 
   if (!fileDetails) {
     return (
       
         
         
-          
+          
         
         
           
@@ -122,16 +90,19 @@ export default function FilePreviewContainer() {
           ).toLocaleString()}`}
         />
         
+        
+        
+        
       
       
-        
         
-          
+           {/* Use the client component */}
         
         
           
@@ -139,8 +110,10 @@ export default function FilePreviewContainer() {
           
           
             {fileDetails.type !== "unknown" && (
-              
-              
+              
             )}
           
           
@@ -172,79 +145,16 @@ export default function FilePreviewContainer() {
             
             
               Description:{" "}
-              {fileDetails.isOwner ? (
-                
-            {fileDetails.isOwner && (
-              
-                
-                
-                
-              
-            )}
+            
+              
+