Skip to content

Commit

Permalink
Rename spinner to progress, add note
Browse files Browse the repository at this point in the history
  • Loading branch information
eevleevs committed Mar 15, 2024
1 parent b2d062a commit e6c683d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
22 changes: 16 additions & 6 deletions apps/jscad-web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ const exportModel = async (format, extension) => {
}
}

const onProgress = ([value, note]) => {
const el = progress.querySelector('progress')
if (value == undefined) {
el.removeAttribute('value')
} else {
el.value = value
}
progress.querySelector('div').innerText = note ?? ''
}

const worker = new Worker('./build/bundle.worker.js')
const handlers = {
entities: ({ entities, mainTime, convertTime }) => {
Expand All @@ -165,20 +175,20 @@ const handlers = {
console.log('Main execution:', mainTime?.toFixed(2), ', jscad mesh -> gl:', convertTime?.toFixed(2))
setError(undefined)
},
progress: ({ progress }) => spinner.value = progress,
onProgress,
}
const { sendCmd, sendNotify } = initMessaging(worker, handlers)

const spinner = byId('spinner')
const progress = byId('progress')
let jobs = 0
let firstJobTimer
async function sendCmdAndSpin(method, params) {
jobs++
if (jobs === 1) {
// do not show spinner for fast renders
// do not show progress for fast renders
firstJobTimer = setTimeout(() => {
spinner.style.display = 'block'
spinner.removeAttribute('value')
onProgress([])
progress.style.display = 'block'
}, 300)
}
try {
Expand All @@ -189,7 +199,7 @@ async function sendCmdAndSpin(method, params) {
} finally {
if (--jobs === 0) {
clearTimeout(firstJobTimer)
spinner.style.display = 'none'
progress.style.display = 'none'
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion apps/jscad-web/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ <h1>JSCAD</h1>

<div id="overlay">
<div class="above-error">
<progress id="spinner" title="Processing..."></progress>
<div id="progress">
<div></div>
<progress title="Processing..."></progress>
</div>

<div id="model-options">
<div id="paramsDiv"></div>
Expand Down
8 changes: 6 additions & 2 deletions apps/jscad-web/static/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -569,16 +569,20 @@ p {
border-top-left-radius: 4px;
}

#spinner {
#progress {
position: absolute;
bottom: 10px;
right: 10px;
display: none;
accent-color: #27c;
}
.dark #spinner {
.dark #progress {
accent-color: #2e96ea;
}
#progress > div {
font-size: small;
text-align: right;
}

.above-error {
flex: 1;
Expand Down

0 comments on commit e6c683d

Please sign in to comment.