Skip to content

Commit 2a10d4c

Browse files
committed
fix(dialogs): handle cancel flows without false action failures
- treat FilePicker close events as user cancels and return safely from move/restore flows - guard dialog .show() promises so cancel/close does not surface fake error toasts - apply the same safe-cancel pattern to Move, Export, and Swarm Reference dialogs
1 parent 9d0cde6 commit 2a10d4c

5 files changed

Lines changed: 63 additions & 8 deletions

File tree

src/app/files/actions/archive.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ registerFileActionCompat({
3636
"Restore",
3737
UnarchiveSvg,
3838
);
39+
if (!path) {
40+
return;
41+
}
3942
const destination = FilesHelper.getPathParts(path)
4043
.slice(1)
4144
.join("/");

src/app/files/actions/export.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ registerFileActionCompat({
3838
callback: async () => downloadMetadata(node),
3939
})
4040
.build()
41-
.show();
41+
.show()
42+
.catch((error) => {
43+
if (!FilesHelper.isDialogCancelError(error)) {
44+
throw error;
45+
}
46+
});
4247
},
4348
});
4449

src/app/files/actions/move.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ registerFileActionCompat({
2323
async exec({ nodes }) {
2424
const node = nodes[0];
2525
const path = await FilesHelper.locationPicker(node, "Move", MoveSvg);
26+
if (!path) {
27+
return;
28+
}
2629
const destination = FilesHelper.getPathParts(path).slice(1).join("/");
2730
await axios({
2831
method: "post",

src/app/files/actions/reference.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,13 @@ registerFileActionCompat({
8484
icon: SvgHelper.convert(OpenSvg),
8585
callback: () => {
8686
void new Dialog(
87-
t("files_external_ethswarm", "Access on Swarm Gateway?"),
8887
t(
8988
"files_external_ethswarm",
90-
"You are about to access this file through gateway.ethswarm.org, a public Swarm gateway used to access Swarm content. Please note this opens an external link and can leave network and server access traces to your swarm reference."
89+
"Access on Swarm Gateway?",
90+
),
91+
t(
92+
"files_external_ethswarm",
93+
"You are about to access this file through gateway.ethswarm.org, a public Swarm gateway used to access Swarm content. Please note this opens an external link and can leave network and server access traces to your swarm reference.",
9194
),
9295
[
9396
{
@@ -103,14 +106,26 @@ registerFileActionCompat({
103106
window.open(
104107
gatewayUrl,
105108
"_blank",
106-
"noopener,noreferrer"
109+
"noopener,noreferrer",
107110
);
108111
},
109112
},
110-
]
111-
).show().catch(() => null);
113+
],
114+
)
115+
.show()
116+
.catch((error) => {
117+
if (!FilesHelper.isDialogCancelError(error)) {
118+
throw error;
119+
}
120+
});
112121
},
113122
},
114-
]).show().catch(() => null);
123+
])
124+
.show()
125+
.catch((error) => {
126+
if (!FilesHelper.isDialogCancelError(error)) {
127+
throw error;
128+
}
129+
});
115130
},
116131
});

src/util/FilesHelper.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import SvgHelper from "@/util/SvgHelper";
66
const FilesHelper = {
77
isSwarmNode: (nodes) =>
88
getMainNode(nodes).attributes["ethswarm-node"] !== undefined,
9+
isDialogCancelError: (error) => isDialogCancelError(error),
910
getSwarmRef: (nodes) => getSwarmRef(nodes),
1011
hasSwarmRef: (nodes) => getSwarmRef(nodes) !== undefined,
1112
canUnshareOnly: (nodes) => {
@@ -93,7 +94,13 @@ const FilesHelper = {
9394
),
9495
)
9596
.build()
96-
.pick(),
97+
.pick()
98+
.catch((error) => {
99+
if (isDialogCancelError(error)) {
100+
return null;
101+
}
102+
throw error;
103+
}),
97104
downloadFile: (blob, filename) => {
98105
const url = URL.createObjectURL(blob);
99106
const a = document.createElement("a");
@@ -140,4 +147,26 @@ function isArchive(nodes) {
140147
return getPathParts(nodes)[1] === "Archive - HejBit";
141148
}
142149

150+
function isDialogCancelError(error) {
151+
if (error === null || typeof error === "undefined") {
152+
return true;
153+
}
154+
155+
if (typeof error === "string") {
156+
return /cancel|abort|dismiss|closed|no nodes selected/i.test(error);
157+
}
158+
159+
if (typeof error === "object") {
160+
const message = "message" in error ? String(error.message ?? "") : "";
161+
const name = "name" in error ? String(error.name ?? "") : "";
162+
163+
return (
164+
/abort|cancel|dismiss|closed/i.test(name) ||
165+
/cancel|abort|dismiss|closed|no nodes selected/i.test(message)
166+
);
167+
}
168+
169+
return false;
170+
}
171+
143172
export default FilesHelper;

0 commit comments

Comments
 (0)