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

fix: minor changes to UI and logic on canvas #150

Merged

Conversation

evgongora
Copy link
Collaborator

@evgongora evgongora commented Feb 14, 2025

Summary by CodeRabbit

  • New Features
    • Enhanced test submission flow that intelligently handles unchanged responses to provide a smoother user experience.
    • Updated insights display with clear loading indicators for visual results and analysis, plus a streamlined share button for quicker social sharing.
    • Revamped results presentation with refined typography and visual effects for a more engaging and polished look.

Copy link
Contributor

coderabbitai bot commented Feb 14, 2025

Walkthrough

This pull request introduces a new environment variable (NEXT_PUBLIC_ENABLE_DEVTOOLS) and updates the initialization logic for the Eruda development tools. It moves the eruda dependency from runtime to development, refines the test submission process in the IdeologyTest page by adding an originalAnswers state and adjusting decision branches, and updates the Insights page to manage separate loading states for canvas and Gemini analysis. Additionally, the ResultsCanvas component gains new props and an asynchronous font-loading function, while provider logic wraps or bypasses Eruda conditions based on the new environment variable.

Changes

File(s) Summary
frontend/.env.example, frontend/src/providers/eruda-provider.tsx, frontend/src/providers/index.tsx Added NEXT_PUBLIC_ENABLE_DEVTOOLS; updated Eruda initialization and provider logic to conditionally wrap children based on the env variable.
frontend/package.json Moved the eruda dependency from dependencies to devDependencies.
frontend/src/app/.../ideology-test/page.tsx Introduced the originalAnswers state and refined the submission flow to check for existing insights and changes in answers before calculating scores.
frontend/src/app/.../insights/page.tsx Added state variables (isCanvasLoading, isGeminiLoading) for loading feedback, separated Gemini API calls into its own effect, removed the downloadImage function, and updated share functionality.
frontend/src/components/Canvas.tsx Extended the ResultsCanvas component with new props (ideology, optional onLoad), added an asynchronous font-loading function, and updated drawing operations and layout details.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant IdeologyTest
    participant API
    participant Navigation
    User->>IdeologyTest: Submit test
    IdeologyTest->>API: Fetch existing insights and answers
    alt Insights exist and answers unchanged
        IdeologyTest->>Navigation: Redirect to Insights page
    else Insights missing or answers changed
        IdeologyTest->>IdeologyTest: Calculate scores
        IdeologyTest->>API: Create/Update insights
        IdeologyTest->>Navigation: Redirect with updated insights
    end
Loading
sequenceDiagram
    participant App
    participant ErudaProvider
    participant Eruda
    App->>ErudaProvider: Render children
    ErudaProvider->>ErudaProvider: Check NEXT_PUBLIC_ENABLE_DEVTOOLS env variable
    alt DevTools Enabled
        ErudaProvider->>Eruda: Initialize eruda library
        Eruda->>ErudaProvider: Confirm initialization
        ErudaProvider->>App: Wrap children with Eruda
    else DevTools Disabled
        ErudaProvider->>App: Render children without Eruda
    end
Loading

Possibly related PRs

Suggested reviewers

  • bitfalt

Poem

Hop along the code, I cheer with delight,
New env vars and state flows make our code bright.
Eruda springs to life when dev mode is true,
Tests and canvases refresh with a vibrant new view.
I, the rabbit, hop through the changes with glee!
🥕💻


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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

netlify bot commented Feb 14, 2025

Deploy Preview for lucent-florentine-971919 ready!

Name Link
🔨 Latest commit f98fd77
🔍 Latest deploy log https://app.netlify.com/sites/lucent-florentine-971919/deploys/67af61083752020008da2076
😎 Deploy Preview https://deploy-preview-150--lucent-florentine-971919.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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: 0

🧹 Nitpick comments (6)
frontend/src/app/ideology-test/page.tsx (2)

72-72: Securing originalAnswers assignment.
Storing the server-sourced answers in originalAnswers is correct to allow comparison. Just ensure no concurrency issues when multiple updates could overwrite originalAnswers.


175-189: Handling multiple scenarios for final result submission is well-structured.

  1. Redirect if no changes and insights exist.
  2. Create new insights if none exist.
  3. Update (PUT) if user's answers changed.

Consider returning to a consistent code path or refactoring these into smaller functions to keep the logic DRY, especially if new scenarios arise.

frontend/src/components/Canvas.tsx (3)

21-41: Font loading function is robust, but consider parallelizing.
The current approach ensures the font is fetched before continuing. You could potentially reduce wait time with a Promise.all approach if you load images in parallel.


85-98: Canvas dimension setting is explicit but watch for high-resolution screens.
You might want to account for window.devicePixelRatio to provide crisper rendering on Retina/HiDPI displays.


99-105: Debug font rendering usage.
Including a prototype text measurement is fine for debugging. Consider removing or gating logs in production if this is only for troubleshooting.

frontend/src/app/insights/page.tsx (1)

551-559: Consider using React state management instead of script injection.

The current implementation uses script injection to emit modal state. Consider using React's state management or a context provider instead.

