File tree Expand file tree Collapse file tree 2 files changed +38
-15
lines changed
ts/WoltLabSuite/Core/Component Expand file tree Collapse file tree 2 files changed +38
-15
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ import { deleteObject } from "WoltLabSuite/Core/Api/DeleteObject";
1111import { postObject } from "WoltLabSuite/Core/Api/PostObject" ;
1212import { ConfirmationType , handleConfirmation } from "../Confirmation" ;
1313import { showProgressSnackbar } from "WoltLabSuite/Core/Component/Snackbar" ;
14- import { getPhrase } from "WoltLabSuite/Core/Language" ;
1514
1615async function handleRpcInteraction (
1716 container : HTMLElement ,
@@ -26,13 +25,7 @@ async function handleRpcInteraction(
2625 return ;
2726 }
2827
29- const snackbar = showProgressSnackbar (
30- getPhrase ( "wcf.global.snackbar.progress" , {
31- label,
32- iteration : 0 ,
33- length : objectIds . length ,
34- } ) ,
35- ) ;
28+ const snackbar = showProgressSnackbar ( label , objectIds . length ) ;
3629
3730 for ( let i = 0 ; i < objectIds . length ; i ++ ) {
3831 if ( confirmationType == ConfirmationType . Delete ) {
@@ -44,11 +37,7 @@ async function handleRpcInteraction(
4437 ) ;
4538 }
4639
47- snackbar . message = getPhrase ( "wcf.global.snackbar.progress" , {
48- label,
49- iteration : i + 1 ,
50- length : objectIds . length ,
51- } ) ;
40+ snackbar . setIteration ( i + 1 ) ;
5241
5342 const element = container . querySelector ( `[data-object-id="${ objectIds [ i ] } "]` ) ;
5443 if ( ! element ) {
Original file line number Diff line number Diff line change @@ -208,12 +208,46 @@ class SnackbarContainer {
208208 }
209209}
210210
211+ class SnackbarProgress {
212+ readonly #snackbar: Snackbar ;
213+ readonly #label: string ;
214+ readonly #length: number ;
215+ #iteration = 0 ;
216+
217+ constructor ( label : string , length : number ) {
218+ this . #label = label ;
219+ this . #length = length ;
220+
221+ this . #snackbar = new Snackbar ( this . #getMessage( ) , SnackbarType . Progress ) ;
222+ }
223+
224+ setIteration ( iteration : number ) : void {
225+ this . #iteration = iteration ;
226+ }
227+
228+ markAsDone ( ) : void {
229+ this . #snackbar. markAsDone ( ) ;
230+ }
231+
232+ get element ( ) : Snackbar {
233+ return this . #snackbar;
234+ }
235+
236+ #getMessage( ) : string {
237+ return getPhrase ( "wcf.global.snackbar.progress" , {
238+ label : this . #label,
239+ iteration : this . #iteration,
240+ length : this . #length,
241+ } ) ;
242+ }
243+ }
244+
211245export function showSuccessSnackbar ( message : string ) : Snackbar {
212246 return new Snackbar ( message , SnackbarType . Success ) ;
213247}
214248
215- export function showProgressSnackbar ( message : string ) : Snackbar {
216- return new Snackbar ( message , SnackbarType . Progress ) ;
249+ export function showProgressSnackbar ( label : string , length : number ) : SnackbarProgress {
250+ return new SnackbarProgress ( label , length ) ;
217251}
218252
219253export function showDefaultSuccessSnackbar ( ) : Snackbar {
You can’t perform that action at this time.
0 commit comments