@@ -40,55 +40,28 @@ def add_hooks(self) -> list[str | rx.Var]:
4040 return [
4141 rx .Var (
4242 f"""useEffect(() => {{
43- if (typeof window === 'undefined') return;
44-
45- // Skip if already initialized
46- if (window.__plainChatInitialized) return;
47-
48- const customerDetails = {{
49- fullName: { self .full_name !s} ,
50- shortName: { self .short_name !s} ,
51- chatAvatarUrl: { self .chat_avatar_url !s} ,
52- }};
53-
54- // Add email if provided
55- if ({ self .email !s} ) {{
56- customerDetails.email = { self .email !s} ;
57- }}
58- if ({ self .email_hash !s} ) {{
59- customerDetails.emailHash = { self .email_hash !s} ;
60- }}
61-
62- const initOptions = {{
63- appId: '{ PLAIN_APP_ID } ',
64- hideLauncher: { self .hide_launcher !s} ,
65- hideBranding: true,
66- theme: 'auto',
67- customerDetails: customerDetails,
68- threadDetails: {{
69- externalId: { self .external_id !s} ,
70- }},
71- }};
72-
73- // Add requireAuthentication if true
74- if ({ self .require_authentication !s} ) {{
75- initOptions.requireAuthentication = true;
76- }}
77-
78- const doInit = () => {{
79- Plain.init(initOptions);
80- window.__plainChatInitialized = true;
81- }};
82-
83- if (window.Plain) {{
84- doInit();
85- return;
86- }}
87-
8843 const script = document.createElement('script');
8944 script.async = false;
9045 script.src = 'https://chat.cdn-plain.com/index.js';
91- script.onload = doInit;
46+ script.onload = () => {{
47+ Plain.init({{
48+ appId: '{ PLAIN_APP_ID } ',
49+ hideLauncher: { self .hide_launcher !s} ,
50+ hideBranding: true,
51+ theme: 'auto',
52+ customerDetails: {{
53+ fullName: { self .full_name !s} ,
54+ shortName: { self .short_name !s} ,
55+ chatAvatarUrl: { self .chat_avatar_url !s} ,
56+ email: { self .email !s} ,
57+ emailHash: { self .email_hash !s} ,
58+ }},
59+ threadDetails: {{
60+ externalId: { self .external_id !s} ,
61+ }},
62+ requireAuthentication: { self .require_authentication !s} ,
63+ }});
64+ }};
9265 document.head.appendChild(script);
9366}}, [])"""
9467 )
0 commit comments