Skip to content

Commit b9ad883

Browse files
committed
chore: cleanup
1 parent 8e22381 commit b9ad883

File tree

11 files changed

+15
-47
lines changed

11 files changed

+15
-47
lines changed

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,12 @@ When using the JavaScript API in plain HTML/JS (requires standalone bundle), you
107107
```javascript
108108
const botController = qaBot({...});
109109

110-
// Add a message to the chat
111110
botController.addMessage("Hello World!");
112-
113-
// Set user login status
114111
botController.setBotIsLoggedIn(true);
115-
116-
// Control chat window (floating mode only)
112+
// (floating mode only)
117113
botController.openChat();
118114
botController.closeChat();
119115
botController.toggleChat();
120-
121116
// Cleanup
122117
botController.destroy();
123118
```

local-demo.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ function updateBotLoginStatus(isLoggedIn) {
5656
function setupLoginCheckbox() {
5757
const loginCheckbox = document.getElementById('user-logged-in');
5858
if (loginCheckbox) {
59-
// Initialize checkbox state based on current cookie
6059
loginCheckbox.checked = isUserLoggedIn();
6160

6261
loginCheckbox.addEventListener('change', (e) => {

src/components/BotController.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ const BotController = React.forwardRef(({
5656
}
5757
});
5858

59-
// Set up the simplified imperative API (only addMessage)
59+
// An imperative method to add a message to bot
60+
// wrapping react-chatbotify `insertMessage`
6061
useImperativeHandle(ref, () => ({
6162
// Add a message to the chat
6263
addMessage: (message) => {
@@ -65,8 +66,6 @@ const BotController = React.forwardRef(({
6566
}
6667
}
6768
}), [messages]);
68-
69-
// This component doesn't render anything
7069
return null;
7170
});
7271

src/components/QABot.js

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,11 @@ import useUpdateHeader from '../hooks/useUpdateHeader';
1010
import useRingEffect from '../hooks/useRingEffect';
1111
import { DEFAULT_CONFIG } from '../config/constants';
1212

13-
/**
14-
* Generate a unique session ID
15-
* @returns {string} A unique session identifier
16-
*/
13+
1714
const generateSessionId = () => {
1815
return `qa_bot_session_${uuidv4()}`;
1916
};
2017

21-
/**
22-
* Get or create a session ID from localStorage
23-
* @returns {string} A session identifier
24-
*/
2518
const getOrCreateSessionId = () => {
2619
// Check if we already have a session ID in localStorage
2720
for (let i = 0; i < localStorage.length; i++) {
@@ -33,12 +26,19 @@ const getOrCreateSessionId = () => {
3326
}
3427
}
3528
}
36-
37-
// No existing session found, generate a new one
3829
const newSessionId = generateSessionId();
3930
localStorage.setItem(newSessionId, newSessionId);
4031
return newSessionId;
4132
};
33+
34+
const buildWelcomeMessage = (isLoggedIn, welcomeMessage) => {
35+
if (isLoggedIn) {
36+
return welcomeMessage || DEFAULT_CONFIG.WELCOME_MESSAGE;
37+
} else {
38+
return DEFAULT_CONFIG.WELCOME_MESSAGE_LOGGED_OUT;
39+
}
40+
}
41+
4242
/**
4343
* Q&A Bot Component (Controlled)
4444
*
@@ -53,15 +53,6 @@ const getOrCreateSessionId = () => {
5353
* @param {string} [props.welcome='Hello! What can I help you with?'] - Welcome message
5454
* @returns {JSX.Element}
5555
*/
56-
57-
const buildWelcomeMessage = (isLoggedIn, welcomeMessage) => {
58-
if (isLoggedIn) {
59-
return welcomeMessage || DEFAULT_CONFIG.WELCOME_MESSAGE;
60-
} else {
61-
return DEFAULT_CONFIG.WELCOME_MESSAGE_LOGGED_OUT;
62-
}
63-
}
64-
6556
const QABot = React.forwardRef((props, botRef) => {
6657
const {
6758
apiKey,
@@ -120,10 +111,8 @@ const QABot = React.forwardRef((props, botRef) => {
120111
isLoggedIn: isBotLoggedIn
121112
});
122113

123-
// Use the AI query handling hook
124114
const handleQuery = useHandleAIQuery(finalApiKey, sessionId, setCurrentQueryId);
125115

126-
// Use the chat flow hook
127116
const flow = useChatFlow({
128117
welcomeMessage,
129118
isBotLoggedIn,

src/config/constants.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Default configuration values for the QA Bot
21
export const DEFAULT_CONFIG = {
32
LOGIN_URL: '/login',
43
PROMPT_TEXT: 'Questions should stand alone and not refer to previous ones.',
@@ -8,24 +7,20 @@ export const DEFAULT_CONFIG = {
87
WELCOME_MESSAGE_LOGOUT_TRANSITION: 'You have been logged out.',
98
API_ENDPOINT: 'https://access-ai.ccs.uky.edu/api/query',
109

11-
// Error messages
1210
ERRORS: {
1311
API_UNAVAILABLE: 'Unable to contact the Q&A Bot. Please try again later.',
1412
},
1513

16-
// Behavior configuration
1714
BEHAVIOR: {
1815
SHOW_RATING_AFTER_FAILED_QUERY: true
1916
},
2017

21-
// Theme defaults
2218
THEME: {
2319
PRIMARY_COLOR: '#1a5b6e',
2420
SECONDARY_COLOR: '#107180',
2521
FONT_FAMILY: 'Arial, sans-serif'
2622
},
2723

28-
// Chat bot UI defaults
2924
CHATBOT: {
3025
TITLE: 'ACCESS Q&A Bot',
3126
AVATAR_URL: 'https://support.access-ci.org/themes/contrib/asp-theme/images/icons/ACCESS-arrrow.svg',

src/hooks/useGetLastUserQuery.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const useGetLastUserQuery = () => {
1111
const history = JSON.parse(historyString);
1212
if (!Array.isArray(history)) return null;
1313

14-
// Find the most recent USER message (latest timestamp)
1514
let latestUserMessage = null;
1615
let latestTimestamp = null;
1716

src/hooks/useHandleAIQuery.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ const useHandleAIQuery = (apiKey, sessionId, setCurrentQueryId) => {
2929
'X-Query-ID': actualQueryId
3030
};
3131

32-
// console.log('| 📫 headers for AI query:', headers);
33-
3432
try {
3533
const requestOptions = {
3634
method: 'POST',

src/hooks/useRingEffect.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ const useRingEffect = (ringEffect, containerRef) => {
2424
}
2525
}, 500); // 500ms delay to make sure its rendered and gain user attention
2626

27-
// Cleanup function
2827
return () => {
2928
clearTimeout(timeoutId);
3029
};
31-
}, [ringEffect, containerRef]); // Only run when ringEffect or containerRef changes
30+
}, [ringEffect, containerRef]);
3231
};
3332

3433
export default useRingEffect;

src/hooks/useThemeColors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const useThemeColors = (containerRef, defaultColors = {}) => {
1919
return containerValue.trim();
2020
}
2121

22-
// Then check parent (useful for web component shadow DOM)
22+
// Then check parent
2323
if (containerRef.current.parentElement) {
2424
const parentStyle = getComputedStyle(containerRef.current.parentElement);
2525
const parentValue = parentStyle.getPropertyValue(name);

src/lib.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export function qaBot(config) {
6464
const root = ReactDOM.createRoot(config.target);
6565
let wrapperRef = { current: null };
6666

67-
// Mount React component directly
6867
root.render(
6968
<React.StrictMode>
7069
<ProgrammaticQABot
@@ -80,7 +79,6 @@ export function qaBot(config) {
8079
</React.StrictMode>
8180
);
8281

83-
// Return controller object that delegates to the wrapper
8482
return {
8583
addMessage: (message) => wrapperRef.current?.addMessage(message),
8684
setBotIsLoggedIn: (status) => wrapperRef.current?.setBotIsLoggedIn(status),
@@ -93,6 +91,4 @@ export function qaBot(config) {
9391
}
9492
};
9593
}
96-
97-
// Default export - prioritize qaBot function for standalone usage
9894
export default qaBot;

0 commit comments

Comments
 (0)