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 Camera Capture and Upload Workflow #10326

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

rajku-dev
Copy link
Contributor

@rajku-dev rajku-dev commented Jan 31, 2025

Proposed Changes

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

  • New Features

    • Introduced an optional setPreview callback in the camera capture dialog for managing preview state.
    • Enhanced file upload functionality with a new condition for opening the upload dialog based on preview state.
  • Bug Fixes

    • Improved dialog visibility and file upload logic.
  • Improvements

    • Added state management for tracking the preview state during file uploads.

@rajku-dev rajku-dev requested a review from a team as a code owner January 31, 2025 03:57
Copy link
Contributor

coderabbitai bot commented Jan 31, 2025

Walkthrough

The pull request introduces changes to the camera capture and file upload workflow across multiple components. The modifications enhance the interaction between the CameraCaptureDialog, FilesTab, and useFileUpload hook by adding an optional setPreview callback, managing the preview state, and refining the logic for opening the upload dialog. These changes aim to provide a more intuitive file upload experience by allowing better control over the submission process and file preview.

Changes

File Change Summary
src/components/Files/CameraCaptureDialog.tsx Added optional setPreview callback to CameraCaptureDialogProps interface and invoked it in button click handlers.
src/components/Files/FilesTab.tsx Modified upload dialog opening logic to include check for fileUpload.previewing being false. Updated useEffect dependency array to include fileUpload.previewing.
src/hooks/useFileUpload.tsx Added previewing state to FileUploadReturn type, initialized previewing state variable, and updated handleUpload function to manage modal behavior post-upload.

Assessment against linked issues

Objective Addressed Explanation
Capture and preview image
Display file name submission pop-up The changes do not include functionality for showing a pop-up for file name submission after capturing an image.
Automatic pop-up closure after submission The changes do not address automatic closure of the pop-up after submission.
Improve camera capture workflow

Possibly related PRs

Suggested labels

needs review, tested

Suggested reviewers

  • Jacobjeevan
  • rithviknishad

Poem

🐰 In the land of code, where images play,
A rabbit hops forth, to brighten the day.
With toggles and previews, the workflow's a breeze,
Capturing moments, with joy and with ease!
So let’s upload swiftly, with a click and a cheer,
For every new file brings us closer, my dear! 📸✨


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 Jan 31, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 1a193d7
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/679c9369bb68040008a44e29
😎 Deploy Preview https://deploy-preview-10326--care-ohc.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 (2)
src/components/Files/CameraCaptureDialog.tsx (1)

178-178: Consider using optional chaining.

The onSubmit callback invocation can be simplified using optional chaining.

-    onSubmit && onSubmit();
+    onSubmit?.();

Also applies to: 244-244

🧰 Tools
🪛 Biome (1.9.4)

[error] 178-178: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

src/hooks/useFileUpload.tsx (1)

Line range hint 282-291: Consider adding error details to the toast message.

The error handling could be improved by including more specific error details in the toast message.

-      } catch {
+      } catch (error) {
         errors.push(file);
+        const errorMessage = error instanceof Error ? error.message : String(error);
+        setError(t("file_error__network") + `: ${errorMessage}`);
       }
     }
 
     setUploading(false);
     setFiles(errors);
     setUploadFileNames(errors?.map((f) => f.name) ?? []);
-    setError(t("file_error__network"));
     setSubmitClicked(false);
     setCameraModalOpen(false);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fd9f145 and f413bfc.

📒 Files selected for processing (3)
  • src/components/Files/CameraCaptureDialog.tsx (3 hunks)
  • src/components/Files/FilesTab.tsx (2 hunks)
  • src/hooks/useFileUpload.tsx (7 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/Files/CameraCaptureDialog.tsx

[error] 178-178: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 244-244: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)
🔇 Additional comments (8)
src/components/Files/CameraCaptureDialog.tsx (2)

19-19: LGTM! Well-typed optional callback.

The onSubmit callback is properly typed as an optional function.


23-23: LGTM! Proper destructuring of props.

The onSubmit callback is properly destructured from props.

src/hooks/useFileUpload.tsx (4)

65-65: LGTM! Well-typed return type.

The submitClicked state is properly typed as an optional boolean in the return type.


97-97: LGTM! Proper state initialization.

The submitClicked state is properly initialized with useState(false).


311-313: LGTM! Proper state management in onSubmit handler.

The submitClicked state is properly set to true in the onSubmit handler.


368-368: LGTM! State properly exposed in return value.

The submitClicked state is properly exposed in the hook's return value.

src/components/Files/FilesTab.tsx (2)

160-169: LGTM! Proper dialog open condition.

The upload dialog open condition properly checks for:

  • Files presence
  • First file existence
  • Submit button click state

592-592: LGTM! Improved dialog layout.

The dialog content layout is improved with:

  • Increased vertical spacing
  • Maximum height constraint
  • Proper overflow handling

@rajku-dev rajku-dev changed the title Fix File Capture and Upload Workflow Fix Camera Capture and Upload Workflow Jan 31, 2025
@nihal467
Copy link
Member

