Merge pull request #11862 from hurxxxx/feat/auto-edit-new-folder

feat: Automatically enter edit mode when creating a new folder
This commit is contained in:
Timothy Jaeryang Baek 2025-03-20 17:40:37 -07:00 committed by GitHub
commit 558295f728
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View File

@ -77,6 +77,7 @@
let allChatsLoaded = false; let allChatsLoaded = false;
let folders = {}; let folders = {};
let newFolderId = null;
const initFolders = async () => { const initFolders = async () => {
const folderList = await getFolders(localStorage.token).catch((error) => { const folderList = await getFolders(localStorage.token).catch((error) => {
@ -90,6 +91,11 @@
for (const folder of folderList) { for (const folder of folderList) {
// Ensure folder is added to folders with its data // Ensure folder is added to folders with its data
folders[folder.id] = { ...(folders[folder.id] || {}), ...folder }; folders[folder.id] = { ...(folders[folder.id] || {}), ...folder };
if (newFolderId && folder.id === newFolderId) {
folders[folder.id].isNew = true;
newFolderId = null;
}
} }
// Second pass: Tie child folders to their parents // Second pass: Tie child folders to their parents
@ -150,6 +156,7 @@
}); });
if (res) { if (res) {
newFolderId = res.id;
await initFolders(); await initFolders();
} }
}; };

View File

@ -215,6 +215,14 @@
// Event listener for when dragging ends // Event listener for when dragging ends
folderElement.addEventListener('dragend', onDragEnd); folderElement.addEventListener('dragend', onDragEnd);
} }
if (folders[folderId].isNew) {
folders[folderId].isNew = false;
setTimeout(() => {
editHandler();
}, 100);
}
}); });
onDestroy(() => { onDestroy(() => {
@ -301,10 +309,13 @@
await tick(); await tick();
// focus on the input // focus on the input and select all text
setTimeout(() => { setTimeout(() => {
const input = document.getElementById(`folder-${folderId}-input`); const input = document.getElementById(`folder-${folderId}-input`);
if (input) {
input.focus(); input.focus();
input.select();
}
}, 100); }, 100);
}; };