From 3325cdf970a6d5b1d5c2c3774f50d66983664ef9 Mon Sep 17 00:00:00 2001 From: Gregoire Parant Date: Tue, 20 Oct 2020 11:25:17 +0200 Subject: [PATCH] Update banned message modal --- front/src/Administration/TypeMessage.ts | 32 +++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/front/src/Administration/TypeMessage.ts b/front/src/Administration/TypeMessage.ts index 7bd9b484..ecfc4597 100644 --- a/front/src/Administration/TypeMessage.ts +++ b/front/src/Administration/TypeMessage.ts @@ -1,12 +1,24 @@ import {TypeMessageInterface} from "./UserMessageManager"; import {HtmlUtils} from "../WebRtc/HtmlUtils"; +let modalTimeOut : NodeJS.Timeout; + export class TypeMessageExt implements TypeMessageInterface{ private nbSecond = 0; private maxNbSecond = 10; private titleMessage = 'IMPORTANT !'; - showMessage(message: string): void { + showMessage(message: string, canDeleteMessage: boolean = true): void { + //delete previous modal + try{ + if(modalTimeOut){ + clearTimeout(modalTimeOut); + } + const modal = HtmlUtils.getElementByIdOrFail('report-message-user'); + modal.remove(); + }catch (err){} + + //create new modal const div : HTMLDivElement = document.createElement('div'); div.classList.add('modal-report-user'); div.id = 'report-message-user'; @@ -34,21 +46,24 @@ export class TypeMessageExt implements TypeMessageInterface{ this.nbSecond = this.maxNbSecond; setTimeout((c) => { - this.forMessage(title); + this.forMessage(title, canDeleteMessage); }, 1000); } - forMessage(title: HTMLParagraphElement){ + forMessage(title: HTMLParagraphElement, canDeleteMessage: boolean = true){ this.nbSecond -= 1; title.innerText = `${this.titleMessage} (${this.nbSecond})`; if(this.nbSecond > 0){ - setTimeout(() => { - this.forMessage(title); + modalTimeOut = setTimeout(() => { + this.forMessage(title, canDeleteMessage); }, 1000); - }else{ + }else { title.innerText = this.titleMessage; - const imgCancel : HTMLImageElement = document.createElement('img'); + if (!canDeleteMessage) { + return; + } + const imgCancel: HTMLImageElement = document.createElement('img'); imgCancel.id = 'cancel-report-user'; imgCancel.src = 'resources/logos/close.svg'; @@ -64,4 +79,7 @@ export class Ban extends TypeMessageExt { } export class Banned extends TypeMessageExt { + showMessage(message: string){ + super.showMessage(message, false); + } } \ No newline at end of file