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

dev: Add drag and drop, fixes and review are still needed #78

Merged
merged 3 commits into from
Jan 29, 2025

Conversation

cosmin42
Copy link
Owner

@cosmin42 cosmin42 commented Jan 28, 2025

Summary by CodeRabbit

  • New Features

    • Added image mapping functionality across multiple components.
    • Enhanced drag-and-drop capabilities for images.
    • Introduced new methods to handle image mapping events.
    • Added a new class for managing and displaying staged images.
  • Improvements

    • Updated UI components to support new image interaction features.
    • Added visual borders to scrollable image views.
    • Introduced a method to retrieve the selected index of media items.
  • Technical Enhancements

    • Expanded image handling protocols and interfaces.
    • Introduced new data decoding and mapping mechanisms.

Copy link

coderabbitai bot commented Jan 28, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request introduces a new image mapping functionality across multiple files in the PhotoBook application. The changes primarily focus on adding methods to handle image mapping events, enabling drag-and-drop capabilities, and enhancing the interaction between frontend and backend image representations. The modifications span Swift, Objective-C, and header files, creating a consistent mechanism for tracking and processing images within the application's architecture.

Changes

File Change Summary
osx/PhotoBook/PhotoBook/Pages/DashboardView.swift Added onImageMapped method to handle image mapping events
osx/PhotoBook/PhotoBook/Pages/PhotoBookApp.swift Added onImageMapped method to PhotobookListenerWrapperCLevel and PhotoBookApp
osx/PhotoBook/PhotoBook/Pages/TableContentView.swift Added decodeData method for dropped items and onImageMapped method
osx/PhotoBook/PhotoBook/Photobook.h Added new method declarations for image mapping in PhotobookListenerWrapperCLevel and Photobook interfaces
osx/PhotoBook/PhotoBook/Photobook.mm Implemented mapImagesToSPL method and updated onImageMapped method
osx/PhotoBook/PhotoBook/PhotobookUIListener.swift Added onImageMapped method to the PhotobookUIListener protocol
osx/PhotoBook/PhotoBook/UPL/UPLIdentifier.swift New class for handling drag-and-drop identifiers
osx/PhotoBook/PhotoBook/Wrappers/FrontendImage/FrontendImage.h Added unwrap method declaration
osx/PhotoBook/PhotoBook/Wrappers/FrontendImage/FrontendImage.mm Implemented unwrap method to return C++ image pointer
osx/PhotoBook/PhotoBook/Media/MediaList.swift Added selectedIndex method to return the index of the selected media item
osx/PhotoBook/PhotoBook/SPL/StagedPhotoLine.swift Introduced StagedPhotoLineModel and StagedPhotoLine for managing and displaying images

Possibly related PRs

  • Cosmin/refactor image model #73: The onImageMapped(imageId: String, image: FrontendImage) method is added in both the main PR and the PhotobookListenerWrapperCLevel extension in PhotoBookApp.swift, indicating a direct relationship in handling image mapping events.

Poem

🐰 A Rabbit's Ode to Image Mapping 🖼️

Drag and drop with playful might,
Images dancing, pixel-bright
Mapping magic, code so neat
Swift and C++ now complete!
A photobook adventure sweet 🎉


📜 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 067e1e9 and ea67285.

📒 Files selected for processing (8)
  • PB/third-party/osx/skia/x86_64/all.xcodeproj/xcuserdata/cosminmihai.xcuserdatad/xcschemes/xcschememanagement.plist (1 hunks)
  • osx/PhotoBook/PhotoBook.xcodeproj/xcuserdata/cosminmihai.xcuserdatad/xcschemes/xcschememanagement.plist (1 hunks)
  • osx/PhotoBook/PhotoBook/Media/MediaList.swift (1 hunks)
  • osx/PhotoBook/PhotoBook/Pages/PhotoBookApp.swift (2 hunks)
  • osx/PhotoBook/PhotoBook/Pages/TableContentView.swift (5 hunks)
  • osx/PhotoBook/PhotoBook/SPL/StagedPhotoLine.swift (1 hunks)
  • osx/PhotoBook/PhotoBook/UPL/UPLIdentifier.swift (1 hunks)
  • osx/PhotoBook/PhotoBook/UPL/UnstagedPhotoLine.swift (3 hunks)

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

@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: 3

🔭 Outside diff range comments (1)
osx/PhotoBook/PhotoBook/Photobook.h (1)

Line range hint 35-50: Fix inconsistent method naming conventions.