@rajku-dev is it ready to be reviewed

@nihal467
Copy link
Member

image

@rajku-dev the normal file upload is not working now

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 (3)
src/components/Files/CameraCaptureDialog.tsx (3)

152-154: Consider using optional chaining for better readability.

Replace the logical AND operator with optional chaining:

-                    togglePreview && togglePreview();
+                    togglePreview?.();
🧰 Tools
🪛 Biome (1.9.4)

[error] 153-153: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


219-221: Consider using optional chaining for better readability.

Replace the logical AND operator with optional chaining:

-                      togglePreview && togglePreview();
+                      togglePreview?.();
🧰 Tools
🪛 Biome (1.9.4)

[error] 220-220: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


244-246: Consider using optional chaining for better readability.

Replace the logical AND operator with optional chaining:

-                      togglePreview && togglePreview();
+                      togglePreview?.();
🧰 Tools
🪛 Biome (1.9.4)

[error] 245-245: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a7df48e and bd81014.

📒 Files selected for processing (3)
  • src/components/Files/CameraCaptureDialog.tsx (4 hunks)
  • src/components/Files/FilesTab.tsx (1 hunks)
  • src/hooks/useFileUpload.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/Files/FilesTab.tsx
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/Files/CameraCaptureDialog.tsx

[error] 153-153: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 220-220: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 245-245: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)
🔇 Additional comments (4)
src/components/Files/CameraCaptureDialog.tsx (1)

19-19: LGTM! Clean interface extension.

The addition of the optional togglePreview callback maintains backward compatibility while enabling preview state management.

Also applies to: 23-23

src/hooks/useFileUpload.tsx (3)

64-64: LGTM! Clean type extension.

The addition of the optional previewing property maintains backward compatibility while supporting the preview state management feature.


96-96: LGTM! Clean state management implementation.

The preview state is properly initialized and follows React best practices.


308-308: LGTM! Clean integration of preview state management.

The preview state is properly toggled and exposed through the hook's return value.

Also applies to: 363-363

@rajku-dev
Copy link
Contributor Author

rajku-dev commented Jan 31, 2025

image

@rajku-dev the normal file upload is not working now

missed self-testing this one, but handled in the latest changes.

@rajku-dev
Copy link
Contributor Author

rajku-dev commented Jan 31, 2025

@rajku-dev is it ready to be reviewed

Yes, I've handled pretty much every edge cases. Could you please test it from your end and let me know if any further changes are required.
Thank you

@github-actions github-actions bot added needs-triage question Further information is requested labels Jan 31, 2025
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 (2)
src/components/Files/CameraCaptureDialog.tsx (2)

153-153: Use optional chaining for better code style.

Replace setPreview && setPreview(...) with optional chaining for cleaner code.

-                    setPreview && setPreview(true);
+                    setPreview?.(true);
-                    setPreview && setPreview(false);
+                    setPreview?.(false);
-                    setPreview && setPreview(true);
+                    setPreview?.(true);

Also applies to: 169-169, 180-180

🧰 Tools
🪛 Biome (1.9.4)

[error] 153-153: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


222-222: Use optional chaining for laptop screen button handlers.

Similar to mobile screen buttons, use optional chaining for cleaner code.

-                      setPreview && setPreview(true);
+                      setPreview?.(true);
-                      setPreview && setPreview(false);
+                      setPreview?.(false);
-                      setPreview && setPreview(false);
+                      setPreview?.(false);
-              setPreview && setPreview(false);
+              setPreview?.(false);

Also applies to: 238-238, 248-248, 264-264

🧰 Tools
🪛 Biome (1.9.4)

[error] 222-222: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bd81014 and 1a193d7.

📒 Files selected for processing (2)
  • src/components/Files/CameraCaptureDialog.tsx (8 hunks)
  • src/hooks/useFileUpload.tsx (5 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/Files/CameraCaptureDialog.tsx

[error] 153-153: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 169-169: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 180-180: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 222-222: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 238-238: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 248-248: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 264-264: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (4)
src/components/Files/CameraCaptureDialog.tsx (1)

19-19: LGTM! Good addition of the optional preview callback.

The optional setPreview callback in the props interface maintains backward compatibility while enabling preview state management.

src/hooks/useFileUpload.tsx (3)

64-64: LGTM! Good addition of the preview state to the return type.

The optional previewing property in FileUploadReturn allows consumers to react to the preview state while maintaining backward compatibility.


96-96: LGTM! Clean implementation of preview state.

The preview state management follows React best practices with appropriate initial state.


290-290: LGTM! Well-integrated preview state management.

The preview state is properly integrated with:

  • Camera modal cleanup after upload
  • Preview state passed to CameraCaptureDialog
  • Preview state exposed to consumers

Also applies to: 308-308, 363-363

@nihal467
Copy link
Member

nihal467 commented Jan 31, 2025

image

  • in the mobile view post clicking the photo and submitting it, the file name popup is not coming up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Camera Capture and Upload Workflow Not Functioning as Expected
2 participants