shopify-chatbot-widget 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "shopify-chatbot-widget",
3
3
  "private": false,
4
- "version": "1.0.1",
4
+ "version": "1.0.3",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useRef } from 'react';
1
+ import React, { useEffect, useRef,useMemo } from 'react';
2
2
  import { Spin } from 'antd';
3
3
  import { LoadingOutlined, CheckCircleOutlined, CloseCircleOutlined } from '@ant-design/icons';
4
4
  import Typing from './Typing';
@@ -133,12 +133,13 @@ const ChatMessages: React.FC<ChatMessagesProps> = ({
133
133
  return () => clearTimeout(timeout);
134
134
  }, [messages]);
135
135
 
136
- const getRandomSuggestions = (count: number = 2) => {
136
+ const randomSuggestions = useMemo(() => {
137
+ const count = 2;
137
138
  if (messagesSuggestions.length <= count) return messagesSuggestions;
138
-
139
+
139
140
  const shuffled = [...messagesSuggestions].sort(() => 0.5 - Math.random());
140
141
  return shuffled.slice(0, count);
141
- };
142
+ }, [messagesSuggestions, messages.length]); // Recalculate when suggestions or message count changes
142
143
 
143
144
 
144
145
  if (isfetchingMessage || isLoading || !messages) {
@@ -219,9 +220,9 @@ const ChatMessages: React.FC<ChatMessagesProps> = ({
219
220
  </div>
220
221
 
221
222
  {/* ADD suggestions here */}
222
- {isLastAssistantMessage && messagesSuggestions.length > 0 && (
223
+ {isLastAssistantMessage && randomSuggestions.length > 0 && (
223
224
  <InlineSuggestions
224
- suggestions={getRandomSuggestions(2)}
225
+ suggestions={randomSuggestions}
225
226
  colorCode={colorCode}
226
227
  onSuggestionClick={sendMessageSuggestion}
227
228
  />
@@ -270,9 +271,9 @@ const ChatMessages: React.FC<ChatMessagesProps> = ({
270
271
  </div>
271
272
 
272
273
  {/* ADD suggestions here - MOVED OUTSIDE the chat-msg div */}
273
- {isLastAssistantMessage && messagesSuggestions.length > 0 && (
274
+ {isLastAssistantMessage && randomSuggestions.length > 0 && (
274
275
  <InlineSuggestions
275
- suggestions={getRandomSuggestions(2)}
276
+ suggestions={randomSuggestions}
276
277
  colorCode={colorCode}
277
278
  onSuggestionClick={sendMessageSuggestion}
278
279
  />
@@ -555,7 +555,6 @@ const socket = useChatSocket(sessionId, handleSocketData);
555
555
 
556
556
 
557
557
  <div className="chatbot-input-area">
558
- {/* <Suggestions sendMessageSuggestion={sendMessageSuggestion} colorCode={colorCode} suggestions={messagesSuggestions} /> */}
559
558
 
560
559
  <ChatInput
561
560
  userMessage={input}
@@ -1,11 +1,11 @@
1
1
 
2
2
 
3
3
  const config = {
4
- // apiUrl:'https://jawebcrm.onrender.com/api/',
5
- // websocketUrl:'wss://jawebcrm.onrender.com/ws' ,
4
+ apiUrl:'https://jawebcrm.onrender.com/api/',
5
+ websocketUrl:'wss://jawebcrm.onrender.com/ws' ,
6
6
 
7
- apiUrl:'http://localhost:8000/api/',
8
- websocketUrl:'ws://localhost:8000/ws',
7
+ // apiUrl:'http://localhost:8000/api/',
8
+ // websocketUrl:'ws://localhost:8000/ws',
9
9
 
10
10
  };
11
11
  export default config;