Skip to content

Fix index error#600

Merged
rahulharpal1603 merged 1 commit intoAOSSIE-Org:mainfrom
rahulharpal1603:fix/index-error
Oct 30, 2025
Merged

Fix index error#600
rahulharpal1603 merged 1 commit intoAOSSIE-Org:mainfrom
rahulharpal1603:fix/index-error

Conversation

@rahulharpal1603
Copy link
Contributor

@rahulharpal1603 rahulharpal1603 commented Oct 30, 2025

Fix errors caused due to #599

Summary by CodeRabbit

  • Refactor
    • Restructured media viewer component integration across the application. The media viewer has been removed from the AI Tagging and Home pages. Media viewing functionality remains available on the Person Images page with improved data handling.

@github-actions
Copy link
Contributor

⚠️ No issue was linked in the PR description.
Please make sure to link an issue (e.g., 'Fixes #issue_number')

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 30, 2025

Walkthrough

This PR refactors the MediaView component to receive image data via props rather than Redux selectors. ChronologicalGallery conditionally renders MediaView with images. Some pages remove MediaView integration, while others update calls to pass the images prop.

Changes

Cohort / File(s) Change Summary
MediaView prop refactoring
frontend/src/components/Media/MediaView.tsx, frontend/src/types/Media.ts
Updated MediaView to accept images prop instead of selecting from Redux; added images: Image[] to MediaViewProps interface
ChronologicalGallery integration
frontend/src/components/Media/ChronologicalGallery.tsx
Added Redux selector for isImageViewOpen; conditionally renders MediaView with chronologicallySortedImages prop
Pages removing MediaView
frontend/src/pages/AITagging/AITagging.tsx, frontend/src/pages/Home/Home.tsx
Removed MediaView imports, isImageViewOpen selectors, and modal rendering; eliminated media viewer flow
PersonImages updating call site
frontend/src/pages/PersonImages/PersonImages.tsx
Updated MediaView invocation to pass images prop instead of sourcing from Redux

Sequence Diagram

sequenceDiagram
    participant Gallery as ChronologicalGallery
    participant Redux as Redux Store
    participant MediaView as MediaView Component
    
    Note over Gallery,MediaView: New Flow (Prop-based)
    Gallery->>Redux: selectIsImageViewOpen
    Redux-->>Gallery: boolean (isImageViewOpen)
    alt isImageViewOpen
        Gallery->>Gallery: Pass chronologicallySortedImages<br/>to MediaView via prop
        Gallery->>MediaView: images={chronologicallySortedImages}
        MediaView->>MediaView: Derive totalImages &<br/>currentImage from prop
    end
    
    Note over MediaView: MediaView no longer<br/>directly queries Redux<br/>for image data
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Extra attention areas:
    • Verify MediaView correctly derives totalImages and currentImage from the new images prop across all call sites
    • Confirm PersonImages properly passes the images array and that it contains the expected data structure
    • Validate that ChronologicalGallery's Redux selector integration doesn't create unintended re-render cycles
    • Check that pages removing MediaView (AITagging, Home) don't leave orphaned state or selectors

Possibly related PRs

Suggested labels

frontend, UI

Poem

🐰 From Redux chains to props so free,
MediaView now receives with glee!
Data flows direct, no selectors in sight,
Gallery and Viewer dance in delight,
Refactored with grace, the components unite! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title Check ❓ Inconclusive The pull request title "Fix index error" uses vague terminology that lacks specificity about the actual changes. The changeset shows a significant architectural refactoring where the MediaView component is being updated to accept an images prop instead of using Redux selectors, with corresponding updates across multiple pages (ChronologicalGallery, PersonImages, AITagging, Home, and the Media types). While the PR description references fixing errors from issue #599, the title itself doesn't convey the core nature of these changes—namely, the shift from Redux state management to prop-based data passing for the MediaView component. A developer scanning the commit history would struggle to understand the primary intent from this generic title alone. Consider revising the title to more clearly describe the architectural change, such as "Refactor MediaView to use prop-based image passing instead of Redux selectors" or "Convert MediaView component to accept images prop" to better communicate the core intent of the changeset to team members reviewing the commit history.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

⚠️ No issue was linked in the PR description.
Please make sure to link an issue (e.g., 'Fixes #issue_number')

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 (1)
frontend/src/components/Media/MediaView.tsx (1)

