Skip to content

Commit

Permalink
Merge branch 'candela97-refactor-blockingwaitdialog' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
tfedor committed Nov 19, 2024
2 parents 8d7db46 + ffb4755 commit beeaf9e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,19 @@ export default class FWorkshopFileSizes extends Feature<CMyWorkshop> {
this._addFileSizes(); // Add file sizes now that data has been fetched
}

private getStatus(): string {
let statusString = L(__calcWorkshopSize_calcLoading, {
private getStatus(): string[] {
const status = [];

status.push(L(__calcWorkshopSize_calcLoading, {
"i": this._completed,
"count": this._total
});
}));

if (this._failed > 0) {
statusString += "<br>";
statusString += L(__workshop_failed, {"n": this._failed});
status.push(L(__workshop_failed, {"n": this._failed}));
}

return statusString;
return status;
}

_getFileSizeStr(size: number): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,16 @@ export default class FWorkshopSubscriberButtons extends Feature<CWorkshopBrowse>
return false;
}

private getStatus(): string {
let status = L(this._method === "subscribe" ? __workshop_subscribeLoading : __workshop_unsubscribeLoading, {
private getStatus(): string[] {
const status = [];

status.push(L(this._method === "subscribe" ? __workshop_subscribeLoading : __workshop_unsubscribeLoading, {
"i": this._completed,
"count": this._total
});
}));

if (this._failed > 0) {
status += "<br>";
status += L(__workshop_failed, {"n": this._failed});
status.push(L(__workshop_failed, {"n": this._failed}));
}

return status;
Expand Down
38 changes: 21 additions & 17 deletions src/js/Core/Modals/BlockingWaitDialog.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
import HTML from "@Core/Html/Html";
import SteamFacade from "@Content/Modules/Facades/SteamFacade";
import type {SvelteComponent} from "svelte";
import BlockingWaitModal from "./BlockingWaitModal.svelte";

let dialogCounter: number = 0;
let counter: number = 0;

export default class BlockingWaitDialog {

private readonly id: string;
private readonly modalId: string;
private modalComponent: SvelteComponent | undefined;

constructor(
private readonly title: string,
private readonly statusFn: () => string
private readonly statusFn: () => string|string[]
) {
this.id = `as_wait_dialog_${++dialogCounter}`;
}

private getContainer(): HTMLElement|null {
return document.querySelector("#" + this.id);
this.modalId = `as_wait_dialog-${++counter}`;
}

async update(): Promise<void> {
const container = this.getContainer();
if (container) {
HTML.inner(container, this.statusFn());
} else {
if (!this.modalComponent) {
await SteamFacade.showBlockingWaitDialog(
this.title,
`<div id="${this.id}">${this.statusFn()}</div>`
`<div id="${this.modalId}"></div>`
);

const target = document.querySelector<HTMLDivElement>("#" + this.modalId);
if (target) {
this.modalComponent = new BlockingWaitModal({target});
} else {
throw new Error("Failed to create blocking wait dialog");
}
}

this.modalComponent.status = this.statusFn();
}

dismiss(): void {
const container = this.getContainer();
if (container) {
SteamFacade.dismissActiveModal(this.id);
if (this.modalComponent) {
this.modalComponent.$destroy();
SteamFacade.dismissActiveModal(this.modalId);
}
}
}
17 changes: 17 additions & 0 deletions src/js/Core/Modals/BlockingWaitModal.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<svelte:options accessors />

<script lang="ts">
import {__wait} from "@Strings/_strings";
import {L} from "@Core/Localization/Localization";
export let status: string|string[] = L(__wait);
</script>


{#if typeof status === "string"}
{status}
{:else}
{#each status as statusStr}
<div>{statusStr}</div>
{/each}
{/if}

0 comments on commit beeaf9e

Please sign in to comment.