Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make files previewable #64

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions webapp/src/components/FilePreview.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import React from 'react';
import React, { useState } from 'react';

interface FilePreviewProps {
files: File[];
}

const FilePreview: React.FC<FilePreviewProps> = ({ files}) => {
const [selectedFile, setSelectedFile] = React.useState<File | null>(null);
const FilePreview: React.FC<FilePreviewProps> = ({ files }) => {
const [selectedFile, setSelectedFile] = useState<File | null>(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 (
<div className="mb-6 bg-white p-4 rounded-lg shadow-md h-full">
<div className="flex flex-col sm:flex-row items-start">
Expand All @@ -37,16 +32,24 @@ const FilePreview: React.FC<FilePreviewProps> = ({ files}) => {
</div>

{selectedFile && (
<div
className="border p-4 rounded-lg mt-2 bg-gray-50"
role="region"
aria-labelledby="file-preview-heading"
>
<h3 id="file-preview-heading" className="font-semibold mb-2">
Preview of: {selectedFile.name}
</h3>
{/* Placeholder for file preview */}
<p>File content would be shown here (mock).</p>
<div className="border p-4 rounded-lg mt-2 bg-gray-50">
<h3 className="font-semibold mb-2">Preview of: {selectedFile.name}</h3>
{selectedFile.type === 'application/pdf' ? (
<iframe
src={URL.createObjectURL(selectedFile)}
title="PDF Preview"
className="w-full h-96"
frameBorder="0"
></iframe>
) : selectedFile.type.startsWith('image/') ? (
<img
src={URL.createObjectURL(selectedFile)}
alt={selectedFile.name}
className="max-w-full h-auto rounded-lg"
/>
) : (
<p>File type not supported for preview. Please select a PDF or image file.</p>
)}
</div>
)}
</div>
Expand Down
Loading