diff --git a/scripts/build.js b/scripts/build.js index 9ce90a5..2d7ca4b 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -2,6 +2,7 @@ document.addEventListener('DOMContentLoaded', function () { const logContainer = this.getElementById('logs'); const followLogsBtn = this.getElementById('followCheckmark'); const buildStatusTxt = this.getElementById('buildStatus'); + let started = logContainer.childElementCount > 0; /** * Get the correct path to establish a ws connection @@ -32,6 +33,10 @@ document.addEventListener('DOMContentLoaded', function () { } } + function handleScrollToggleClick() { + window.scrollTo(0, followLogsBtn.checked ? document.body.scrollHeight : 0); + } + /** * Split string by newline char * @param {string} str @@ -53,9 +58,16 @@ document.addEventListener('DOMContentLoaded', function () { ws.onmessage = function (message) { const buildEvent = JSON.parse(message.data); + if (!started) { + started = true; + buildStatusTxt.replaceChild(document.createTextNode('running'), buildStatusTxt.firstChild); + } if (buildEvent.type === 'finish') { ws.close(); buildStatusTxt.replaceChild(document.createTextNode(buildEvent.message), buildStatusTxt.firstChild); + appendLines([`finished: ${buildEvent.message}`]); + const cancelBtn = document.getElementById('cancelRow'); + cancelBtn.parentElement.removeChild(cancelBtn); } else { appendLines(splitLines(buildEvent.message), buildEvent.type === 'err'); @@ -66,5 +78,5 @@ document.addEventListener('DOMContentLoaded', function () { connect(); followLogsBtn.checked = false; - followLogsBtn.addEventListener('change', scrollToBottom); + followLogsBtn.addEventListener('change', handleScrollToggleClick); }); \ No newline at end of file diff --git a/views/build.ejs b/views/build.ejs index df1a2ec..77b274e 100644 --- a/views/build.ejs +++ b/views/build.ejs @@ -21,7 +21,7 @@ <% if (!ended) { %> -