| 1 |
import { createSlotFill } from '@wordpress/components' |
| 2 |
import { useEffect, useState } from '@wordpress/element' |
| 3 |
import { registerPlugin, unregisterPlugin } from '@wordpress/plugins' |
| 4 |
import { ChatSettings } from '@chat/ChatSettings' |
| 5 |
import { ChatButton } from '@chat/components/ChatButton' |
| 6 |
import { ChatDialog } from '@chat/components/ChatDialog' |
| 7 |
import { motion, AnimatePresence } from 'framer-motion' |
| 8 |
|
| 9 |
export const Chat = () => { |
| 10 |
const [showChat, setShowChat] = useState(window.extChatData?.showChat) |
| 11 |
const [showDialog, setShowDialog] = useState(false) |
| 12 |
|
| 13 |
useEffect(() => { |
| 14 |
const { Fill } = createSlotFill('Extendify/Assist/Settings') |
| 15 |
registerPlugin('extendify-chat-settings', { |
| 16 |
render: () => ( |
| 17 |
<Fill> |
| 18 |
<ChatSettings |
| 19 |
showChat={showChat} |
| 20 |
setShowChat={setShowChat} |
| 21 |
/> |
| 22 |
</Fill> |
| 23 |
), |
| 24 |
}) |
| 25 |
return () => unregisterPlugin('extendify-chat-settings') |
| 26 |
}, [showChat]) |
| 27 |
|
| 28 |
if (!showChat) return null |
| 29 |
|
| 30 |
return ( |
| 31 |
<> |
| 32 |
<ChatButton |
| 33 |
showDialog={showDialog} |
| 34 |
onClick={() => setShowDialog(!showDialog)} |
| 35 |
/> |
| 36 |
<AnimatePresence> |
| 37 |
{showDialog && ( |
| 38 |
<motion.div |
| 39 |
key="chat-dialog" |
| 40 |
className="fixed bottom-0 right-0 z-high" |
| 41 |
initial={{ y: 15, opacity: 0 }} |
| 42 |
exit={{ y: 15, opacity: 0 }} |
| 43 |
transition={{ |
| 44 |
y: { duration: 0.25 }, |
| 45 |
opacity: { duration: 0.1 }, |
| 46 |
}} |
| 47 |
animate={{ y: 0, opacity: 1 }}> |
| 48 |
<ChatDialog setShowChat={setShowChat} /> |
| 49 |
</motion.div> |
| 50 |
)} |
| 51 |
</AnimatePresence> |
| 52 |
</> |
| 53 |
) |
| 54 |
} |
| 55 |
|