-      <script
-        dangerouslySetInnerHTML={{
-          __html: `
-            window.dispatchEvent(new CustomEvent('modalState', { 
-              detail: { isOpen: ${isModalOpen} }
-            }));
-          `,
-        }}
-      />
+      <ModalStateProvider isOpen={isModalOpen} />
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 91c5edc and f98fd77.

⛔ Files ignored due to path filters (1)
  • frontend/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • frontend/.env.example (1 hunks)
  • frontend/package.json (1 hunks)
  • frontend/src/app/ideology-test/page.tsx (7 hunks)
  • frontend/src/app/insights/page.tsx (8 hunks)
  • frontend/src/components/Canvas.tsx (8 hunks)
  • frontend/src/providers/eruda-provider.tsx (1 hunks)
  • frontend/src/providers/index.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Code Quality & Build
🔇 Additional comments (15)
frontend/src/app/ideology-test/page.tsx (5)

31-31: Good addition of originalAnswers state.
Helps track the baseline answers for comparison, which is crucial for determining if the user has updated their responses.


53-58: Ensure consistent completion logic.
When the test status is "completed", the immediate redirect to Insights is fine. However, consider whether there's any scenario (e.g., user reopened the test page in a new tab) where partial data might need reconciling before redirect.


101-101: Preventing double submission is good.
Avoiding multiple simultaneous submissions reduces the risk of data inconsistencies or duplicate results. Confirm that other interactions (e.g., handleAnswer calls) also gracefully check isSubmitting.


116-116: Early score calculation is clear and logical.
Computing the final scores before branching into scenarios helps ensure you don’t recalculate or produce partial updates.


146-155: Insight existence and answer change checks look solid.
This is an essential guard to avoid unnecessary writes. Confirm you have server-side checks to handle edge cases (e.g., stale data).

frontend/src/components/Canvas.tsx (4)

9-11: New props ideology and onLoad add flexibility.
Being able to pass an ideology string and an optional callback is a clean separation of concerns.


277-288: Extra spacing and text box for ideology look good.
The gradient styling complements the UI. Just confirm that very long ideologies (e.g., long text) remain visible without clipping.


316-356: Closest match display is consistent with the layout.
The design uses a highlight box and subtle glow. This ensures brand consistency—nice approach.


358-389: CTA button design is appealing.
The spacing and text alignment appear correct. Great call on calling onLoad?.() after drawing completes, letting parent components respond to the finished render.

frontend/src/providers/index.tsx (1)

15-15: Environment-based conditional is correct.
Switching from the old environment variable to NEXT_PUBLIC_ENABLE_DEVTOOLS is a clean approach. Make sure to document usage for other devs.

frontend/src/providers/eruda-provider.tsx (1)

13-13:

✅ Verification successful

LGTM! Environment-based control for development tools.

The addition of the environment variable check improves control over when development tools are initialized.

Verify the environment variable is properly set in your development environment:


🏁 Script executed:

#!/bin/bash
# Check if NEXT_PUBLIC_ENABLE_DEVTOOLS is set in .env files
echo "Checking .env files for NEXT_PUBLIC_ENABLE_DEVTOOLS..."
fd -t f "^\.env" -x grep -l "NEXT_PUBLIC_ENABLE_DEVTOOLS"

Length of output: 384


Below is a revised shell script that ensures hidden files are included in the search. Please run it to verify that your hidden .env files correctly set the NEXT_PUBLIC_ENABLE_DEVTOOLS variable:

LGTM! Environment-based control for development tools is a solid addition.
The change to add an environment variable check improves the conditional initialization of Eruda. However, please verify your setup by running the above script to confirm that hidden .env files (which typically contain environment configurations) include the NEXT_PUBLIC_ENABLE_DEVTOOLS variable.


🏁 Script executed:

[run_scripts]
#!/bin/bash
echo "Searching hidden .env files for NEXT_PUBLIC_ENABLE_DEVTOOLS using -H flag..."
fd -H -t f "^\.env" -x grep -l "NEXT_PUBLIC_ENABLE_DEVTOOLS"

Length of output: 369


LGTM! Environment-based control for development tools is well implemented. The change ensures Eruda is initialized only when the NEXT_PUBLIC_ENABLE_DEVTOOLS variable is set to "true". The updated verification script confirms that the variable is present in your .env.example file. Please ensure that your actual development configuration (e.g., in .env.local or similar) also sets NEXT_PUBLIC_ENABLE_DEVTOOLS appropriately.

frontend/src/app/insights/page.tsx (2)

40-41: LGTM! Added loading states for better UX.

The addition of separate loading states for canvas and Gemini analysis improves user experience by providing clear feedback.


113-154: LGTM! Separated Gemini API call for better code organization.

Moving the Gemini API call to a separate effect improves code organization and maintainability.

frontend/.env.example (1)

23-26: LGTM! Well-documented environment variables.

The addition of NODE_ENV and NEXT_PUBLIC_ENABLE_DEVTOOLS with clear comments improves configuration documentation.

frontend/package.json (1)

48-48: LGTM! Correctly moved eruda to devDependencies.

Moving eruda to devDependencies is appropriate as it's a development tool.

@evgongora evgongora merged commit 4d89e8e into MindVault-Inc:main Feb 14, 2025
8 checks passed
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.

1 participant