Skip to content

Commit 7aea7a6

Browse files
committed
Fix remote asset browser refresh and error state handling
1 parent 6419900 commit 7aea7a6

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/RemoteContentAssets/Presentation/Resources/assets/controllers/remote_asset_browser_controller.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export default class extends Controller {
104104
private backgroundSyncTimeoutId: ReturnType<typeof setTimeout> | null = null;
105105
private latestManifestRevision: string | null = null;
106106
private isBackgroundSyncEnabled: boolean = false;
107+
private uploadErrorFallbackLabel: string = "Upload failed. Please try again.";
107108
private readonly focusHandler = (): void => {
108109
void this.checkForManifestUpdates();
109110
};
@@ -115,6 +116,13 @@ export default class extends Controller {
115116

116117
connect(): void {
117118
this.isConnected = true;
119+
if (this.hasUploadErrorTarget) {
120+
const textEl = this.uploadErrorTarget.querySelector("[data-error-text]");
121+
const initialText = textEl?.textContent?.trim();
122+
if (initialText) {
123+
this.uploadErrorFallbackLabel = initialText;
124+
}
125+
}
118126
void this.fetchAssets();
119127
this.setupDropzone();
120128
this.isBackgroundSyncEnabled = this.getBackgroundSyncIntervalMs() > 0;
@@ -513,7 +521,7 @@ export default class extends Controller {
513521
}
514522

515523
private async checkForManifestUpdates(): Promise<void> {
516-
if (this.isUploading) {
524+
if (this.isUploading || this.isLoading) {
517525
return;
518526
}
519527

@@ -560,7 +568,9 @@ export default class extends Controller {
560568
}
561569

562570
private async reloadAssetsAfterConfirmation(): Promise<void> {
563-
await this.fetchAssets();
571+
if ((await this.fetchAssets()) === null) {
572+
return;
573+
}
564574
this.showUploadStatus("success");
565575
setTimeout(() => this.showUploadStatus("none"), 3000);
566576
}
@@ -572,13 +582,7 @@ export default class extends Controller {
572582
}
573583

574584
private getUploadErrorFallbackLabel(): string {
575-
if (this.hasUploadErrorTarget) {
576-
const textEl = this.uploadErrorTarget.querySelector("[data-error-text]");
577-
if (textEl && textEl.textContent !== null && textEl.textContent !== "") {
578-
return textEl.textContent;
579-
}
580-
}
581-
return "Upload failed. Please try again.";
585+
return this.uploadErrorFallbackLabel;
582586
}
583587

584588
private normalizeManifestData(data: { urls?: string[]; revision?: string }): { urls: string[]; revision: string } {

0 commit comments

Comments
 (0)