The interface has mixed naming conventions:

  • Some methods use PascalCase: NewProject, RecallMetadata
  • Others use camelCase: startPhotobook, generateProjectName

This inconsistency is noted in the TODO comment. Let's fix it by using consistent camelCase as per Objective-C conventions.

- (void) startPhotobook;
- (NSString*) generateProjectName;
-- (void) NewProject:(PaperSettings*)paperSettings;
-- (void) RecallMetadata;
+- (void) newProject:(PaperSettings*)paperSettings;
+- (void) recallMetadata;
🧹 Nitpick comments (9)
osx/PhotoBook/PhotoBook/PhotobookUIListener.swift (1)

15-15: Remove trailing semicolon to follow Swift conventions.

Swift doesn't require semicolons at the end of statements. Remove it to maintain consistency with Swift idioms.

-    func onImageMapped(imageId: String, image: FrontendImage)
+    func onImageMapped(imageId: String, image: FrontendImage)
🧰 Tools
🪛 SwiftLint (0.57.0)

[Warning] 15-15: Lines should not have trailing semicolons

(trailing_semicolon)

osx/PhotoBook/PhotoBook/Wrappers/FrontendImage/FrontendImage.mm (1)

9-9: Remove unused import.

The UniformTypeIdentifiers framework import appears to be unused in this file.

-#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
osx/PhotoBook/PhotoBook/UPL/UPLIdentifier.swift (2)

15-15: Remove trailing semicolon to follow Swift conventions.

Swift doesn't require semicolons at the end of statements.

-    public var row:UInt = 0;
+    public var row: UInt = 0

11-22: Add documentation for public API.

Since this is a new class implementing drag & drop functionality, please add documentation comments explaining:

  • The purpose of the class
  • Usage examples
  • Parameter descriptions
  • Threading considerations

Example:

/// Represents a unique identifier for drag & drop operations in UPL (User Placement Layout).
/// This class enables drag & drop functionality by implementing necessary protocols and
/// providing serialization support.
///
/// Example usage:
/// ```
/// let identifier = UPLIdentifier(row: 1, indices: [0, 1])
/// ```
class UPLIdentifier: NSObject, Identifiable, NSItemProviderWriting, Encodable, Decodable {
    /// Unique identifier for the instance
    let id = UUID()
    
    /// The row number in the layout grid
    public var row: UInt = 0
    /// Indices representing positions within the row
    public var indices: [UInt]
    
    /// Creates a new UPL identifier
    /// - Parameters:
    ///   - row: The row number in the layout grid
    ///   - indices: Array of indices representing positions within the row
    init(row: UInt, indices: [UInt]) {
        self.row = row
        self.indices = indices
    }
}
osx/PhotoBook/PhotoBook/Photobook.h (2)

50-50: Add documentation for the new image mapping method.

The new method mapImagesToSPL lacks documentation about its purpose and usage.

+/**
+ * Maps images to the SPL (Service Placement Layout) system.
+ *
+ * @param images Dictionary mapping image identifiers to their corresponding FrontendImage objects
+ */
- (void) mapImagesToSPL:(NSDictionary<NSString*, FrontendImage*>*)images;

24-24: Add documentation for the image mapping callback.

The new listener method onImageMapped lacks documentation about when it's called and what the parameters represent.

+/**
+ * Called when an image has been successfully mapped in the system.
+ *
+ * @param imageId Unique identifier for the mapped image
+ * @param image The frontend representation of the mapped image
+ */
- (void)onImageMapped:(NSString*)imageId image:(FrontendImage*)image;
osx/PhotoBook/PhotoBook/UPL/UnstagedPhotoLine.swift (1)

39-41: Add error handling and visual feedback for drag operation.

The drag implementation needs enhancement:

  1. Add error handling for the index conversion to UInt
  2. Provide visual feedback during drag operation
 .onDrag {
-    NSItemProvider(object: UPLIdentifier(row:0, indices:[UInt(index)]))
+    if index >= 0 {
+        let provider = NSItemProvider(object: UPLIdentifier(row:0, indices:[UInt(index)]))
+        withAnimation {
+            // Add visual feedback here
+        }
+        return provider
+    }
+    return NSItemProvider()
 }
osx/PhotoBook/PhotoBook/Pages/PhotoBookApp.swift (2)

38-42: Add null check and documentation for the image mapping handler.

