'use client'; import { DiscordIcon } from '@/components/icons/discord'; import { websiteConfig } from '@/config/website'; import { useMediaQuery } from '@/hooks/use-media-query'; import WidgetBot from '@widgetbot/react-embed'; import { useEffect, useRef, useState } from 'react'; /** * Discord Widget, shows the channels and messages in the discord server * * @deprecated * This feature is deprecated for Discord Widget can not be used anymore. * * https://docs.widgetbot.io/embed/react-embed/ */ export default function DiscordWidget() { if (!websiteConfig.features.enableDiscordWidget) { return null; } const serverId = process.env.NEXT_PUBLIC_DISCORD_WIDGET_SERVER_ID as string; const channelId = process.env.NEXT_PUBLIC_DISCORD_WIDGET_CHANNEL_ID as string; if (!serverId || !channelId) { return null; } const [open, setOpen] = useState(false); const widgetRef = useRef(null); const { device, width: windowWidth, height: windowHeight } = useMediaQuery(); let widgetWidth = 800; let widgetHeight = 600; if (device === 'mobile') { widgetWidth = windowWidth ? Math.floor(windowWidth * 0.9) : 320; widgetHeight = windowHeight ? Math.floor(windowHeight * 0.8) : 400; } else if (device === 'tablet' || device === 'sm') { widgetWidth = windowWidth ? Math.floor(windowWidth * 0.9) : 600; widgetHeight = windowHeight ? Math.floor(windowHeight * 0.8) : 480; } useEffect(() => { if (!open) return; function handleClick(e: MouseEvent) { if (widgetRef.current && !widgetRef.current.contains(e.target as Node)) { setOpen(false); } } document.addEventListener('mousedown', handleClick); return () => document.removeEventListener('mousedown', handleClick); }, [open]); return (
{/* discord icon button, show in bottom right corner */} {!open && ( )} {/* discord widget expand layer */} {open && (
)}
); }