Skip to content

Commit

Permalink
Merge pull request #21 from ubclaunchpad/SarahWang/upload-photo-changes
Browse files Browse the repository at this point in the history
Sarah wang/upload photo changes
  • Loading branch information
pluswang2001 authored Jan 31, 2025
2 parents 8d55f48 + 5fd8958 commit 7ddebfe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
17 changes: 0 additions & 17 deletions frontend/src/components/UploadPhoto/PreviewSection.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { useState } from "react";
import {
ChevronDoubleRightIcon,
PencilSquareIcon,
} from "@heroicons/react/24/solid";
import "./PreviewSection.css";

Expand All @@ -11,12 +9,6 @@ export default function PreviewSection({
handlePreviewClick,
handleTranscribe,
}) {
const [isEditing, setIsEditing] = useState(false);

/** Toggle edit mode */
const handleEdit = () => {
setIsEditing((prev) => !prev);
};

/** Handle image deletion */
const handleDeleteImage = (timestampToDelete) => {
Expand All @@ -40,13 +32,6 @@ export default function PreviewSection({
<ChevronDoubleRightIcon className="preview-section-icon" />
<span>Preview</span>
</button>
<button
className={`edit-button ${isEditing ? "active" : ""}`}
onClick={handleEdit}
>
<PencilSquareIcon className="edit-icon" />
<span>Edit</span>
</button>
</div>

<div className="preview-list">
Expand All @@ -57,14 +42,12 @@ export default function PreviewSection({
alt={`Preview ${index + 1}`}
className="preview-image"
/>
{isEditing && (
<button
className="delete-button"
onClick={() => handleDeleteImage(fileData.timestamp)}
>
×
</button>
)}
</div>
))}
</div>
Expand Down
22 changes: 16 additions & 6 deletions frontend/src/pages/upload_photo/UploadPhoto.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,26 @@ function MainContent({ files, setFiles, handleTranscribe }) {
/** Handle files from input or drop */
const handleFiles = (newFiles) => {
const filesArray = Array.from(newFiles);

const filesWithPreview = filesArray.map((file) => {
return {

setFiles((prevFiles) => {
// Check if the new total would exceed the limit
const totalFiles = prevFiles.length + filesArray.length;

if (totalFiles > 2) {
alert("You can only upload up to 2 files.");
return prevFiles; // Return the current state without changes
}

// Process the new files
const filesWithPreview = filesArray.map((file) => ({
file: file, // Store the actual File object
timestamp: Date.now(),
preview: URL.createObjectURL(file),
};
}));

return [...prevFiles, ...filesWithPreview]; // Append new files
});
setFiles((prev) => [...filesWithPreview, ...prev]); // Add new files to beginning
};
};

/** Toggle preview visibility */
const handlePreviewClick = () => {
Expand Down

0 comments on commit 7ddebfe

Please sign in to comment.