The new method follows the existing pattern but could be improved:

  1. Add a null check before accessing the last listener to prevent crashes
  2. Consider documenting the method's purpose and parameters
  3. Consider whether other listeners in the array should also receive this event
+    /// Notifies listeners when an image has been mapped to a specific ID
+    /// - Parameters:
+    ///   - imageId: The unique identifier for the mapped image
+    ///   - image: The frontend representation of the mapped image
     func onImageMapped(imageId: String, image: FrontendImage)
     {
+        guard let listener = photobookUIListener.last else { return }
-        photobookUIListener.last?.onImageMapped(imageId:imageId, image: image)
+        listener.onImageMapped(imageId:imageId, image: image)
     }

Line range hint 9-10: Consider refactoring the listener implementation pattern.

The current implementation using global arrays and push/pop methods has several architectural concerns:

  1. Global mutable state can lead to thread-safety issues and makes testing difficult
  2. The stack-based listener pattern might be better implemented using a proper observer pattern
  3. Consider moving listener management to a dedicated service class

Consider refactoring to a more robust pattern:

// Create a dedicated service
class ListenerService {
    private var listeners = [PhotobookUIListener]()
    
    func addListener(_ listener: PhotobookUIListener) {
        listeners.append(listener)
    }
    
    func removeListener(_ listener: PhotobookUIListener) {
        if let index = listeners.firstIndex(where: { $0 === listener }) {
            listeners.remove(at: index)
        }
    }
    
    func notifyImageMapped(imageId: String, image: FrontendImage) {
        listeners.forEach { $0.onImageMapped(imageId: imageId, image: image) }
    }
}

Also applies to: 122-131

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a82394b and 067e1e9.

📒 Files selected for processing (11)
  • osx/PhotoBook/PhotoBook/Pages/DashboardView.swift (1 hunks)
  • osx/PhotoBook/PhotoBook/Pages/PhotoBookApp.swift (2 hunks)
  • osx/PhotoBook/PhotoBook/Pages/TableContentView.swift (4 hunks)
  • osx/PhotoBook/PhotoBook/Photobook.h (3 hunks)
  • osx/PhotoBook/PhotoBook/Photobook.mm (3 hunks)
  • osx/PhotoBook/PhotoBook/PhotobookUIListener.swift (1 hunks)
  • osx/PhotoBook/PhotoBook/UPL/UPLIdentifier.swift (1 hunks)
  • osx/PhotoBook/PhotoBook/UPL/UnstagedPhotoLine.swift (2 hunks)
  • osx/PhotoBook/PhotoBook/Wrappers/FrontendImage/FrontendImage.h (1 hunks)
  • osx/PhotoBook/PhotoBook/Wrappers/FrontendImage/FrontendImage.mm (2 hunks)
  • osx/PhotoBook/PhotoBook/Wrappers/FrontendImage/FrontendImageExtension.swift (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • osx/PhotoBook/PhotoBook/Wrappers/FrontendImage/FrontendImageExtension.swift
🧰 Additional context used
🪛 SwiftLint (0.57.0)
osx/PhotoBook/PhotoBook/PhotobookUIListener.swift

[Warning] 15-15: Lines should not have trailing semicolons

(trailing_semicolon)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build and analyze default scheme using xcodebuild command
  • GitHub Check: Build and analyze default scheme using xcodebuild command
🔇 Additional comments (8)
osx/PhotoBook/PhotoBook/Wrappers/FrontendImage/FrontendImage.h (1)

30-32: LGTM, but needs documentation.

The unwrap method is well-placed and follows the established pattern for C++ interop. However, please add documentation to clarify:

  • The method's purpose
  • Ownership semantics of the returned pointer
  • Any preconditions or side effects

Let's verify the memory management implications:

✅ Verification successful

Documentation needed for unwrap method

The unwrap method is memory-safe as it returns a shared_ptr-managed pointer. Please add documentation to clarify:

  • Returns the underlying C++ image object
  • Ownership is shared (managed by shared_ptr)
  • No preconditions required
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for memory management patterns in the codebase

# Look for ownership transfer patterns
rg -A 5 "unwrap.*GenericImagePtr" 

# Check for potential memory leaks or cleanup
ast-grep --pattern 'if \($_ = [$_]unwrap\) { 
  $$$ 
  delete $_;
  $$$
}'

Length of output: 112


Script:

#!/bin/bash
# Find and examine the implementation file
fd "FrontendImage.mm" --type f --exec cat {}

# Look for similar wrapper patterns
rg -g "*.h" "GenericImagePtr" -A 3 -B 3

# Look for documentation patterns in wrapper classes
rg -g "*.h" "@interface.*Wrapper" -A 10

Length of output: 27313

osx/PhotoBook/PhotoBook/Wrappers/FrontendImage/FrontendImage.mm (1)

38-41: Document memory management expectations for unwrapped pointer.

The unwrap method exposes the internal C++ pointer. Please add documentation about:

  1. Memory ownership expectations
  2. Lifetime guarantees of the returned pointer
  3. Thread safety considerations

This will help prevent memory-related issues when the pointer is used across language boundaries.

osx/PhotoBook/PhotoBook/UPL/UnstagedPhotoLine.swift (1)

50-50: LGTM! Border adds clear visual distinction.

The border addition improves the UI by clearly delineating the scroll view area.

osx/PhotoBook/PhotoBook/Pages/DashboardView.swift (1)

158-159: Implement onImageMapped protocol method.

The empty implementation needs to be completed to handle image mapping events properly. Consider updating the UI or state when images are mapped.

Would you like me to suggest an implementation based on the protocol requirements?

osx/PhotoBook/PhotoBook/Photobook.mm (1)

84-91: LGTM! Clean implementation of onImageMapped.

The method properly handles:

  1. UUID to string conversion
  2. FrontendImage creation from GenericImagePtr
osx/PhotoBook/PhotoBook/Pages/TableContentView.swift (3)

272-298: LGTM! Well-structured drop implementation with proper error handling.

The drop target implementation:

  1. Properly handles data loading and errors
  2. Uses unique UUIDs for image mapping
  3. Has appropriate error logging

322-326: LGTM! Clean decoder implementation.

The decodeData method is concise and follows Swift best practices.


374-377: Implement onImageMapped to handle mapped images.

The empty implementation should be completed to:

  1. Update UI state when images are mapped
  2. Handle any errors during mapping

Would you like me to suggest an implementation based on the application's requirements?

Comment on lines +28 to +37
func loadData(withTypeIdentifier typeIdentifier: String, forItemProviderCompletionHandler completionHandler: @escaping @Sendable (Data?, (any Error)?) -> Void) -> Progress? {
do {
let encoder = JSONEncoder()
let dataToReturn = try encoder.encode(self)
completionHandler(dataToReturn, nil)
} catch {
completionHandler(nil, error)
}
return Progress(totalUnitCount: 100)
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve progress reporting and error handling.

The current implementation has several issues:

  1. The Progress object doesn't reflect actual work done
  2. No validation of the type identifier
  3. Error handling could be more specific

Consider this improved implementation:

func loadData(withTypeIdentifier typeIdentifier: String, forItemProviderCompletionHandler completionHandler: @escaping @Sendable (Data?, (any Error)?) -> Void) -> Progress? {
    // Verify type identifier
    guard typeIdentifier == UTType.plainText.identifier else {
        completionHandler(nil, NSError(domain: "UPLIdentifier", code: 1, userInfo: [
            NSLocalizedDescriptionKey: "Unsupported type identifier: \(typeIdentifier)"
        ]))
        return nil
    }
    
    let progress = Progress(totalUnitCount: 100)
    
    do {
        let encoder = JSONEncoder()
        progress.completedUnitCount = 50 // Encoding started
        let dataToReturn = try encoder.encode(self)
        progress.completedUnitCount = 100 // Encoding completed
        completionHandler(dataToReturn, nil)
    } catch {
        completionHandler(nil, error)
    }
    
    return progress
}

Comment on lines +222 to +246
- (void) mapImagesToSPL:(NSDictionary<NSString*, FrontendImage*>*)images
{
auto imageToPaperService = mPhotobook->imageToPaperService();

std::unordered_map<PBDev::ImageToPaperId, PB::GenericImagePtr,
boost::hash<PBDev::ImageToPaperId>>
backendMap;

for (NSString *key in images) {
std::string uuidStr = [key UTF8String];
try {
boost::uuids::string_generator gen;
boost::uuids::uuid nativeUuid = gen(uuidStr);

PBDev::ImageToPaperId imageId = PBDev::ImageToPaperId(nativeUuid);

backendMap[imageId] = [images[key] unwrap];

} catch (const std::exception& e) {
}
}

imageToPaperService->map(
PBDev::ImageToPaperServiceId(PB::RuntimeUUID::newUUID()), backendMap);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling and validation in mapImagesToSPL.

The implementation has several issues:

  1. Empty catch block silently ignores UUID parsing errors
  2. No validation for null images
  3. No error propagation to Swift layer
 - (void) mapImagesToSPL:(NSDictionary<NSString*, FrontendImage*>*)images
 {
+    if (!images) {
+        NSLog(@"Error: images dictionary is null");
+        return;
+    }
     auto imageToPaperService = mPhotobook->imageToPaperService();
     
     std::unordered_map<PBDev::ImageToPaperId, PB::GenericImagePtr,
                          boost::hash<PBDev::ImageToPaperId>>
           backendMap;
     
     for (NSString *key in images) {
+        if (!images[key]) {
+            NSLog(@"Error: null image for key %@", key);
+            continue;
+        }
         std::string uuidStr = [key UTF8String];
         try {
             boost::uuids::string_generator gen;
             boost::uuids::uuid nativeUuid = gen(uuidStr);
             
             PBDev::ImageToPaperId imageId = PBDev::ImageToPaperId(nativeUuid);
             
             backendMap[imageId] = [images[key] unwrap];
             
         } catch (const std::exception& e) {
+            NSLog(@"Error parsing UUID %@: %s", key, e.what());
         }
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- (void) mapImagesToSPL:(NSDictionary<NSString*, FrontendImage*>*)images
{
auto imageToPaperService = mPhotobook->imageToPaperService();
std::unordered_map<PBDev::ImageToPaperId, PB::GenericImagePtr,
boost::hash<PBDev::ImageToPaperId>>
backendMap;
for (NSString *key in images) {
std::string uuidStr = [key UTF8String];
try {
boost::uuids::string_generator gen;
boost::uuids::uuid nativeUuid = gen(uuidStr);
PBDev::ImageToPaperId imageId = PBDev::ImageToPaperId(nativeUuid);
backendMap[imageId] = [images[key] unwrap];
} catch (const std::exception& e) {
}
}
imageToPaperService->map(
PBDev::ImageToPaperServiceId(PB::RuntimeUUID::newUUID()), backendMap);
}
- (void) mapImagesToSPL:(NSDictionary<NSString*, FrontendImage*>*)images
{
if (!images) {
NSLog(@"Error: images dictionary is null");
return;
}
auto imageToPaperService = mPhotobook->imageToPaperService();
std::unordered_map<PBDev::ImageToPaperId, PB::GenericImagePtr,
boost::hash<PBDev::ImageToPaperId>>
backendMap;
for (NSString *key in images) {
if (!images[key]) {
NSLog(@"Error: null image for key %@", key);
continue;
}
std::string uuidStr = [key UTF8String];
try {
boost::uuids::string_generator gen;
boost::uuids::uuid nativeUuid = gen(uuidStr);
PBDev::ImageToPaperId imageId = PBDev::ImageToPaperId(nativeUuid);
backendMap[imageId] = [images[key] unwrap];
} catch (const std::exception& e) {
NSLog(@"Error parsing UUID %@: %s", key, e.what());
}
}
imageToPaperService->map(
PBDev::ImageToPaperServiceId(PB::RuntimeUUID::newUUID()), backendMap);
}

@@ -107,6 +112,7 @@ struct PhotoBookApp: App, PhotobookUIListener, NoirUIListener {
func onMappingFinished(root: String) {}
func onImageUpdated(root: String, row:UInt, index:UInt){}
func onCollageThumbnailsCreated(){}
func onImageMapped(imageId: String, image: FrontendImage){}
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Remove duplicate protocol implementation

The empty onImageMapped implementation at line 115 is redundant as PhotoBookApp already implements this method at line 39 with proper delegation logic. Having two implementations of the same protocol method within the same type can lead to unexpected behavior.

  • Remove the empty implementation at line 115 since the working implementation at line 39 already handles the protocol requirement by delegating to the last listener.
🔗 Analysis chain

Review empty implementation and verify protocol requirements.

The empty implementation raises several concerns:

  1. The TODO comment above suggests that PhotobookUIListener might not be needed in this struct
  2. If the listener is needed, the empty implementation should be documented or handle state updates

Let's verify the protocol usage:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for PhotobookUIListener protocol definition and its usage
ast-grep --pattern 'protocol PhotobookUIListener {
  $$$
}'

# Search for other implementations of onImageMapped
rg -p "func onImageMapped.*FrontendImage" -A 5

Length of output: 952

@cosmin42 cosmin42 merged commit 6e02e67 into main Jan 29, 2025
2 of 3 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