Skip to content

Conversation

@shanecranor
Copy link
Owner

@shanecranor shanecranor commented Apr 6, 2025

Moves processing to web worker
Switch to JS modules
Add export ability
Add loading screen
Improve styles

Summary by CodeRabbit

  • New Features

    • Introduced an animated loading overlay with a progress bar to improve visual feedback during image rendering.
    • Added the ability to download rendered output as a PNG file.
    • Enhanced asynchronous rendering and state updates for a more responsive experience.
  • Style

    • Applied updated visual styling to loading elements for a cleaner, modern look.

@shanecranor shanecranor requested a review from Copilot April 6, 2025 15:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 6 changed files in this pull request and generated no comments.

Files not reviewed (2)
  • index.css: Language not supported
  • index.html: Language not supported

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 6, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 6, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request introduces a loading overlay and loading bar to enhance user feedback during rendering operations. New CSS rules are added to style these elements, and the HTML structure is updated to include the overlay with a loading bar and message. A new JavaScript module (index.js) manages asynchronous rendering using a web worker, handles state management, and provides functionality to download the rendered image. Additionally, several existing functions in other modules have been refactored to be exported, and a worker script is added to perform pixel-based rendering with progress updates.

Changes

File(s) Summary of Changes
index.css Added new CSS rules for #loadingOverlay, #loadingBarContainer, and #loadingBar to style a full viewport overlay, loading bar container, and animated loading bar.
index.html Introduced a new loading overlay element (with a loading bar and message) and updated script tags to use ES modules (now including index.js).
index.js New module implementing asynchronous rendering using a web worker. Manages drawing on a canvas, state checking via URL, formula generation, and image download functionality.
qbist.js and qbistListeners.js Modified functions to be exported. In qbist.js, the drawing function code has been commented out. In qbistListeners.js, state loading functions now use Object.assign for merging state and improved error handling.
worker.js New worker script that listens for "render" messages, processes image rendering with progress updates, and sends back a buffer containing rendered pixel data.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant M as Main (index.js)
    participant W as Worker (worker.js)

    U->>M: Initiates rendering/update
    M->>W: Send "render" command with parameters
    W-->>M: Send progress updates (if applicable)
    W-->>M: Send final image data buffer
    M->>M: Update canvas and loading overlay UI
Loading

Possibly related PRs

  • Move processing to worker  #1: This PR introduces a loading overlay and loading bar components in the CSS and HTML, indicating a direct connection in their implementation.

Poem

Oh, what a day unfolds in code,
A rabbit’s delight in each new mode.
Loading overlays and bars that gleam,
Workers at work—what a seamless dream!
Hop along, for changes bring cheer,
In CodeRabbit’s realm, magic is here!
🐰✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ab95671 and 85d013c.

