Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Support secondary

Manav Rathi52866bdc8ee2
diff --git a/web/apps/photos/src/components/Collections/CollectionHeader.tsx b/web/apps/photos/src/components/Collections/CollectionHeader.tsx
index 495840ac90..031182a9d1 100644
--- a/web/apps/photos/src/components/Collections/CollectionHeader.tsx
+++ b/web/apps/photos/src/components/Collections/CollectionHeader.tsx
@@ -195,9 +195,9 @@ const CollectionOptions: React.FC<CollectionOptionsProps> = ({
wrap(() => _renameCollection(newName))();
const confirmDeleteCollection = () => {
- setDialogMessage({
+ showMiniDialog({
title: t("delete_album_title"),
- content: (
+ message: (
<Trans
i18nKey={"delete_album_message"}
components={{
@@ -205,18 +205,14 @@ const CollectionOptions: React.FC<CollectionOptionsProps> = ({
}}
/>
),
- proceed: {
+ continue: {
text: t("delete_photos"),
+ color: "critical",
action: deleteCollectionAlongWithFiles,
- variant: "critical",
},
secondary: {
text: t("keep_photos"),
action: deleteCollectionButKeepFiles,
- variant: "primary",
- },
- close: {
- text: t("cancel"),
},
});
};
diff --git a/web/packages/base/components/MiniDialog.tsx b/web/packages/base/components/MiniDialog.tsx
index d22ef62200..a5ab5385f2 100644
--- a/web/packages/base/components/MiniDialog.tsx
+++ b/web/packages/base/components/MiniDialog.tsx
@@ -92,6 +92,36 @@ export interface MiniDialogAttributes {
*/
action?: () => void | Promise<void>;
};
+ /**
+ * Customize the secondary action button shown in the dialog.
+ *
+ * This is rarely needed. When provided, these attributes behave similar to
+ * the {@link continue} attributes, except this button is shown below the
+ * primary button.
+ *
+ * This is not supported when button direction is "row".
+ */
+ secondary?: {
+ /**
+ * The string to use as the label for the secondary action button.
+ *
+ * Must be provided.
+ */
+ text: string;
+ /**
+ * The color of the button.
+ *
+ * Default is "primary".
+ */
+ color?: ButtonProps["color"];
+ /**
+ * The function to call when the user activates the button.
+ *
+ * The behaviour of this function is exactly the same as that of the
+ * primary {@link action} provided via the {@link continue} attributes.
+ */
+ action?: () => void | Promise<void>;
+ };
/**
* The string to use as the label for the cancel button.
*
@@ -129,7 +159,9 @@ type MiniDialogProps = Omit<DialogProps, "onClose"> & {
export const AttributedMiniDialog: React.FC<
React.PropsWithChildren<MiniDialogProps>
> = ({ open, onClose, attributes, children, ...props }) => {
- const [phase, setPhase] = useState<"loading" | "failed" | undefined>();
+ const [phase, setPhase] = useState<
+ "loading" | "secondary-loading" | "failed" | undefined
+ >();
if (!attributes) {
return <></>;
@@ -143,7 +175,12 @@ export const AttributedMiniDialog: React.FC<
const handleClose: ModalProps["onClose"] = (_, reason) => {
if (attributes.nonClosable) return;
// Ignore backdrop clicks when we're processing the user request.
- if (reason == "backdropClick" && phase == "loading") return;
+ if (
+ reason == "backdropClick" &&
+ (phase == "loading" || phase == "secondary-loading")
+ ) {
+ return;
+ }
resetPhaseAndClose();
};
@@ -167,6 +204,7 @@ export const AttributedMiniDialog: React.FC<
const loadingButton = attributes.continue && (
<LoadingButton
loading={phase == "loading"}
+ disabled={phase == "secondary-loading"}
fullWidth
color={attributes.continue.color ?? "accent"}
autoFocus={attributes.continue.autoFocus}
@@ -185,6 +223,30 @@ export const AttributedMiniDialog: React.FC<
</LoadingButton>
);
+ const secondaryLoadingButton = attributes.secondary?.text && (
+ <LoadingButton
+ disabled={phase == "loading"}
+ loading={phase == "secondary-loading"}
+ fullWidth
+ color={attributes.secondary.color ?? "primary"}
+ onClick={async () => {
+ setPhase("secondary-loading");
+ try {
+ await attributes.secondary?.action?.();
+ resetPhaseAndClose();
+ } catch (e) {
+ log.error(e);
+ setPhase("failed");
+ }
+ }}
+ >
+ {attributes.secondary.text}
+ </LoadingButton>
+ );
+
+ if (secondaryLoadingButton && attributes.buttonDirection == "row")
+ throw new Error("Unsupported combination");
+
const cancelButton = cancelTitle && (
<FocusVisibleButton
fullWidth
@@ -268,6 +330,7 @@ export const AttributedMiniDialog: React.FC<
) : (
<>
{loadingButton}
+ {secondaryLoadingButton}
{cancelButton}
</>
)}