From 8cf87acb7bac5e315097e14e868069dcae0fae1a Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Fri, 15 Nov 2024 17:27:26 +0530 Subject: [PATCH] Rework --- .../components/gallery/PeopleHeader.tsx | 41 ++++++++++++++++--- web/packages/new/photos/services/ml/people.ts | 32 +++++++-------- 2 files changed, 50 insertions(+), 23 deletions(-) diff --git a/web/packages/new/photos/components/gallery/PeopleHeader.tsx b/web/packages/new/photos/components/gallery/PeopleHeader.tsx index bda66fa1fb..37e1fe0cae 100644 --- a/web/packages/new/photos/components/gallery/PeopleHeader.tsx +++ b/web/packages/new/photos/components/gallery/PeopleHeader.tsx @@ -528,7 +528,23 @@ const suggestionsDialogReducer: React.Reducer< // original assigned state. updates.delete(item.id); } else { - updates.set(item.id, value); + const update = (() => { + switch (value) { + case true: + // true corresponds to update "assign". + return "assign"; + case false: + // false maps to different updates for suggestions + // vs choices. + return item.assigned === undefined + ? "rejectSuggestion" + : "rejectSavedChoice"; + case undefined: + // undefined means reset. + return "reset"; + } + })(); + updates.set(item.id, update); } return { ...state, updates }; } @@ -764,7 +780,7 @@ const SuggestionOrChoiceList: React.FC = ({ {!item.fixed && ( onUpdateItem(item, toItemValue(v))} > @@ -781,12 +797,25 @@ const SuggestionOrChoiceList: React.FC = ({ ); -const fromItemValue = (item: SCItem, updates: PersonSuggestionUpdates) => { +const itemValueFromUpdate = ( + item: SCItem, + updates: PersonSuggestionUpdates, +) => { // Use the in-memory state if available. For choices, fallback to their // original state. - const resolved = updates.has(item.id) - ? updates.get(item.id) - : item.assigned; + const resolveUpdate = () => { + switch (updates.get(item.id)) { + case "assign": + return true; + case "rejectSavedChoice": + return false; + case "rejectSuggestion": + return false; + default: + return undefined; + } + }; + const resolved = updates.has(item.id) ? resolveUpdate() : item.assigned; return resolved ? "yes" : resolved === false ? "no" : undefined; }; diff --git a/web/packages/new/photos/services/ml/people.ts b/web/packages/new/photos/services/ml/people.ts index 60bc54da3d..f06f633779 100644 --- a/web/packages/new/photos/services/ml/people.ts +++ b/web/packages/new/photos/services/ml/people.ts @@ -621,18 +621,18 @@ const randomSample = (items: T[], n: number) => { * * Each entry is a (clusterID, update) pair. * - * * Entries with "assign" should be assigned to the cgroup, - * * Entries with "reject-local" should be rejected from the cgroup locally. - * These correspond to suggestions which the user did not accept. - * * Entries with "reject-remote" should be rejected from the cgroup both + * * Clusters with "assign" should be assigned to the cgroup, + * * Clusters with "rejectSuggestion" should be rejected from the cgroup + * locally. These correspond to suggestions which the user did not accept. + * * Clusters with "rejectSavedChoice" should be rejected from the cgroup both * locally and on remote. These correspond to saved choices which the user * went on to explicitly reject. - * * Entries with "reset" should be reset - i.e. should be removed from both the - * assigned and rejected choices associated with the cgroup (if needed). + * * Clusters with "reset" should be reset - i.e. should be removed from both + * the assigned and rejected choices associated with the cgroup (if needed). */ export type PersonSuggestionUpdates = Map< string, - "assign" | "reject-local" | "reject-remote" | "reset" + "assign" | "rejectSuggestion" | "rejectSavedChoice" | "reset" >; /** @@ -700,18 +700,15 @@ export const _applyPersonSuggestionUpdates = async ( }; // Add `clusterID` to the list of rejected clusters locally. - const rejectLocal = (clusterID: string) => { + const rejectClusterLocal = (clusterID: string) => { rejectedClusterIDs.push(clusterID); rejectUpdateCount += 1; }; - // Add `clusterID` to the list of rejected clusters locally, and mark the - // faces in that cluster as rejected on remote. - const rejectRemote = (clusterID: string) => { + // Mark the faces in `clusterID` as rejected on remote. + const rejectFacesRemote = (clusterID: string) => { const cluster = clusterWithID(clusterID); - rejectedClusterIDs.push(clusterID); newlyRejectedFaceIDs = newlyRejectedFaceIDs.concat(cluster.faces); - rejectUpdateCount += 1; }; // Remove `clusterID` from the list of rejected clusters (if needed). @@ -731,14 +728,15 @@ export const _applyPersonSuggestionUpdates = async ( unrejectIfNeeded(clusterID); break; - case "reject-local": + case "rejectSuggestion": unassignIfNeeded(clusterID); - rejectLocal(clusterID); + rejectClusterLocal(clusterID); break; - case "reject-remote": + case "rejectSavedChoice": unassignIfNeeded(clusterID); - rejectRemote(clusterID); + rejectClusterLocal(clusterID); + rejectFacesRemote(clusterID); break; case "reset":