From 97372722c2905a7140c9fbcae2978971de174931 Mon Sep 17 00:00:00 2001 From: Sverre Nystad Date: Wed, 30 Oct 2024 13:27:48 +0100 Subject: [PATCH] feat: make files previewable --- webapp/src/components/FilePreview.tsx | 39 ++++++++++++++------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/webapp/src/components/FilePreview.tsx b/webapp/src/components/FilePreview.tsx index 206ad1c..4ccbea0 100644 --- a/webapp/src/components/FilePreview.tsx +++ b/webapp/src/components/FilePreview.tsx @@ -1,22 +1,17 @@ -import React from 'react'; +import React, { useState } from 'react'; interface FilePreviewProps { files: File[]; } -const FilePreview: React.FC = ({ files}) => { - const [selectedFile, setSelectedFile] = React.useState(null); +const FilePreview: React.FC = ({ files }) => { + const [selectedFile, setSelectedFile] = useState(null); - /** - * Sets the selected file for preview. - * @param fileName - The name of the file to select. - */ const handleSelectFile = (fileName: string) => { const file = files.find(file => file.name === fileName) ?? null; setSelectedFile(file); }; - return (
@@ -37,16 +32,24 @@ const FilePreview: React.FC = ({ files}) => {
{selectedFile && ( -
-

- Preview of: {selectedFile.name} -

- {/* Placeholder for file preview */} -

File content would be shown here (mock).

+
+

Preview of: {selectedFile.name}

+ {selectedFile.type === 'application/pdf' ? ( + + ) : selectedFile.type.startsWith('image/') ? ( + {selectedFile.name} + ) : ( +

File type not supported for preview. Please select a PDF or image file.

+ )}
)}