Skip to content

feat: enhance drawing functionality with file support#33

Merged
macintushar merged 1 commit intomacintushar:mainfrom
sedationh:main
Jul 14, 2025
Merged

feat: enhance drawing functionality with file support#33
macintushar merged 1 commit intomacintushar:mainfrom
sedationh:main

Conversation

@sedationh
Copy link
Contributor

@sedationh sedationh commented Jul 10, 2025

  • Added support for BinaryFiles in ExcalidrawData type.
  • Updated createNewPage and setDrawData functions to handle files.
  • Modified drawDataStore to include files in state management.
  • Enhanced Mermaid and Page components to manage file uploads and updates.
support.image.mov

Summary by CodeRabbit

  • New Features

    • Added support for saving and loading binary files (such as images) alongside drawings. Files are now persisted and restored with each drawing page.
  • Bug Fixes

    • Ensured that changes to files are detected and saved, preventing loss of associated files during updates.

- Added support for BinaryFiles in ExcalidrawData type.
- Updated createNewPage and setDrawData functions to handle files.
- Modified drawDataStore to include files in state management.
- Enhanced Mermaid and Page components to manage file uploads and updates.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 10, 2025

Walkthrough

The changes integrate support for handling and persisting binary files within Excalidraw scenes. Relevant types and function signatures are updated to include an optional files property, and logic in the store and UI components is extended to save, load, and synchronize both drawing elements and associated binary files.

Changes

File(s) Change Summary
src/db/draw.ts Added ExcalidrawData type with optional files; updated createNewPage and setDrawData to handle files.
src/stores/drawDataStore.ts Extended DrawData and DrawDataStore to support optional files; updated setPageData accordingly.
src/views/Mermaid.tsx Modified handleSaveAsNewPage to pass both elements and files to createNewPage.
src/views/Page.tsx Updated to load, save, and synchronize binary files with Excalidraw scenes; updated mutation and store logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Excalidraw
    participant PageComponent
    participant Store
    participant DB

    User->>Excalidraw: Edits scene (elements, files)
    Excalidraw->>PageComponent: getSceneElements(), getFiles()
    PageComponent->>Store: setPageData(page_id, elements, name, files)
    PageComponent->>DB: setDrawData(id, elements, name, files)
    DB-->>PageComponent: Save confirmation
    Store-->>PageComponent: State updated
    PageComponent->>Excalidraw: addFiles(files) (on load)
Loading

Poem

A bunny with bytes and brushes anew,
Now saves your files with sketches too.
Drawings and doodles, all bundled tight,
In Excalidraw’s warren, your files take flight!
With a hop and a save, your art’s complete—
Binary treasures and lines so neat.
🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c5480e1 and 33a4e4c.

📒 Files selected for processing (4)
  • src/db/draw.ts (4 hunks)
  • src/stores/drawDataStore.ts (5 hunks)
  • src/views/Mermaid.tsx (1 hunks)
  • src/views/Page.tsx (5 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/views/Mermaid.tsx (1)
src/db/draw.ts (1)
  • createNewPage (40-57)
src/db/draw.ts (1)
src/db/supabase.ts (1)
  • supabase (6-6)
🔇 Additional comments (19)
src/views/Mermaid.tsx (1)

61-62: LGTM! Clean integration of file support.

The addition of file retrieval and passing to createNewPage is consistent with the updated function signature and maintains the existing error handling pattern.

src/stores/drawDataStore.ts (4)

2-2: LGTM! Proper import addition.

The BinaryFiles import is correctly added to support the new file handling functionality.


11-11: LGTM! Backward-compatible type extension.

The optional files property maintains backward compatibility while extending the DrawData type to support binary files.


22-22: LGTM! Consistent method signature update.

The setPageData method signature correctly includes the optional files parameter, maintaining consistency with the updated type definition.


31-41: LGTM! Proper state management implementation.

The implementation correctly includes files in the state update while maintaining the existing timestamp comparison logic for determining when to update the state.

src/views/Page.tsx (8)

15-15: LGTM! Correct import addition.

The BinaryFiles import is properly added to support the new file handling functionality.


41-42: LGTM! Consistent mutation signature update.

The mutation function signature correctly includes the optional files parameter and properly passes it to the setDrawData function.


58-70: LGTM! Proper file handling in scene updates.

The implementation correctly extracts files from page data and safely adds them to the Excalidraw instance only when files exist, preventing unnecessary API calls.


82-82: LGTM! Consistent file retrieval.

Files are properly retrieved from the Excalidraw API, maintaining consistency with the element retrieval pattern.


87-88: LGTM! Comprehensive change detection.

The comparison logic correctly checks for changes in both elements and files, ensuring that file modifications trigger saves appropriately.


91-91: LGTM! Consistent store update.

The setPageData call correctly includes files alongside other parameters, maintaining consistency with the updated store interface.


98-98: LGTM! Complete mutation payload.

Files are properly included in the mutation payload, ensuring they are persisted to the database.


134-137: LGTM! Proper local file restoration.

The implementation correctly restores files from local storage when available, maintaining consistency with the server-side file handling.

src/db/draw.ts (6)

2-2: LGTM! Correct import addition.

The BinaryFiles import is properly added to support the new file handling functionality in the database layer.


12-16: LGTM! Well-structured data type definition.

The ExcalidrawData type properly encapsulates the drawing data structure with optional appState and files properties, providing a clean interface for database operations.


42-42: LGTM! Consistent function signature update.

The createNewPage function signature correctly includes the optional files parameter, maintaining backward compatibility.


46-49: LGTM! Proper data structure construction.

The ExcalidrawData object is correctly constructed with sensible defaults (empty array for elements, empty object for files) when parameters are not provided.


63-63: LGTM! Consistent parameter addition.

The setDrawData function signature correctly includes the optional files parameter, maintaining consistency with the createNewPage function.


66-69: LGTM! Consistent data handling.

The ExcalidrawData object construction follows the same pattern as in createNewPage, ensuring consistent data structure across database operations.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

@vercel
Copy link

vercel bot commented Jul 10, 2025

@sedationh is attempting to deploy a commit to the Tushar Selvakumar's projects Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Jul 10, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
draw ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 10, 2025 1:47pm

@sedationh
Copy link
Contributor Author

#12

@macintushar
Copy link
Owner

@sedationh this is awesome! I'll just test it out and make sure nothing is breaking with previous pages before merging.

@macintushar
Copy link
Owner

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 10, 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.

@macintushar macintushar merged commit 9438a94 into macintushar:main Jul 14, 2025
5 checks passed
@macintushar
Copy link
Owner

@sedationh just finished testing, seems to work properly. Thank you for contributing!

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