From f7b28556b0900deba9c91849deb6218683d0b37e Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Sun, 8 Jun 2025 22:48:50 +0330 Subject: [PATCH] fix build --- .env | 4 +- src/chatbot/Chatbot.tsx | 131 +++++++++++-------------- src/chatbot/hooks/useSocketHandlers.ts | 49 +++++---- 3 files changed, 86 insertions(+), 98 deletions(-) diff --git a/.env b/.env index ae75762..3a5862f 100644 --- a/.env +++ b/.env @@ -1,6 +1,6 @@ VITE_TOKEN_NAME = 'dzone_token' VITE_REFRESH_TOKEN_NAME = 'dzone_refresh_token' -# VITE_BASE_URL = 'https://api-dzone.danakcorp.com' -VITE_BASE_URL = 'http://localhost:4000' +VITE_BASE_URL = 'https://api-dzone.danakcorp.com' +# VITE_BASE_URL = 'http://localhost:4000' VITE_SLUG_ID = 'slug_id' \ No newline at end of file diff --git a/src/chatbot/Chatbot.tsx b/src/chatbot/Chatbot.tsx index a8fe73c..9efdbae 100644 --- a/src/chatbot/Chatbot.tsx +++ b/src/chatbot/Chatbot.tsx @@ -55,8 +55,8 @@ const Chatbot: FC = ({ isOpen, onClose }) => { const [currentSessionId, setCurrentSessionId] = useState(null); const [socket, setSocket] = useState(null); const [showChatbot, setShowChatbot] = useState(false); - const [showConnectionMessage, setShowConnectionMessage] = - useState(false); + // const [showConnectionMessage, setShowConnectionMessage] = + // useState(false); const [reconnectAttempts, setReconnectAttempts] = useState(0); const maxReconnectAttempts = 5; @@ -73,7 +73,6 @@ const Chatbot: FC = ({ isOpen, onClose }) => { addMessage, addSystemMessage, updateMessage, - clearMessages, } = useMessages(); const { setupSocketHandlers } = useSocketHandlers({ socket, @@ -202,7 +201,7 @@ const Chatbot: FC = ({ isOpen, onClose }) => { // Show connection message only briefly when status changes useEffect(() => { // Always show connection status, don't hide it - setShowConnectionMessage(true); + // setShowConnectionMessage(true); return () => { if (connectionTimeoutRef.current) { @@ -302,24 +301,24 @@ const Chatbot: FC = ({ isOpen, onClose }) => { }); }; - const joinChat = (sessionId: string) => { - if (!socket || !socket.connected) { - addSystemMessage("اتصال Socket.IO برقرار نیست", "error"); - return; - } + // const joinChat = (sessionId: string) => { + // if (!socket || !socket.connected) { + // addSystemMessage("اتصال Socket.IO برقرار نیست", "error"); + // return; + // } - // Get user ID from localStorage or use a default - const userId = - localStorage.getItem(import.meta.env.VITE_USER_ID_KEY || "user_id") || - localStorage.getItem("userId") || - "anonymous_user"; + // // Get user ID from localStorage or use a default + // const userId = + // localStorage.getItem(import.meta.env.VITE_USER_ID_KEY || "user_id") || + // localStorage.getItem("userId") || + // "anonymous_user"; - console.log(`🔄 Joining chat session: ${sessionId}`); - socket.emit(SOCKET_EVENTS.JOIN_CHAT, { - sessionId: sessionId, - userId: userId, - }); - }; + // console.log(`🔄 Joining chat session: ${sessionId}`); + // socket.emit(SOCKET_EVENTS.JOIN_CHAT, { + // sessionId: sessionId, + // userId: userId, + // }); + // }; const handleSendMessage = () => { const message = inputValue.trim(); @@ -459,35 +458,32 @@ const Chatbot: FC = ({ isOpen, onClose }) => { return (
{/* Header */}

چت بات داناک

{/* Always show a compact connection status */}
{connectionInfo.icon}
@@ -520,9 +516,8 @@ const Chatbot: FC = ({ isOpen, onClose }) => { return (
{message.isUser && (
@@ -530,41 +525,37 @@ const Chatbot: FC = ({ isOpen, onClose }) => {
)}
{message.timestamp.toLocaleTimeString("fa-IR", { hour: "2-digit", @@ -626,23 +617,21 @@ const Chatbot: FC = ({ isOpen, onClose }) => { isProcessing || connectionStatus !== "connected" } - className={`ml-2 ${ - inputValue.trim() === "" || + className={`ml-2 ${inputValue.trim() === "" || isProcessing || connectionStatus !== "connected" - ? "bg-gray-300" - : "bg-blue-600 hover:bg-blue-700" - } text-white rounded-full w-9 h-9 flex items-center justify-center focus:outline-none transition-colors flex-shrink-0`} + ? "bg-gray-300" + : "bg-blue-600 hover:bg-blue-700" + } text-white rounded-full w-9 h-9 flex items-center justify-center focus:outline-none transition-colors flex-shrink-0`} >
diff --git a/src/chatbot/hooks/useSocketHandlers.ts b/src/chatbot/hooks/useSocketHandlers.ts index 189501e..31f926c 100644 --- a/src/chatbot/hooks/useSocketHandlers.ts +++ b/src/chatbot/hooks/useSocketHandlers.ts @@ -24,7 +24,6 @@ export const useSocketHandlers = ({ updateMessage, addSystemMessage, setCurrentSessionId, - isProcessing, }: UseSocketHandlersProps) => { // Keep track of the current bot message like in the JS version const botMessageRef = useRef<{ @@ -325,30 +324,30 @@ export const useSocketHandlers = ({ }; // Helper function to format text with markdown-like syntax -const formatText = (text: string) => { - if (!text) return ""; +// const formatText = (text: string) => { +// if (!text) return ""; - // Clean the text first to avoid HTML injection - const cleanedText = text - .replace(/&/g, "&") - .replace(//g, ">") - .replace(/"/g, """) - .replace(/'/g, "'"); +// // Clean the text first to avoid HTML injection +// const cleanedText = text +// .replace(/&/g, "&") +// .replace(//g, ">") +// .replace(/"/g, """) +// .replace(/'/g, "'"); - // Format with markdown-like syntax and handle newlines properly - const formattedText = cleanedText - // Bold text - .replace(/\*\*(.*?)\*\*/g, "$1") - // Italic text - .replace(/\*(.*?)\*/g, "$1") - // Line breaks - ensure they work properly with proper spacing - .replace(/\n/g, "
") - // Links (optional) - .replace( - /\[([^\]]+)\]\(([^)]+)\)/g, - '$1' - ); +// // Format with markdown-like syntax and handle newlines properly +// const formattedText = cleanedText +// // Bold text +// .replace(/\*\*(.*?)\*\*/g, "$1") +// // Italic text +// .replace(/\*(.*?)\*/g, "$1") +// // Line breaks - ensure they work properly with proper spacing +// .replace(/\n/g, "
") +// // Links (optional) +// .replace( +// /\[([^\]]+)\]\(([^)]+)\)/g, +// '$1' +// ); - return formattedText; -}; +// return formattedText; +// };