Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use progress indicator instead of spinner #101

Merged
merged 9 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .github/workflows/build.yml

This file was deleted.

21 changes: 17 additions & 4 deletions apps/jscad-web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,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 @@ -180,25 +190,28 @@ const handlers = {
console.log('Main execution:', mainTime?.toFixed(2), ', jscad mesh -> gl:', convertTime?.toFixed(2))
setError(undefined)
},
onProgress,
}

/** @type {JscadWorker} */
const workerApi = messageProxy(worker, handlers, { onJobCount: trackJobs })

const spinner = byId('spinner')
const progress = byId('progress')
let jobs = 0
let firstJobTimer

function trackJobs(jobs) {
if (jobs === 1) {
// do not show progress for fast renders
clearTimeout(firstJobTimer)
// do not show spinner for fast renders
firstJobTimer = setTimeout(() => {
spinner.style.display = 'block'
onProgress()
progress.style.display = 'block'
}, 300)
}
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">
<div id="spinner" title="Processing..."></div>
<div id="progress">
<div></div>
<progress title="Processing..."></progress>
</div>

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

#spinner {
#progress {
position: absolute;
bottom: 10px;
right: 10px;
border: 6px solid #f3f3f3;
border-top: 6px solid #27c;
border-radius: 50%;
width: 32px;
height: 32px;
animation: spin 1s linear infinite;
display: none;
accent-color: #27c;
}
.dark #spinner {
border: 6px solid #222;
border-top: 6px solid #16a;
.dark #progress {
accent-color: #2e96ea;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
#progress > div {
font-size: small;
text-align: right;
}

.above-error {
Expand Down