Merge pull request Smart Naming for Files and Modular code#176
Open
anshika-guleria wants to merge 3 commits into
Open
Merge pull request Smart Naming for Files and Modular code#176anshika-guleria wants to merge 3 commits into
anshika-guleria wants to merge 3 commits into
Conversation
…ixing feat: add Back to Home navigation button in sidebar Signed-off-by: Anshika Guleria <anshikaguleria532@gmail.com>
|
@Durgeshwar-AI is attempting to deploy a commit to the Durgeshwar's projects Team on Vercel. A member of the Team first needs to authorize it. |
Owner
|
@anshika-guleria please fix the merge conflicts. |
Author
|
I hope i did correctly please check @Durgeshwar-AI |
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the frontend conversion tools to centralize download handling and provide consistent, “smart” suggested output filenames that users can edit before downloading.
Changes:
- Added reusable filename utilities (
buildDownloadName, sanitizers) and a shared download helper (triggerDownload). - Introduced
useDownloadFilenamehook +OutputFilenameInputcomponent and wired many tool pages to use them (viaToolPageTemplateand/or page-specific UI). - Updated multiple pages to use
toolName/outputExtension/filenameDetailinstead of per-pagegetDownloadFilenamelogic.
Reviewed changes
Copilot reviewed 29 out of 30 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/src/utils/fileNames.js | New shared filename building + sanitization utilities. |
| frontend/src/utils/downloadFile.js | New shared download helper to consolidate anchor/objectURL logic. |
| frontend/src/hooks/useDownloadFilename.js | New hook to manage suggested + user-edited filenames and resolution logic. |
| frontend/src/components/OutputFilenameInput.jsx | New reusable “output filename” input UI with basic sanitization. |
| frontend/src/components/FileUploadArea.jsx | Adds optional OutputFilenameInput rendering in the upload area. |
| frontend/src/components/ToolPageTemplate.jsx | Integrates filename hook + download helper; exposes filename context to callers. |
| frontend/src/pages/RotateFlip.jsx | Uses template filename context to name transformed image downloads. |
| frontend/src/pages/RemoveBg.jsx | Migrates to toolName/outputExtension for naming consistency. |
| frontend/src/pages/PDFWatermark.jsx | Uses useDownloadFilename + triggerDownload; adds filename input. |
| frontend/src/pages/PdfSplit.jsx | Uses useDownloadFilename + triggerDownload; adds filename input. |
| frontend/src/pages/PdfSign.jsx | Migrates to toolName/outputExtension for naming consistency. |
| frontend/src/pages/PdfRotateFlip.jsx | Uses useDownloadFilename; sets suggested detail based on action; updates download name. |
| frontend/src/pages/PdfPng.jsx | Adds smarter per-page/zip naming based on extracted page text + shared naming utility. |
| frontend/src/pages/PdfMerge.jsx | Attempts to refactor merge flow to shared filename/download utilities (currently inconsistent). |
| frontend/src/pages/PdfDocx.jsx | Uses useDownloadFilename + triggerDownload; adds filename input. |
| frontend/src/pages/ImageWbp.jsx | Migrates to toolName/outputExtension for naming consistency. |
| frontend/src/pages/ImageWatermark.jsx | Uses useDownloadFilename + triggerDownload; adds filename input. |
| frontend/src/pages/ImageUpscale.jsx | Migrates to toolName/filenameDetail/outputExtension for naming consistency. |
| frontend/src/pages/ImageToSVG.jsx | Uses triggerDownload and template filename context for SVG downloads. |
| frontend/src/pages/ImageResize.jsx | Uses triggerDownload and template filename context; adds filenameDetail. |
| frontend/src/pages/ImagePdf.jsx | Attempts to migrate to ToolPageTemplate (currently incomplete/broken). |
| frontend/src/pages/ImageOCR.jsx | Uses triggerDownload and template filename context for text downloads. |
| frontend/src/pages/ImageMetadata.jsx | Uses triggerDownload and template filename context for stripped/clean downloads. |
| frontend/src/pages/ImageJpg.jsx | Migrates to toolName/outputExtension for naming consistency. |
| frontend/src/pages/ImageGrayScale.jsx | Migrates to toolName/outputExtension for naming consistency. |
| frontend/src/pages/ImageDpi.jsx | Uses triggerDownload and template filename context; adds filenameDetail. |
| frontend/src/pages/ImageCompress.jsx | Switches to shared naming utility for compressed output names. |
| frontend/src/pages/ImageBase64.jsx | Uses triggerDownload and template filename context for base64 text downloads. |
| frontend/src/pages/DocxPdf.jsx | Uses useDownloadFilename + triggerDownload; adds filename input. |
| frontend/package-lock.json | Lockfile update (adds peer: true flags in multiple entries). |
Files not reviewed (1)
- frontend/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| return blob.arrayBuffer(); | ||
| }; | ||
| import { useCallback } from "react"; |
Comment on lines
102
to
+110
| return ( | ||
| <div className="w-full max-w-[760px] mx-auto p-10 text-center flex flex-col justify-center items-center bg-linear-to-br from-[#f6f8fa] to-white rounded-2xl shadow-[0_10px_30px_rgba(0,0,0,0.08)] overflow-hidden"> | ||
| <h1 className="mb-10 text-[#1a1a2e] text-5xl font-bold tracking-tight relative inline-block after:content-[''] after:absolute after:w-15 after:h-1 after:bg-linear-to-r after:from-[#4361ee] after:to-[#7209b7] after:-bottom-2.5 after:left-1/2 after:-translate-x-1/2 after:rounded-sm"> | ||
| Image to PDF | ||
| </h1> | ||
| <p className="text-gray-500 mb-8"> | ||
| Convert multiple images into a single PDF and arrange them in the exact | ||
| order you want. | ||
| </p> | ||
|
|
||
| <form onSubmit={createPdf} className="w-full flex flex-col items-center"> | ||
| <div | ||
| ref={dropAreaRef} | ||
| className={`w-full border-2 border-dashed rounded-2xl p-8 mb-6 cursor-pointer transition-all duration-300 flex flex-col items-center select-none ${ | ||
| isDragging | ||
| ? "border-[#3b82f6] bg-[#ebf5ff] scale-[1.02]" | ||
| : "border-[#c7d2fe] bg-[rgba(239,246,255,0.6)] hover:border-[#4361ee] hover:-translate-y-1 hover:shadow-[0_8px_15px_rgba(67,97,238,0.1)] hover:bg-[rgba(229,240,255,0.8)] active:translate-y-0 active:shadow-[0_4px_8px_rgba(67,97,238,0.08)] active:bg-[rgba(219,234,254,0.9)]" | ||
| }`} | ||
| onDragEnter={handleDragEnter} | ||
| onDragOver={handleDragOver} | ||
| onDragLeave={handleDragLeave} | ||
| onDrop={handleDrop} | ||
| onClick={handleAreaClick} | ||
| <ToolPageTemplate | ||
| title="Image to PDF" | ||
| description="Convert an image into a PDF file, right in your browser." | ||
| accept="image/*" | ||
| validateFile={validateFile} | ||
| onSubmit={createPdf} | ||
| toolName="pdf" | ||
| outputExtension="pdf" |
Comment on lines
+6
to
+15
| function MergePdf() { | ||
| const [files, setFiles] = useState([]); | ||
| const { downloadFilename, setDownloadFilename, resetDownloadFilename, resolveFilename } = | ||
| useDownloadFilename({ | ||
| originalName: files[0]?.name, | ||
| tool: "merged", | ||
| detail: files.length > 1 ? `${files.length} files` : undefined, | ||
| extension: "pdf", | ||
| enabled: files.length > 0, | ||
| }); |
Comment on lines
+171
to
+174
| const blob = await res.blob(); | ||
| triggerDownload(blob, resolveFilename("merged.pdf")); | ||
| setStatusMessage("PDFs merged successfully! File downloaded."); | ||
| setStatusType("success"); |
Comment on lines
82
to
+86
| const blob = await response.blob(); | ||
| const url = URL.createObjectURL(blob); | ||
| const a = document.createElement("a"); | ||
| a.href = url; | ||
|
|
||
| const extension = file.name.includes(".") | ||
| ? file.name.slice(file.name.lastIndexOf(".")) | ||
| : ".png"; | ||
| const baseName = file.name.includes(".") | ||
| ? file.name.replace(/\.[^.]+$/, "") | ||
| : file.name; | ||
| a.download = `${baseName}_stripped${extension}`; | ||
|
|
||
| document.body.appendChild(a); | ||
| a.click(); | ||
| document.body.removeChild(a); | ||
| URL.revokeObjectURL(url); | ||
| triggerDownload( | ||
| blob, | ||
| resolveFilename?.(`${file.name.replace(/\.[^.]+$/, "")}_stripped.png`, nameOverrides), | ||
| ); |
Comment on lines
115
to
+119
| const blob = await response.blob(); | ||
| const url = URL.createObjectURL(blob); | ||
|
|
||
| const a = document.createElement("a"); | ||
| a.href = url; | ||
|
|
||
| const baseName = file.name.replace(/\.[^.]+$/, ""); | ||
| const extension = file.name.includes(".") ? file.name.split(".").pop() : "png"; | ||
|
|
||
| a.download = `${baseName}_privacy_cleaned.${extension}`; | ||
|
|
||
| document.body.appendChild(a); | ||
| a.click(); | ||
| document.body.removeChild(a); | ||
|
|
||
| URL.revokeObjectURL(url); | ||
| triggerDownload( | ||
| blob, | ||
| resolveFilename?.(`${file.name.replace(/\.[^.]+$/, "")}_privacy_cleaned.png`, nameOverrides), | ||
| ); |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Owner
|
@anshika-guleria It has multiple problems please fix them. |
Author
|
I am on it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: add reusable utilities for file naming and download handling in frontend
🔀 Pull Request
📌 Issue Reference
Closes #158
📝 Summary
This PR improves the frontend code structure by introducing reusable utilities and removing repeated logic across different conversion pages (PDF to PNG, image to PDF, SVG, etc.).
Changes made:
✅ Checklist
🏅 Open Source Program Participation
Program Name: GSSoC 2026
💬 Additional Notes
I tried my best to keep the changes minimal, clean, and consistent with the existing codebase. This is mainly a refactor to improve structure and reusability, not a UI change.
I have also made file names editable
Please let me know if any improvements are required.