From ebde2c795a794be448b0715aa11b245aba4f8f28 Mon Sep 17 00:00:00 2001 From: SivanA-Kaltura <88330203+SivanA-Kaltura@users.noreply.github.com> Date: Sun, 21 Jan 2024 17:32:45 +0200 Subject: [PATCH 1/3] clear active message + wait for event before sorting messages --- src/call-to-action.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/call-to-action.tsx b/src/call-to-action.tsx index ed7d691..5b51c6c 100644 --- a/src/call-to-action.tsx +++ b/src/call-to-action.tsx @@ -34,6 +34,9 @@ class CallToAction extends BasePlugin { } if (this.messages.length) { + this.eventManager.listenOnce(this.player, this.player.Event.Core.CAN_PLAY, () => { + this.sortMessages(); + }); this.eventManager.listen(this.player, this.player.Event.Core.TIME_UPDATE, () => this.onTimeUpdate()); this.eventManager.listen(this.player, this.player.Event.Core.SEEKED, () => this.onSeeked()); } @@ -74,6 +77,7 @@ class CallToAction extends BasePlugin { if (this.activeMessage) { this.callToActionManager.removeMessage(); this.activeMessageEndTime = -1; + this.activeMessage = null; } for (const message of this.messages) { @@ -112,9 +116,14 @@ class CallToAction extends BasePlugin { ) { this.callToActionManager.removeMessage(); this.activeMessageEndTime = -1; + this.activeMessage = null; } } + private sortMessages() { + this.messages.sort((messageA: MessageData, messageB: MessageData) => this.compareMessagesByTiming(messageA, messageB)); + } + private filterMessages() { this.messages = this.config.messages .map(message => { @@ -148,8 +157,7 @@ class CallToAction extends BasePlugin { const contentValid = message.description || message.title || message.buttons.length; return durationValid && timingValid && contentValid; - }) - .sort((messageA: MessageData, messageB: MessageData) => this.compareMessagesByTiming(messageA, messageB)); + }); } private compareMessagesByTiming(messageA: MessageData, messageB: MessageData) { From 7b822aab306f1d2007dbe275264db29bad42bb1e Mon Sep 17 00:00:00 2001 From: SivanA-Kaltura <88330203+SivanA-Kaltura@users.noreply.github.com> Date: Sun, 21 Jan 2024 18:11:17 +0200 Subject: [PATCH 2/3] wait for loaded data event --- src/call-to-action.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/call-to-action.tsx b/src/call-to-action.tsx index 5b51c6c..df0dd92 100644 --- a/src/call-to-action.tsx +++ b/src/call-to-action.tsx @@ -34,9 +34,7 @@ class CallToAction extends BasePlugin { } if (this.messages.length) { - this.eventManager.listenOnce(this.player, this.player.Event.Core.CAN_PLAY, () => { - this.sortMessages(); - }); + this.eventManager.listenOnce(this.player, this.player.Event.Core.LOADED_DATA, () => this.sortMessages()); this.eventManager.listen(this.player, this.player.Event.Core.TIME_UPDATE, () => this.onTimeUpdate()); this.eventManager.listen(this.player, this.player.Event.Core.SEEKED, () => this.onSeeked()); } From b4d91a0c27c6750c5d91408ec3ac08759d1b40e4 Mon Sep 17 00:00:00 2001 From: SivanA-Kaltura <88330203+SivanA-Kaltura@users.noreply.github.com> Date: Tue, 23 Jan 2024 15:29:01 +0200 Subject: [PATCH 3/3] handle messages not being hidden when showing a new message --- src/call-to-action.tsx | 2 ++ src/components/text-with-tooltip/text-with-tooltip.tsx | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/call-to-action.tsx b/src/call-to-action.tsx index df0dd92..fc4cdc5 100644 --- a/src/call-to-action.tsx +++ b/src/call-to-action.tsx @@ -179,6 +179,8 @@ class CallToAction extends BasePlugin { private showMessage(message: MessageDataWithTracking, duration?: number) { this.activeMessage = message; message.wasShown = true; + + this.callToActionManager.removeMessage(); this.callToActionManager.addMessage({ message, duration, diff --git a/src/components/text-with-tooltip/text-with-tooltip.tsx b/src/components/text-with-tooltip/text-with-tooltip.tsx index 42a0176..899c29b 100644 --- a/src/components/text-with-tooltip/text-with-tooltip.tsx +++ b/src/components/text-with-tooltip/text-with-tooltip.tsx @@ -12,7 +12,7 @@ const TextWithTooltip = ({text, numberOfLines}: {text: string; numberOfLines: nu const [isFinalized, setIsFinalized] = useState(false); useLayoutEffect(() => { - if (textRef?.current && comparisonTextRef?.current) { + if (!isFinalized && textRef?.current && comparisonTextRef?.current) { setIsFinalized(true); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore @@ -22,7 +22,7 @@ const TextWithTooltip = ({text, numberOfLines}: {text: string; numberOfLines: nu const comparisonTextHeight = comparisonTextRef?.current?.getBoundingClientRect().height; setShowTooltip(textHeight < comparisonTextHeight); } - }, [isFinalized]); + }); const textElement = (