Skip to content

Commit 71f756b

Browse files
PlayBridgeJS: Add progress bar for initialization steps
1 parent 4cc348e commit 71f756b

File tree

3 files changed

+104
-1
lines changed

3 files changed

+104
-1
lines changed

Examples/PlayBridgeJS/Sources/JavaScript/app.js

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ export class BridgeJSPlayground {
4343
this.copyButton = /** @type {HTMLButtonElement} */ (document.getElementById('copyButton'));
4444
/** @type {HTMLButtonElement} */
4545
this.closeShareDialogButton = /** @type {HTMLButtonElement} */ (document.getElementById('closeShareDialog'));
46+
47+
// Progress UI elements
48+
/** @type {HTMLDivElement | null} */
49+
this.progressBar = /** @type {HTMLDivElement} */ (document.getElementById('progressBar'));
50+
/** @type {HTMLDivElement | null} */
51+
this.progressFill = /** @type {HTMLDivElement} */ (document.getElementById('progressFill'));
52+
/** @type {HTMLDivElement | null} */
53+
this.progressLabel = /** @type {HTMLDivElement} */ (document.getElementById('progressLabel'));
4654
}
4755

4856
/**
@@ -55,43 +63,53 @@ export class BridgeJSPlayground {
5563
}
5664

5765
try {
66+
this.showProgress('Starting…', 5);
5867
// Initialize editor system
5968
await this.editorSystem.init();
69+
this.setProgress('Editor ready', 30);
6070

6171
// Initialize BridgeJS
6272
await this.initializeBridgeJS();
73+
this.setProgress('BridgeJS ready', 70);
6374

6475
// Set up event listeners
6576
this.setupEventListeners();
6677

6778
// Check for shared code in URL
79+
this.setProgress('Checking shared code…', 80);
6880
const sharedCode = await CodeShareManager.extractCodeFromUrl();
6981
if (sharedCode) {
7082
this.editorSystem.setInputs(sharedCode);
7183
} else {
7284
// Load sample code
7385
this.editorSystem.setInputs(sampleCode);
7486
}
75-
87+
this.setProgress('Finalizing…', 95);
7688
this.isInitialized = true;
7789
console.log('BridgeJS Playground initialized successfully');
90+
this.setProgress('Ready', 100);
91+
setTimeout(() => this.hideProgress(), 400);
7892
} catch (error) {
7993
console.error('Failed to initialize BridgeJS Playground:', error);
8094
this.showError('Failed to initialize application: ' + error.message);
95+
this.hideProgress();
8196
}
8297
}
8398

8499
// Initialize BridgeJS
85100
async initializeBridgeJS() {
86101
try {
87102
// Import the BridgeJS module
103+
this.setProgress('Loading BridgeJS…', 50);
88104
const { init } = await import("../../.build/plugins/PackageToJS/outputs/Package/index.js");
89105
const virtualHost = await this.createTS2SkeletonFactory();
106+
this.setProgress('Preparing TypeScript host…', 60);
90107
const { exports } = await init({
91108
getImports: () => ({
92109
createTS2Skeleton: () => this.createTS2Skeleton(virtualHost)
93110
})
94111
});
112+
this.setProgress('Creating runtime…', 65);
95113
this.playBridgeJS = new exports.PlayBridgeJS();
96114
console.log('BridgeJS initialized successfully');
97115
} catch (error) {
@@ -284,4 +302,42 @@ export class BridgeJSPlayground {
284302
hideError() {
285303
this.errorDisplay.classList.remove('show');
286304
}
305+
306+
/**
307+
* Shows progress bar.
308+
* @param {string} label
309+
* @param {number} percent
310+
*/
311+
showProgress(label, percent) {
312+
if (this.progressBar) {
313+
this.progressBar.classList.add('show');
314+
this.progressBar.classList.remove('hidden');
315+
}
316+
this.setProgress(label, percent);
317+
}
318+
319+
/**
320+
* Updates progress label and percentage.
321+
* @param {string} label
322+
* @param {number} percent
323+
*/
324+
setProgress(label, percent) {
325+
if (this.progressLabel) {
326+
this.progressLabel.textContent = label;
327+
}
328+
if (this.progressFill) {
329+
const clamped = Math.max(0, Math.min(100, Number(percent) || 0));
330+
this.progressFill.style.width = clamped + '%';
331+
}
332+
}
333+
334+
/**
335+
* Hides progress bar.
336+
*/
337+
hideProgress() {
338+
if (this.progressBar) {
339+
this.progressBar.classList.remove('show');
340+
this.progressBar.classList.add('hidden');
341+
}
342+
}
287343
}

Examples/PlayBridgeJS/Sources/JavaScript/styles.css

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,47 @@ body {
221221
word-break: break-word;
222222
}
223223

224+
/* Progress bar */
225+
.progress {
226+
margin: 16px auto 0 auto;
227+
max-width: 640px;
228+
opacity: 0;
229+
visibility: hidden;
230+
transition: opacity 0.2s ease;
231+
}
232+
233+
.progress.show {
234+
opacity: 1;
235+
visibility: visible;
236+
}
237+
238+
.progress.hidden {
239+
opacity: 0;
240+
visibility: hidden;
241+
}
242+
243+
.progress-track {
244+
height: 8px;
245+
background-color: var(--color-fill-tertiary);
246+
border: 1px solid var(--color-border);
247+
border-radius: 999px;
248+
overflow: hidden;
249+
}
250+
251+
.progress-fill {
252+
height: 100%;
253+
width: 0%;
254+
background-color: var(--color-figure-blue);
255+
transition: width 0.2s ease;
256+
}
257+
258+
.progress-label {
259+
margin-top: 8px;
260+
text-align: center;
261+
font-size: 12px;
262+
color: var(--color-secondary-label);
263+
}
264+
224265
.main-content {
225266
flex: 1;
226267
display: grid;

Examples/PlayBridgeJS/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ <h3>Share Your Code</h3>
4242
</div>
4343
</div>
4444
</div>
45+
<div id="progressBar" class="progress hidden" aria-live="polite">
46+
<div class="progress-track">
47+
<div id="progressFill" class="progress-fill" style="width:0%"></div>
48+
</div>
49+
<div id="progressLabel" class="progress-label">Initializing…</div>
50+
</div>
4551
</header>
4652

4753

0 commit comments

Comments
 (0)