📒 Files selected for processing (2)
  • index.js (1 hunks)
  • qbistListeners.js (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 10

🔭 Outside diff range comments (2)
index.js (1)

108-111: 🧹 Nitpick (assertive)

Loading UI initialization is good, but needs fallback handling

The loading overlay initialization code is straightforward, but it doesn't handle cases where the elements might not exist.

Add null checks to prevent errors if elements are missing:

- const loadingOverlay = document.getElementById("loadingOverlay")
- const loadingBar = document.getElementById("loadingBar")
- loadingOverlay.style.display = "none"
+ const loadingOverlay = document.getElementById("loadingOverlay")
+ const loadingBar = document.getElementById("loadingBar")
+ if (loadingOverlay) {
+   loadingOverlay.style.display = "none"
+ }
qbistListeners.js (1)

77-82: 🧹 Nitpick (assertive)

Use Number.parseInt consistently

Maintain consistency by using Number.parseInt in the downloadListener function as well.

Replace global parseInt with Number.parseInt throughout the function:

function downloadListener() {
-  const outputWidth = parseInt(document.getElementById("outputWidth").value)
-  const outputHeight = parseInt(document.getElementById("outputHeight").value)
-  const oversampling = parseInt(document.getElementById("oversampling").value)
+  const outputWidth = Number.parseInt(document.getElementById("outputWidth").value)
+  const outputHeight = Number.parseInt(document.getElementById("outputHeight").value)
+  const oversampling = Number.parseInt(document.getElementById("oversampling").value)
  downloadImage(outputWidth, outputHeight, oversampling)
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 78-78: Use Number.parseInt instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.

(lint/style/useNumberNamespace)


[error] 79-79: Use Number.parseInt instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.

(lint/style/useNumberNamespace)


[error] 80-80: Use Number.parseInt instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.

(lint/style/useNumberNamespace)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 54863a1 and ab95671.

📒 Files selected for processing (6)
  • index.css (1 hunks)
  • index.html (1 hunks)
  • index.js (1 hunks)
  • qbist.js (5 hunks)
  • qbistListeners.js (2 hunks)
  • worker.js (1 hunks)
🧰 Additional context used
🧬 Code Definitions (3)
qbistListeners.js (2)
index.js (7)
  • mainFormula (48-48)
  • mainFormula (48-48)
  • generateFormulas (51-56)
  • updateAll (59-69)
  • canvas (63-63)
  • formulas (47-47)
  • formulas (47-47)
qbist.js (1)
  • createInfo (25-39)
index.js (3)
qbist.js (6)
  • info (26-31)
  • createInfo (25-39)
  • i (83-83)
  • i (125-125)
  • i (136-136)
  • modifyInfo (42-76)
qbistListeners.js (2)
  • oversampling (80-80)
  • loadStateFromParam (36-56)
worker.js (3)
  • progress (12-12)
  • data (5-5)
  • data (7-7)
qbist.js (1)
worker.js (1)
  • optimize (8-8)
🪛 Biome (1.9.4)
qbistListeners.js

[error] 60-60: Use Number.parseInt instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.

(lint/style/useNumberNamespace)

index.js

[error] 17-17: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 63-63: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 47-47: This let declares a variable that is only assigned once.

'formulas' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 48-48: This let declares a variable that is only assigned once.

'mainFormula' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

🔇 Additional comments (15)
index.html (2)

75-80: Loading overlay implementation looks good!

The loading overlay provides excellent user feedback during rendering operations. The HTML structure with container, bar, and message text is well-organized.


83-85: Appropriate conversion to ES modules.

Converting to ES modules is a good architectural improvement that enables better code organization and the ability to use the web worker.

index.css (2)

103-115: Well-structured loading overlay styles.

The loading overlay is properly positioned with fixed positioning and a high z-index to appear above other content. The use of CSS variables for colors maintains theme consistency.


117-129: Nice loading bar implementation with smooth transitions.

The loading bar container and progress indicator are well-styled with appropriate widths and a smooth transition effect for width changes.

qbist.js (1)

25-25: Good use of ES module exports.

Adding the export keyword to these functions is appropriate for enabling their use in the worker and other modules.

Also applies to: 42-42, 80-80, 111-111

index.js (3)

51-56: Formula generation logic looks sound

The formula generation approach is correct, setting the first formula to the main one and creating variations for the rest.


72-80: URL state checking is well implemented

The function to check for URL state parameters is properly implemented with clear return values.


82-87: Initialization logic is clean and effective

The initialization code checks URL state first and falls back to generating new formulas if needed.

qbistListeners.js (7)

1-7: Good modularization with imports from index.js

The file now properly imports the required functions and variables from index.js, supporting the move to ES modules.


9-9: Function export enhances modularity

Exporting the loadStateFromUserInput function improves code organization and reusability.


36-36: Function export enhances modularity

Exporting the loadStateFromParam function allows it to be used in index.js and other modules.


46-46: Using Object.assign preserves additional properties

Using Object.assign instead of direct assignment is a good practice as it preserves any properties in mainFormula that might not be present in stateObj.


53-53: Improved error logging

Adding console.error for detailed error logging while keeping the user-facing alert message simple is a good practice.


61-61: Using Object.assign preserves formula properties

Using Object.assign for updating mainFormula is consistent with the approach used elsewhere in the code.


69-69: Using Object.assign preserves formula properties

Consistent use of Object.assign for mainFormula updates.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Apr 6, 2025

Deploying qbist with  Cloudflare Pages  Cloudflare Pages

Latest commit: 85d013c
Status: ✅  Deploy successful!
Preview URL: https://f46f6a54.qbist.pages.dev
Branch Preview URL: https://move-processing-to-worker.qbist.pages.dev

View logs

shanecranor and others added 3 commits April 6, 2025 11:38
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@shanecranor shanecranor merged commit 95103c3 into main Apr 6, 2025
1 check passed
@shanecranor shanecranor deleted the move-processing-to-worker branch April 6, 2025 16:41
@coderabbitai coderabbitai bot mentioned this pull request Apr 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants