-
-
Notifications
You must be signed in to change notification settings - Fork 89
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: Fix a bug that caused some unassigned face photos to be unselectable #774
fix: Fix a bug that caused some unassigned face photos to be unselectable #774
Conversation
I really hope that I have not broken anything with this 😆 But it works for me so far, I look forward to feedback! |
@@ -228,7 +283,7 @@ export type ISelectionAction = { | |||
/** Icon component */ | |||
icon: any; | |||
/** Action to perform */ | |||
callback: (selection: Map<number, IPhoto>) => Promise<void>; | |||
callback: (selection: any) => Promise<void>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type should be SelectionProxy
but this doesn't work. Can someone help out here?
17433bb
to
e3e20f9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let photosToDelete: IPhoto[] = [] | ||
for (const photo of selection.values()) { | ||
if (photo === undefined) { | ||
continue | ||
} | ||
if (delIds.indexOf(photo.fileid) > -1) { | ||
photosToDelete.push(photo) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Why not just
selection.values().filter( ... )
? - Can get a safer time complexity by making
delIds
aSet
first
// Only do this if the photo in the selection set is this one. | ||
// The problem arises when there are duplicates (e.g. face rect) | ||
// in the list, which creates an inconsistent state if we do this. | ||
if (this.selection.get(photo.fileid) === photo) { | ||
this.selection.delete(photo.fileid); | ||
if (this.selection.get(photo) === photo) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment and check should no longer be relevant.
@@ -220,6 +220,61 @@ export type ITick = { | |||
key?: number; | |||
}; | |||
|
|||
export class SelectionProxy { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
types.ts
is intended only for interfaces, not implementations (this way, you can import type ...
). This class can move to another file.
} | ||
|
||
get(photo: IPhoto): IPhoto | undefined { | ||
return this.map.get(photo.key!); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This, precisely, could be the issue. Photo.key
is nullable because, well, it can be null. The bang operator discards this information without a check. There are indeed a bunch of places where we "fake" a IPhoto
object that doesn't have a key.
By now though, I'm hoping the selection manager doesn't have to deal with these things. So a runtime assertion here might suffice, so we know if something breaks.
This resolves #721