Skip to content

Commit 67543d2

Browse files
author
jonathan sprauel
committed
option to keep folder on deletion
1 parent 354b2b5 commit 67543d2

2 files changed

Lines changed: 108 additions & 26 deletions

File tree

index.html

Lines changed: 96 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
}
107107
}
108108

109-
/* Masquer la barre d'entrée si configPanel ou sandboxModal sont visibles */
109+
/* Masquer la barre d'entrée si configPanel ou sandboxModal ou deleteConfirmModal sont visibles */
110110
#configPanel[style*="display: flex"]~#sandboxModal[style*="display: flex"]~#floatingInputBar {
111111
display: none !important;
112112
}
@@ -115,6 +115,10 @@
115115
display: none !important;
116116
}
117117

118+
#deleteConfirmModal[style*="display: flex"]~#floatingInputBar {
119+
display: none !important;
120+
}
121+
118122
/* Styles pour la vue chat */
119123
.chat-view {
120124
display: none;
@@ -313,6 +317,28 @@ <h3 id="sandboxModalTitle" class="text-lg font-semibold mb-4">Sandbox Title</h3>
313317
</div>
314318
</div>
315319
</div>
320+
<!-- Modal pour confirmation de suppression de sandbox -->
321+
<div id="deleteConfirmModal" class="fixed inset-0 bg-black bg-opacity-30 z-40 items-center justify-center"
322+
style="display:none;">
323+
<div class="bg-white rounded-lg shadow-lg p-6 w-full max-w-md mx-auto flex flex-col">
324+
<h3 class="text-lg font-semibold mb-4 text-red-600">
325+
<i class="fas fa-exclamation-triangle mr-2"></i>Delete Sandbox
326+
</h3>
327+
<p class="text-gray-700 mb-6">Are you sure you want to delete this sandbox?</p>
328+
<div class="flex flex-col space-y-3">
329+
<button id="deleteKeepFolderBtn"
330+
class="bg-orange-500 hover:bg-orange-600 text-white py-3 px-4 rounded flex items-center justify-center">
331+
<i class="fas fa-folder mr-2"></i>Delete sandbox but keep folder
332+
</button>
333+
<button id="deleteWithFolderBtn"
334+
class="bg-red-600 hover:bg-red-700 text-white py-3 px-4 rounded flex items-center justify-center">
335+
<i class="fas fa-trash mr-2"></i>Delete sandbox and folder
336+
</button>
337+
<button id="deleteCancelBtn"
338+
class="bg-gray-300 hover:bg-gray-400 text-gray-800 py-2 px-4 rounded">Cancel</button>
339+
</div>
340+
</div>
341+
</div>
316342
<!-- Champ de saisie flottant discret à droite -->
317343
<div id="floatingInputBar"
318344
class="floating-input-bar z-30 flex items-center justify-center pointer-events-none">
@@ -476,24 +502,73 @@ <h3 id="sandboxModalTitle" class="text-lg font-semibold mb-4">Sandbox Title</h3>
476502

477503
deleteBtn.onclick = async function () {
478504
if (!currentConvId) return;
479-
if (confirm('Delete Sandbox (folder will also be deleted)?')) {
480-
const ok = await deleteSandbox(currentConvId);
481-
if (ok) {
482-
await loadHistoryPanel();
483-
// Charge la première conversation restante, sinon vide le chat
484-
const convs = await fetchSandboxes();
485-
if (convs.length > 0) {
486-
await loadSandbox(convs[0].id);
487-
} else {
488-
currentConvId = null;
489-
currentConvMessages = [];
490-
document.getElementById('timelineContainer').innerHTML = '';
491-
document.getElementById('chatContainer').innerHTML = '';
492-
document.getElementById('currentConvTitle').textContent = '';
493-
}
505+
506+
// Show the delete confirmation modal
507+
const deleteModal = document.getElementById('deleteConfirmModal');
508+
deleteModal.style.display = 'flex';
509+
};
510+
511+
// Handle delete confirmation modal buttons
512+
const deleteModal = document.getElementById('deleteConfirmModal');
513+
const deleteKeepFolderBtn = document.getElementById('deleteKeepFolderBtn');
514+
const deleteWithFolderBtn = document.getElementById('deleteWithFolderBtn');
515+
const deleteCancelBtn = document.getElementById('deleteCancelBtn');
516+
517+
deleteKeepFolderBtn.onclick = async function () {
518+
deleteModal.style.display = 'none';
519+
const ok = await deleteSandbox(currentConvId, false); // false = keep folder
520+
if (ok) {
521+
await loadHistoryPanel();
522+
// Charge la première conversation restante, sinon vide le chat
523+
const convs = await fetchSandboxes();
524+
if (convs.length > 0) {
525+
await loadSandbox(convs[0].id);
526+
} else {
527+
currentConvId = null;
528+
currentConvMessages = [];
529+
document.getElementById('timelineContainer').innerHTML = '';
530+
document.getElementById('chatContainer').innerHTML = '';
531+
document.getElementById('currentConvTitle').textContent = '';
494532
}
495533
}
496534
};
535+
536+
deleteWithFolderBtn.onclick = async function () {
537+
deleteModal.style.display = 'none';
538+
const ok = await deleteSandbox(currentConvId, true); // true = delete folder
539+
if (ok) {
540+
await loadHistoryPanel();
541+
// Charge la première conversation restante, sinon vide le chat
542+
const convs = await fetchSandboxes();
543+
if (convs.length > 0) {
544+
await loadSandbox(convs[0].id);
545+
} else {
546+
currentConvId = null;
547+
currentConvMessages = [];
548+
document.getElementById('timelineContainer').innerHTML = '';
549+
document.getElementById('chatContainer').innerHTML = '';
550+
document.getElementById('currentConvTitle').textContent = '';
551+
}
552+
}
553+
};
554+
555+
deleteCancelBtn.onclick = function () {
556+
deleteModal.style.display = 'none';
557+
};
558+
559+
// Handle escape key for delete modal
560+
document.addEventListener('keydown', function(e) {
561+
if (e.key === 'Escape' && deleteModal.style.display === 'flex') {
562+
deleteModal.style.display = 'none';
563+
}
564+
});
565+
566+
// Handle click outside modal to close
567+
deleteModal.addEventListener('click', function(e) {
568+
if (e.target === deleteModal) {
569+
deleteModal.style.display = 'none';
570+
}
571+
});
497572
};
498573

499574
// Gestionnaires pour les boutons de basculement de vue
@@ -796,8 +871,10 @@ <h3 id="sandboxModalTitle" class="text-lg font-semibold mb-4">Sandbox Title</h3>
796871
}
797872
});
798873
// Fonctions pour supprimer et renommer une conversation
799-
async function deleteSandbox(convId) {
800-
const res = await fetch(`/sandboxes/${convId}`, { method: 'DELETE' });
874+
async function deleteSandbox(convId, deleteFolder = true) {
875+
const params = new URLSearchParams();
876+
params.append('delete_folder', deleteFolder.toString());
877+
const res = await fetch(`/sandboxes/${convId}?${params}`, { method: 'DELETE' });
801878
return res.ok;
802879
}
803880
async function renameSandbox(convId, newTitle) {
@@ -884,7 +961,7 @@ <h3 id="sandboxModalTitle" class="text-lg font-semibold mb-4">Sandbox Title</h3>
884961
timeline.innerHTML = '<div class="text-center text-gray-500 py-8">Welcome ! What can I do for you today? Don\'t forget to configure your API key in the configuration panel.</div>';
885962
return;
886963
}
887-
964+
888965
// Regroupement correct des étapes : chaque user suivi de 1 ou plusieurs assistant
889966
const steps = [];
890967
let currentStep = null;

main.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -737,20 +737,25 @@ async def api_add_message(conv_id: str, request: Request):
737737
return {"status": "ok"}
738738

739739
@app.delete("/sandboxes/{conv_id}")
740-
async def api_delete_sandbox(conv_id: str):
740+
async def api_delete_sandbox(conv_id: str, delete_folder: bool = True):
741741
convs = load_all_sandboxes()
742742
if conv_id not in convs:
743743
return JSONResponse(status_code=404, content={"error": "Not found"})
744744

745745
sandbox_path = get_sandbox_path(conv_id)
746746
del convs[conv_id]
747747
save_all_sandboxes(convs)
748-
# Suppression du dossier sandbox correspondant
749-
import shutil
750-
if os.path.exists(sandbox_path):
751-
shutil.rmtree(sandbox_path)
752-
logging.info(f"Deleted sandbox {conv_id} at path {sandbox_path}")
753-
return {"status": "deleted"}
748+
749+
# Conditionally delete the sandbox folder
750+
if delete_folder:
751+
import shutil
752+
if os.path.exists(sandbox_path):
753+
shutil.rmtree(sandbox_path)
754+
logging.info(f"Deleted sandbox {conv_id} and folder at path {sandbox_path}")
755+
else:
756+
logging.info(f"Deleted sandbox {conv_id} but kept folder at path {sandbox_path}")
757+
758+
return {"status": "deleted", "folder_deleted": delete_folder}
754759

755760
@app.patch("/sandboxes/{conv_id}")
756761
async def api_patch_sandbox(conv_id: str, request: Request):

0 commit comments

Comments
 (0)