Skip to content

Commit 549e282

Browse files
committed
remove batch files when finished
1 parent 794cf61 commit 549e282

File tree

3 files changed

+98
-2
lines changed

3 files changed

+98
-2
lines changed

src/web/static/js/files/file-upload.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,81 @@ export const FileUpload = {
186186
lastUploadedFileName = null;
187187
},
188188

189+
/**
190+
* Set a file as the active file for editing
191+
* Syncs the file's language parameters TO the UI (file → interface)
192+
* @param {string} filename - Name of the file to set as active
193+
*/
194+
setActiveFile(filename) {
195+
const filesToProcess = StateManager.getState('files.toProcess') || [];
196+
const file = filesToProcess.find(f => f.name === filename);
197+
198+
if (!file) {
199+
return false;
200+
}
201+
202+
// Only allow setting as active if file is still Queued
203+
if (file.status !== 'Queued') {
204+
MessageLogger.showMessage(`Cannot edit file '${filename}' - it's already being processed.`, 'info');
205+
return false;
206+
}
207+
208+
// Update the active file tracking
209+
lastUploadedFileName = filename;
210+
211+
// Sync file parameters TO the interface (file → UI)
212+
this._syncFileToInterface(file);
213+
214+
// Update display to reflect new active file
215+
this.updateFileDisplay();
216+
217+
return true;
218+
},
219+
220+
/**
221+
* Sync file language parameters to the UI interface
222+
* This is the reverse direction: file → interface
223+
* @param {Object} file - File object with sourceLanguage and targetLanguage
224+
* @private
225+
*/
226+
_syncFileToInterface(file) {
227+
// Sync source language
228+
if (file.sourceLanguage) {
229+
const success = setLanguageInSelect('sourceLang', file.sourceLanguage);
230+
if (!success) {
231+
// Language not in list, set to "Other" and fill custom input
232+
const sourceLangSelect = DomHelpers.getElement('sourceLang');
233+
const customSourceLang = DomHelpers.getElement('customSourceLang');
234+
if (sourceLangSelect) {
235+
sourceLangSelect.value = 'Other';
236+
sourceLangSelect.dispatchEvent(new Event('change', { bubbles: true }));
237+
}
238+
if (customSourceLang) {
239+
customSourceLang.value = file.sourceLanguage;
240+
customSourceLang.dispatchEvent(new Event('input', { bubbles: true }));
241+
}
242+
}
243+
}
244+
245+
// Sync target language
246+
if (file.targetLanguage) {
247+
const success = setLanguageInSelect('targetLang', file.targetLanguage);
248+
if (!success) {
249+
// Language not in list, set to "Other" and fill custom input
250+
const targetLangSelect = DomHelpers.getElement('targetLang');
251+
const customTargetLang = DomHelpers.getElement('customTargetLang');
252+
if (targetLangSelect) {
253+
targetLangSelect.value = 'Other';
254+
targetLangSelect.dispatchEvent(new Event('change', { bubbles: true }));
255+
}
256+
if (customTargetLang) {
257+
customTargetLang.value = file.targetLanguage;
258+
customTargetLang.dispatchEvent(new Event('input', { bubbles: true }));
259+
}
260+
}
261+
}
262+
},
263+
189264
/**
190265
* Save file queue to localStorage
191266
* @private
@@ -476,6 +551,14 @@ export const FileUpload = {
476551
const isActiveFile = file.name === lastUploadedFileName && file.status === 'Queued';
477552
li.className = isActiveFile ? 'file-item file-active' : 'file-item';
478553

554+
// Add click handler to set file as active (only for Queued files)
555+
if (file.status === 'Queued') {
556+
li.style.cursor = 'pointer';
557+
li.onclick = () => {
558+
this.setActiveFile(file.name);
559+
};
560+
}
561+
479562
// Icon/thumbnail container
480563
const iconContainer = document.createElement('span');
481564
iconContainer.className = 'file-icon';

src/web/static/js/translation/translation-tracker.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ export const TranslationTracker = {
330330
filesToProcess.splice(fileIndex, 1);
331331
StateManager.setState('files.toProcess', filesToProcess);
332332
MessageLogger.addLog(`🗑️ Removed ${filename} from file list (source file cleaned up)`);
333+
// Notify file list change to update UI and persist to localStorage
334+
FileUpload.notifyFileListChanged();
333335
}
334336
},
335337

src/web/static/style.css

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,9 +1337,20 @@ input[type="range"]::-moz-range-thumb {
13371337
overflow: hidden;
13381338
}
13391339

1340-
.file-item:hover {
1341-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
1340+
/* Clickable file items (Queued status) */
1341+
.file-item[style*="cursor: pointer"]:hover {
1342+
box-shadow: 0 2px 8px rgba(54, 118, 216, 0.15);
13421343
transform: translateY(-1px);
1344+
border-color: var(--primary-light);
1345+
}
1346+
1347+
.file-item[style*="cursor: pointer"]:hover:not(.file-active) {
1348+
background: rgba(54, 118, 216, 0.03);
1349+
}
1350+
1351+
/* Non-clickable file items (Processing/Completed) */
1352+
.file-item:not([style*="cursor: pointer"]):hover {
1353+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
13431354
}
13441355

13451356
/* Active file - the last uploaded file that syncs with language selectors */

0 commit comments

Comments
 (0)