-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'candela97-refactor-blockingwaitdialog' into develop
- Loading branch information
Showing
4 changed files
with
51 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |