@@ -4,11 +4,13 @@ import { getKeyForObject, splitObjectByPrefix } from "../util";
4
4
import { useMethod , useConversation , useUIBox , useMountBox } from "../hooks" ;
5
5
import { EventListeners } from "../EventListeners" ;
6
6
import { UIBoxProps } from "../types" ;
7
+ import { useEffect } from "react" ;
7
8
8
9
type PopupProps = UIBoxProps < Talk . Popup > &
9
10
Talk . PopupOptions & {
10
11
highlightedWords ?: Parameters < Talk . Popup [ "setHighlightedWords" ] > [ 0 ] ;
11
12
popupRef ?: React . MutableRefObject < Talk . Popup | undefined > ;
13
+ show ?: boolean ;
12
14
} ;
13
15
14
16
export function Popup ( props : PopupProps ) {
@@ -27,6 +29,7 @@ function ActivePopup(props: PopupProps & { session: Talk.Session }) {
27
29
conversationId,
28
30
syncConversation,
29
31
asGuest,
32
+ show,
30
33
popupRef,
31
34
...optionsAndEvents
32
35
} = props ;
@@ -40,7 +43,20 @@ function ActivePopup(props: PopupProps & { session: Talk.Session }) {
40
43
useMethod ( box , presence , "setPresence" ) ;
41
44
useMethod ( box , highlightedWords , "setHighlightedWords" ) ;
42
45
useConversation ( session , box , syncConversation , conversationId , asGuest ) ;
43
- useMountBox ( box , undefined ) ;
46
+ const mounted = useMountBox ( box , { show : show ?? true } ) ;
47
+
48
+ useEffect ( ( ) => {
49
+ if ( show === undefined || ! mounted ) {
50
+ return ;
51
+ }
52
+
53
+ if ( show ) {
54
+ box ?. show ( ) ;
55
+ } else {
56
+ box ?. hide ( ) ;
57
+ }
58
+
59
+ } , [ show , mounted , box ] )
44
60
45
61
return < EventListeners target = { box } handlers = { events } /> ;
46
62
}
0 commit comments