From 305650925ec1de7125cc62ee39997ea3414215d1 Mon Sep 17 00:00:00 2001 From: Arnab-Afk Date: Thu, 27 Mar 2025 12:43:18 +0530 Subject: [PATCH] Add file download functionality to EditorArea component --- Frontend/src/components/EditorArea.jsx | 111 +++++++++++++++++++++++++ backend/tmp/main.exe | Bin 8596480 -> 8596480 bytes 2 files changed, 111 insertions(+) diff --git a/Frontend/src/components/EditorArea.jsx b/Frontend/src/components/EditorArea.jsx index c24d41c..89b954b 100644 --- a/Frontend/src/components/EditorArea.jsx +++ b/Frontend/src/components/EditorArea.jsx @@ -662,6 +662,37 @@ Happy coding!`; } }; + // Add this function above the return statement + const handleDownloadFile = () => { + if (!activeFile) return; + + // Create a blob with the file content + const blob = new Blob([activeFile.content], { type: 'text/plain' }); + + // Create a URL for the blob + const url = URL.createObjectURL(blob); + + // Create a temporary anchor element + const a = document.createElement('a'); + a.href = url; + + // Get just the filename without path + const fileName = activeFile.id.includes('/') ? + activeFile.id.split('/').pop() : + activeFile.id; + + // Set the download attribute with the filename + a.download = fileName; + + // Append to the document, click it, and then remove it + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + + // Release the object URL + URL.revokeObjectURL(url); + }; + return (
{sidebarVisible && ( @@ -818,6 +849,7 @@ Happy coding!`; )} + {/* Modify the editor-actions div to include the download button */}
+ + {/* Add download button */} +
{isNewFileModalOpen && ( @@ -886,6 +942,61 @@ Happy coding!`; Rename
+ + {/* Add download option - only show for files */} + {contextMenuTarget?.type === 'file' && ( +
{ + // Find the file in the files array + const file = files.find(f => f.id === contextMenuTarget.path); + if (file) { + // Create a blob with the file content + const blob = new Blob([file.content], { type: 'text/plain' }); + + // Create a URL for the blob + const url = URL.createObjectURL(blob); + + // Create a temporary anchor element + const a = document.createElement('a'); + a.href = url; + + // Get just the filename without path + const fileName = file.id.includes('/') ? + file.id.split('/').pop() : + file.id; + + // Set the download attribute with the filename + a.download = fileName; + + // Append to the document, click it, and then remove it + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + + // Release the object URL + URL.revokeObjectURL(url); + } + closeContextMenu(); + }}> + + + + + + Download +
+ )} +
{ deleteItem(contextMenuTarget.path, contextMenuTarget.type); closeContextMenu(); diff --git a/backend/tmp/main.exe b/backend/tmp/main.exe index fadda57c13abb516db0596fd8695e8ecaeb4d037..345d95955940ca310b108a60df03528bdb7eda2b 100644 GIT binary patch delta 752 zcmbWx$zBox0D$pdWSF+uVx>i?X=$2+!wfS>kjnrr<=_Hp8^$b6D6uMH+n5I~-8^{p z?8zGs;7jy4eZE46|K&S1hV>11ukkmPhNp4bcQR#Z(XYl`5+N;!2>t5%a4 zJtLdN_@<@_$@+9YZ&_RA`odhy$tNnMQdQ6$xtLRDVg*f4>8l09nW}B~wf7uu2;B#+ zx8Zs(z=Mlu!6lscR$N9K+HnO}aShjT10A@DTeyuo=)_&z!+mt28xQahK0Lx>^q?1g zc!GWm;3=MA5JPy5VT|AfMj^nDF^C92f{Y*(s0d-a>3YK_%Agsr{FWV(P02oIWP^qw zsMq&7iCv`8=tvR%OL6kBib##FH9r97n@=i3p;2g$Ybz3e(UKLmUar zU>0+j$7{U70(2y?h$SpHkE1K8v;UiHFo`r)v4(ZL#XG#m2Yf^Z8~B7Q44ANB<1-w5 sK@OYPLLOgHKoKRBQ9%{k*g*}usACV`@Et$!6TjeMAHSOs&%xQyKbkS_(*OVf delta 752 zcmbWx%U%*;06_6yWN2Q>uBK+0-L%5t1BaQ>AeBf(0c(Vyi#o#$!YCSGDcWVs1)Fv) z+`4wvjtB51dYn$L;NrhItKRTcoGH_ZZsjrs$1Z6lePLx@l1sZGpPo+5 zCPm({WGi2c>(XL9S}xo6Mzx-d$BN~dTBWirWyhwqniW%W2|XA{RI6E$nj2~#{Jkpm z9lG9z>pce#&Z7kv@V~dB4Hwal4s@ammv9-~xPq&=hU>V2o9MwU^r8>_xQzka!CegE z9)@rq5AYC=@EF4w!4o{iGx#tH34RC!5X2Z{grGo$hViEBoj6g3Rm)H<*(`+oni5cL z%`nxxDGW_6SgH{Snugz0h471`0Z+QOHMAt;@t`;gd(xwg#}BwTz|Usbb9g%P50g&p&;S4c