Reset selection

This commit is contained in:
Manav Rathi 2024-09-26 21:36:30 +05:30
parent 4c0c05a54a
commit de6a494da7
No known key found for this signature in database
4 changed files with 43 additions and 22 deletions

View File

@ -174,9 +174,10 @@ export const GalleryBarAndListHeader: React.FC<CollectionsProps> = ({
) : (
<PeopleHeader
person={ensure(
people.find((p) => p.id == activePersonID),
people.find((p) => p.id == activePersonID) ??
people[0],
)}
appContext={appContext}
{...{ onSelectPerson, appContext }}
/>
),
itemType: ITEM_TYPE.HEADER,

View File

@ -553,7 +553,7 @@ export default function Gallery() {
);
} else if (barMode == "people") {
const activePerson = ensure(
people.find((p) => p.id == activePersonID),
people.find((p) => p.id == activePersonID) ?? people[0],
);
const pfSet = new Set(activePerson.fileIDs);
filteredFiles = getUniqueFiles(
@ -1058,7 +1058,7 @@ export default function Gallery() {
// when the user clicks the "People" header in the search empty state (it
// is guaranteed that this header will only be shown if there is at
// least one person).
setActivePersonID(person.id ?? ensure(people[0]).id);
setActivePersonID(person?.id ?? ensure(people[0]).id);
setBarMode("people");
};

View File

@ -100,9 +100,10 @@ export interface GalleryBarImplProps {
*/
activePersonID: string | undefined;
/**
* Called when the user selects a new person in the bar.
* Called when the selection should be moved to a new person in the bar, or
* reset to the default state (when {@link person} is `undefined`).
*/
onSelectPerson: (person: Person) => void;
onSelectPerson: (person: Person | undefined) => void;
}
export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({
@ -212,7 +213,8 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({
type: "people",
people,
activePerson: ensure(
people.find((p) => p.id == activePersonID),
people.find((p) => p.id == activePersonID) ??
people[0],
),
onSelectPerson,
},

View File

@ -28,17 +28,18 @@ import type { CGroup } from "../../services/user-entity";
import type { NewAppContextPhotos } from "../../types/context";
import { SpaceBetweenFlex } from "../mui-custom";
import { NameInputDialog } from "../NameInputDialog";
import { useWrapLoadError } from "../use-wrap";
import type { GalleryBarImplProps } from "./BarImpl";
import { GalleryItemsHeaderAdapter, GalleryItemsSummary } from "./ListHeader";
interface PeopleHeaderProps {
type PeopleHeaderProps = Pick<GalleryBarImplProps, "onSelectPerson"> & {
person: Person;
appContext: NewAppContextPhotos;
}
};
export const PeopleHeader: React.FC<PeopleHeaderProps> = ({
person,
appContext,
onSelectPerson,
}) => {
return (
<GalleryItemsHeaderAdapter>
@ -53,7 +54,7 @@ export const PeopleHeader: React.FC<PeopleHeaderProps> = ({
{person.type == "cgroup" ? (
<CGroupPersonOptions
cgroup={person.cgroup}
appContext={appContext}
{...{ onSelectPerson, appContext }}
/>
) : (
<ClusterPersonOptions
@ -66,19 +67,24 @@ export const PeopleHeader: React.FC<PeopleHeaderProps> = ({
);
};
interface CGroupPersonOptionsProps {
type CGroupPersonOptionsProps = Pick<
PeopleHeaderProps,
"appContext" | "onSelectPerson"
> & {
cgroup: CGroup;
appContext: NewAppContextPhotos;
}
};
const CGroupPersonOptions: React.FC<CGroupPersonOptionsProps> = ({
cgroup,
appContext,
onSelectPerson,
}) => {
const { startLoading, finishLoading, setDialogBoxAttributesV2 } =
appContext;
const wrap = useWrapLoadError(appContext);
const {
startLoading,
finishLoading,
onGenericError,
setDialogBoxAttributesV2,
} = appContext;
const [openAddNameInput, setOpenAddNameInput] = useState(false);
@ -102,11 +108,24 @@ const CGroupPersonOptions: React.FC<CGroupPersonOptionsProps> = ({
close: { text: t("cancel") },
proceed: {
text: t("RESET"),
action: wrap(() => deletePerson(cgroup)),
action: doDeletePerson,
},
buttonDirection: "row",
});
const doDeletePerson = async () => {
startLoading();
try {
await deletePerson(cgroup);
// Reset the selection to the default state.
onSelectPerson(undefined);
} catch (e) {
onGenericError(e);
} finally {
finishLoading();
}
};
return (
<>
<OverflowMenu
@ -142,10 +161,9 @@ const CGroupPersonOptions: React.FC<CGroupPersonOptionsProps> = ({
);
};
interface ClusterPersonOptionsProps {
type ClusterPersonOptionsProps = Pick<PeopleHeaderProps, "appContext"> & {
cluster: FaceCluster;
appContext: NewAppContextPhotos;
}
};
const ClusterPersonOptions: React.FC<ClusterPersonOptionsProps> = ({
cluster,