23-35: Implementation is safe, but consider resetting currentViewIndex on images change.

The refactoring correctly shifts from Redux selector to prop-based images, with defensive bounds checking that prevents index errors.

However, there's an architectural coupling: currentViewIndex remains global Redux state while images are now passed per-component. If a user opens MediaView on one page (e.g., index 7 of 10 images), closes it, then navigates to another page with fewer images (e.g., 3 images), the stale index 7 would be out of bounds. The defensive checks at lines 31-34 and 131 prevent crashes by returning null, but MediaView won't display when expected.

Consider resetting currentViewIndex when the images array changes to avoid stale index issues:

+useEffect(() => {
+  // Reset view index if current index is out of bounds for new images array
+  if (currentViewIndex >= images.length) {
+    dispatch(setCurrentViewIndex(-1));
+  }
+}, [images, currentViewIndex, dispatch]);

Alternatively, reset on component mount:

+useEffect(() => {
+  // Reset view on unmount to prevent stale indices
+  return () => {
+    dispatch(setCurrentViewIndex(-1));
+  };
+}, [dispatch]);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 67d2434 and ef16866.

📒 Files selected for processing (6)
  • frontend/src/components/Media/ChronologicalGallery.tsx (3 hunks)
  • frontend/src/components/Media/MediaView.tsx (2 hunks)
  • frontend/src/pages/AITagging/AITagging.tsx (1 hunks)
  • frontend/src/pages/Home/Home.tsx (1 hunks)
  • frontend/src/pages/PersonImages/PersonImages.tsx (1 hunks)
  • frontend/src/types/Media.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
frontend/src/components/Media/MediaView.tsx (1)
frontend/src/types/Media.ts (1)
  • MediaViewProps (34-38)
frontend/src/pages/PersonImages/PersonImages.tsx (1)
frontend/src/components/Media/MediaView.tsx (1)
  • MediaView (23-214)
frontend/src/components/Media/ChronologicalGallery.tsx (4)
frontend/src/features/imageSelectors.ts (1)
  • selectIsImageViewOpen (13-16)
frontend/src/components/Media/ImageCard.tsx (1)
  • ImageCard (19-109)
frontend/src/features/imageSlice.ts (1)
  • setCurrentViewIndex (22-34)
frontend/src/components/Media/MediaView.tsx (1)
  • MediaView (23-214)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Backend Tests
  • GitHub Check: Tauri Build Check (windows-latest)
  • GitHub Check: Tauri Build Check (ubuntu-22.04)
  • GitHub Check: Tauri Build Check (macos-latest, --target aarch64-apple-darwin)
🔇 Additional comments (5)
frontend/src/types/Media.ts (1)

37-37: LGTM! Type definition aligns with the refactoring.

The addition of images: Image[] to MediaViewProps correctly supports the architectural change to pass image data via props rather than Redux selectors.

frontend/src/pages/PersonImages/PersonImages.tsx (1)

124-124: LGTM! Correctly passes images to MediaView.

The images prop aligns with the array used for iteration and index calculation, preventing index mismatches.

frontend/src/pages/AITagging/AITagging.tsx (1)

7-7: LGTM! MediaView functionality preserved through ChronologicalGallery.

The removal of direct MediaView usage is appropriate since ChronologicalGallery now handles MediaView rendering internally, centralizing the viewer logic.

frontend/src/components/Media/ChronologicalGallery.tsx (1)

184-184: MediaView rendering centralized correctly.

The conditional rendering of MediaView with chronologicallySortedImages aligns properly with the index calculations via imageIndexMap, preventing index errors.

Note: If multiple ChronologicalGallery instances were rendered simultaneously on the same page, each would render a MediaView (full-screen modal) when isImageViewOpen is true, which could cause issues. Currently, each page renders only one instance, so this isn't a concern in practice.

frontend/src/pages/Home/Home.tsx (1)

11-11: LGTM! Consistent refactoring pattern.

Removal of direct MediaView usage is appropriate as ChronologicalGallery now manages MediaView rendering, maintaining functionality while centralizing the viewer logic.

@rahulharpal1603 rahulharpal1603 merged commit 8980d72 into AOSSIE-Org:main Oct 30, 2025
9 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