@@ -8,12 +8,10 @@ Please see LICENSE files in the repository root for full details.
88import React , { type JSX } from "react" ;
99import { type Room , ClientEvent } from "matrix-js-sdk/src/matrix" ;
1010import { logger } from "matrix-js-sdk/src/logger" ;
11- import { type IWidget } from "matrix-widget-api" ;
1211
1312import { _t , _td } from "../../../languageHandler" ;
14- import AppTile from "../elements/AppTile " ;
13+ import type { TranslationKey } from "../../../languageHandler " ;
1514import Spinner from "../elements/Spinner" ;
16- import { MatrixClientPeg } from "../../../MatrixClientPeg" ;
1715import dis from "../../../dispatcher/dispatcher" ;
1816import AccessibleButton from "../elements/AccessibleButton" ;
1917import WidgetUtils , { type UserWidget } from "../../../utils/WidgetUtils" ;
@@ -28,13 +26,7 @@ import GenericElementContextMenu from "../context_menus/GenericElementContextMen
2826import RightPanelStore from "../../../stores/right-panel/RightPanelStore" ;
2927import { UPDATE_EVENT } from "../../../stores/AsyncStore" ;
3028import { setStickerpickerAttachedToSidebar } from "./StickerpickerSidebarStore" ;
31-
32- // This should be below the dialog level (4000), but above the rest of the UI (1000-2000).
33- // We sit in a context menu, so this should be given to the context menu.
34- const STICKERPICKER_Z_INDEX = 3500 ;
35-
36- // Key to store the widget's AppTile under in PersistedElement
37- const PERSISTED_ELEMENT_KEY = "stickerPicker" ;
29+ import StickerpickerHost , { PERSISTED_ELEMENT_KEY , STICKERPICKER_Z_INDEX } from "./StickerpickerHost" ;
3830
3931interface IProps {
4032 room : Room ;
@@ -61,7 +53,6 @@ export default class Stickerpicker extends React.PureComponent<IProps, IState> {
6153 public static currentWidget ?: UserWidget ;
6254
6355 private dispatcherRef ?: string ;
64-
6556 private prevSentVisibility ?: boolean ;
6657
6758 private popoverWidth = 340 ;
@@ -135,7 +126,7 @@ export default class Stickerpicker extends React.PureComponent<IProps, IState> {
135126 this . dispatcherRef = dis . register ( this . onAction ) ;
136127
137128 // Track updates to widget state in account data
138- MatrixClientPeg . safeGet ( ) . on ( ClientEvent . AccountData , this . updateWidget ) ;
129+ this . props . room . client . on ( ClientEvent . AccountData , this . updateWidget ) ;
139130
140131 if ( this . props . displayMode === "popover" ) {
141132 RightPanelStore . instance . on ( UPDATE_EVENT , this . onRightPanelStoreUpdate ) ;
@@ -145,8 +136,7 @@ export default class Stickerpicker extends React.PureComponent<IProps, IState> {
145136 }
146137
147138 public componentWillUnmount ( ) : void {
148- const client = MatrixClientPeg . get ( ) ;
149- if ( client ) client . removeListener ( ClientEvent . AccountData , this . updateWidget ) ;
139+ this . props . room . client . removeListener ( ClientEvent . AccountData , this . updateWidget ) ;
150140 if ( this . props . displayMode === "popover" ) {
151141 RightPanelStore . instance . off ( UPDATE_EVENT , this . onRightPanelStoreUpdate ) ;
152142 }
@@ -260,92 +250,44 @@ export default class Stickerpicker extends React.PureComponent<IProps, IState> {
260250 }
261251 }
262252
263- private getStickerpickerApp ( ) : IWidget | null {
264- const stickerpickerWidget = this . state . stickerpickerWidget ;
265- if ( ! stickerpickerWidget ?. content ?. url ) return null ;
266-
267- stickerpickerWidget . content . name = stickerpickerWidget . content . name || _t ( "common|stickerpack" ) ;
268-
269- return {
270- id : stickerpickerWidget . id ,
271- url : stickerpickerWidget . content . url ,
272- name : stickerpickerWidget . content . name ,
273- type : stickerpickerWidget . content . type ,
274- data : stickerpickerWidget . content . data ,
275- creatorUserId : stickerpickerWidget . content . creatorUserId || stickerpickerWidget . sender ,
276- } ;
277- }
278-
279- private renderStickerpickerApp ( stickerApp : IWidget , sidebarMode = false ) : JSX . Element {
280- const stickerpickerWidget = this . state . stickerpickerWidget ! ;
281-
282- return (
283- < AppTile
284- app = { stickerApp }
285- room = { this . props . room }
286- threadId = { this . props . threadId }
287- fullWidth = { true }
288- userId = { MatrixClientPeg . safeGet ( ) . credentials . userId ! }
289- creatorUserId = { stickerpickerWidget . sender || MatrixClientPeg . safeGet ( ) . credentials . userId ! }
290- waitForIframeLoad = { true }
291- showMenubar = { ! sidebarMode }
292- onEditClick = { this . launchManageIntegrations }
293- onDeleteClick = { this . removeStickerpickerWidgets }
294- onAttachToSidebarClick = { this . props . displayMode === "popover" ? this . attachToSidebar : undefined }
295- showTitle = { false }
296- showPopout = { false }
297- handleMinimisePointerEvents = { true }
298- userWidget = { true }
299- showLayoutButtons = { false }
300- />
301- ) ;
302- }
303-
304- public getStickerpickerContent ( ) : JSX . Element {
253+ private renderStickerpickerWidget ( displayMode : "popover" | "sidebar" ) : JSX . Element {
305254 if ( this . state . imError ) {
306255 return this . errorStickerpickerContent ( ) ;
307256 }
308257
309- const stickerApp = this . getStickerpickerApp ( ) ;
310-
311- if ( stickerApp ) {
258+ if ( this . state . stickerpickerWidget ?. content ?. url ) {
312259 return (
313- < div className = "mx_Stickers_content_container" >
314- < div
315- id = "stickersContent"
316- className = "mx_Stickers_content"
317- style = { {
318- border : "none" ,
319- height : this . popoverHeight ,
320- width : this . popoverWidth ,
321- } }
322- >
323- < PersistedElement persistKey = { PERSISTED_ELEMENT_KEY } zIndex = { STICKERPICKER_Z_INDEX } >
324- { this . renderStickerpickerApp ( stickerApp ) }
325- </ PersistedElement >
326- </ div >
327- </ div >
260+ < StickerpickerHost
261+ room = { this . props . room }
262+ threadId = { this . props . threadId }
263+ stickerpickerWidget = { this . state . stickerpickerWidget }
264+ displayMode = { displayMode }
265+ popoverWidth = { this . popoverWidth }
266+ popoverHeight = { this . popoverHeight }
267+ onEditClick = { this . launchManageIntegrations }
268+ onDeleteClick = { this . removeStickerpickerWidgets }
269+ onAttachToSidebarClick = { this . attachToSidebar }
270+ />
328271 ) ;
329272 }
330273
331274 return this . defaultStickerpickerContent ( ) ;
332275 }
333276
334- public getSidebarStickerpickerContent ( ) : JSX . Element {
335- if ( this . state . imError ) {
336- return this . errorStickerpickerContent ( ) ;
337- }
277+ public getStickerpickerContent ( ) : JSX . Element {
278+ return this . renderStickerpickerWidget ( "popover" ) ;
279+ }
338280
281+ public getSidebarStickerpickerContent ( ) : JSX . Element {
339282 if ( ! this . state . widgetStateLoaded ) {
340283 return < div className = "mx_Stickers_sidebar" > { this . loadingStickerpickerContent ( ) } </ div > ;
341284 }
342285
343- const stickerApp = this . getStickerpickerApp ( ) ;
344- if ( stickerApp ) {
345- return < div className = "mx_Stickers_sidebar" > { this . renderStickerpickerApp ( stickerApp , true ) } </ div > ;
286+ if ( this . state . imError ) {
287+ return this . errorStickerpickerContent ( ) ;
346288 }
347289
348- return < div className = "mx_Stickers_sidebarPlaceholder " > { this . defaultStickerpickerContent ( ) } </ div > ;
290+ return < div className = "mx_Stickers_sidebar " > { this . renderStickerpickerWidget ( "sidebar" ) } </ div > ;
349291 }
350292
351293 /**
0 commit comments