const queueBtn = document.getElementById('queue-btn');
const jobsContainer = document.getElementById('jobs-container');
let jobs = [];
function renderJobs() {
if (!jobsContainer) return;
if (jobs.length === 0) {
jobsContainer.innerHTML = '';
return;
}
jobsContainer.innerHTML =
'
' +
'
Pending jobs
' +
'
' +
jobs
.map(function (job) {
const preview = job.text.length > 80 ? job.text.slice(0, 80) + '\u2026' : job.text;
return (
'- ' +
'queued ยท ' + job.id + '' +
'' + preview + ' \u2192 ' + job.toLanguage + '' +
'
'
);
})
.join('') +
'
';
}
queueBtn?.addEventListener('click', async () => {
const text = textInput.value;
const toLanguage = toLangSelect.value;
const model = modelSelect.value;
const res = await fetch('/api/jobs', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text, toLanguage, model }),
});
if (!res.ok) return;
const { id } = await res.json();
jobs = [{ id, text, toLanguage, model }].concat(jobs);
renderJobs();
});