From 4e0b6950792aa32e4b927de7a212d43178629470 Mon Sep 17 00:00:00 2001 From: Alex Kaminskii Date: Mon, 30 Jan 2023 14:40:18 +0100 Subject: [PATCH] refactor(player): pass MarkerClick callback on targets ingection --- .../Session/Player/ClickMapRenderer/ThinPlayer.tsx | 3 +-- frontend/app/player/web/WebPlayer.ts | 6 +----- frontend/app/player/web/addons/TargetMarker.ts | 14 ++++++-------- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/frontend/app/components/Session/Player/ClickMapRenderer/ThinPlayer.tsx b/frontend/app/components/Session/Player/ClickMapRenderer/ThinPlayer.tsx index f903804f4..886bb848c 100644 --- a/frontend/app/components/Session/Player/ClickMapRenderer/ThinPlayer.tsx +++ b/frontend/app/components/Session/Player/ClickMapRenderer/ThinPlayer.tsx @@ -24,7 +24,6 @@ function WebPlayer(props: any) { makeAutoObservable(state) ); setContextValue({ player: WebPlayerInst, store: PlayerStore }); - WebPlayerInst.setMarkerClick(onMarkerClick) return () => WebPlayerInst.clean(); }, [session.sessionId]); @@ -38,7 +37,7 @@ function WebPlayer(props: any) { contextValue.player.pause() contextValue.player.jump(jumpTimestamp) contextValue.player.scale() - setTimeout(() => { contextValue.player.showClickmap(insights) }, 250) + setTimeout(() => { contextValue.player.showClickmap(insights, onMarkerClick) }, 250) }, 500) } return () => { diff --git a/frontend/app/player/web/WebPlayer.ts b/frontend/app/player/web/WebPlayer.ts index ba6f557b6..2c7f33f45 100644 --- a/frontend/app/player/web/WebPlayer.ts +++ b/frontend/app/player/web/WebPlayer.ts @@ -113,14 +113,10 @@ export default class WebPlayer extends Player { this.screen.overlay.remove() // hack. TODO: 1.split Screen functionalities (overlay, mounter) 2. separate ClickMapPlayer class that does not create overlay this.targetMarker.injectTargets(...args) this.freeze().then(() => { - this.targetMarker.updateMarkedTargets() + this.targetMarker.injectTargets(...args) }) } - setMarkerClick = (...args: Parameters) => { - this.targetMarker.setOnMarkerClick(...args) - } - toggleUserName = (name?: string) => { this.screen.cursor.showTag(name) } diff --git a/frontend/app/player/web/addons/TargetMarker.ts b/frontend/app/player/web/addons/TargetMarker.ts index a31f5534e..1c8236d7d 100644 --- a/frontend/app/player/web/addons/TargetMarker.ts +++ b/frontend/app/player/web/addons/TargetMarker.ts @@ -39,7 +39,6 @@ export default class TargetMarker { private clickMapOverlay: HTMLDivElement | null = null private clickContainers: HTMLDivElement[] = [] private smallClicks: HTMLDivElement[] = [] - private onMarkerClick: (selector: string, innerText: string) => void static INITIAL_STATE: State = { markedTargets: null, activeTargetIndex: 0 @@ -137,7 +136,10 @@ export default class TargetMarker { } - injectTargets(selections: { selector: string, count: number, clickRage?: boolean }[] | null) { + injectTargets( + selections: { selector: string, count: number, clickRage?: boolean }[] | null, + onMarkerClick?: (selector: string, innerText: string) => void, + ) { if (selections) { const totalCount = selections.reduce((a, b) => { return a + b.count @@ -183,7 +185,7 @@ export default class TargetMarker { border.onclick = (e) => { e.stopPropagation() const innerText = el.innerText.length > 25 ? `${el.innerText.slice(0, 20)}...` : el.innerText - this.onMarkerClick?.(s.selector, innerText) + onMarkerClick?.(s.selector, innerText) this.clickContainers.forEach(container => { if (container.id === containerId) { container.style.visibility = "visible" @@ -202,7 +204,7 @@ export default class TargetMarker { overlay.onclick = (e) => { e.stopPropagation() - this.onMarkerClick('', '') + onMarkerClick?.('', '') this.clickContainers.forEach(container => { container.style.visibility = "hidden" }) @@ -228,8 +230,4 @@ export default class TargetMarker { } } - setOnMarkerClick(cb: (selector: string) => void) { - this.onMarkerClick = cb - } - }