From 332671570b4777c3b078b655d9eabae18a2803d8 Mon Sep 17 00:00:00 2001 From: Andrew Charneski Date: Tue, 26 Nov 2024 02:30:33 -0500 Subject: [PATCH] wip --- .gitignore | 1 - webapp/chat-app/.eslintrc.json | 40 +++++++++++++ webapp/chat-app/.gitignore | 23 ++++++++ webapp/chat-app/.prettierrc | 9 +++ webapp/chat-app/src/App.test.js | 12 +++- webapp/chat-app/src/App.tsx | 52 ++++++++++++---- webapp/chat-app/src/components/Chat/index.tsx | 31 ++++++++-- .../chat-app/src/components/ChatInterface.tsx | 36 +++++++---- webapp/chat-app/src/components/Header.tsx | 20 ++++++- webapp/chat-app/src/components/InputArea.tsx | 19 +++++- .../chat-app/src/components/Layout/index.tsx | 15 ++++- webapp/chat-app/src/components/Menu/Menu.tsx | 33 ++++++++--- .../src/components/Menu/ThemeMenu.tsx | 35 +++++++---- webapp/chat-app/src/components/Menu/index.ts | 9 ++- .../chat-app/src/components/MessageList.tsx | 24 ++++++-- webapp/chat-app/src/components/Tabs/index.tsx | 33 +++++++++-- webapp/chat-app/src/hooks/index.ts | 8 ++- webapp/chat-app/src/hooks/useTheme.ts | 12 +++- webapp/chat-app/src/hooks/useWebSocket.ts | 14 ++++- webapp/chat-app/src/index.js | 20 ++++++- webapp/chat-app/src/index.tsx | 18 +++++- webapp/chat-app/src/services/websocket.ts | 42 ++++++++++--- webapp/chat-app/src/setupTests.js | 33 +++++++++++ webapp/chat-app/src/store/Provider.tsx | 17 +++++- webapp/chat-app/src/store/index.ts | 18 +++++- .../chat-app/src/store/slices/configSlice.ts | 33 ++++++++++- .../chat-app/src/store/slices/messageSlice.ts | 20 ++++++- webapp/chat-app/src/store/slices/uiSlice.ts | 8 +++ webapp/chat-app/src/store/slices/userSlice.ts | 20 ++++++- webapp/chat-app/src/styled.d.ts | 39 ++++++++++++ webapp/chat-app/src/styles/GlobalStyles.ts | 43 ++++++++++++-- webapp/chat-app/src/themes/ThemeProvider.tsx | 12 +++- webapp/chat-app/src/themes/globalStyles.ts | 41 ++++++++++++- webapp/chat-app/src/themes/index.ts | 7 ++- webapp/chat-app/src/themes/themes.ts | 49 +++++++++++++++ ....ts (Additional changes for theme objects) | 36 +++++++++++ webapp/chat-app/src/types.ts | 36 +++++++++++ webapp/chat-app/src/types/index.ts | 33 ++++++++++- webapp/chat-app/src/types/styled.d.ts | 49 +++++++++++++++ webapp/chat-app/src/utils/logger.ts | 59 +++++++++++++++++++ webapp/chat-app/tsconfig.json | 12 ++-- 41 files changed, 969 insertions(+), 102 deletions(-) create mode 100644 webapp/chat-app/.eslintrc.json create mode 100644 webapp/chat-app/.gitignore create mode 100644 webapp/chat-app/.prettierrc create mode 100644 webapp/chat-app/src/themes/themes.ts (Additional changes for theme objects) create mode 100644 webapp/chat-app/src/utils/logger.ts diff --git a/.gitignore b/.gitignore index 82a24a15..78fcf9c7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ reports/ build/ .gradle/ .idea/ -.* openai.key *.log *.log.* diff --git a/webapp/chat-app/.eslintrc.json b/webapp/chat-app/.eslintrc.json new file mode 100644 index 00000000..3cfef177 --- /dev/null +++ b/webapp/chat-app/.eslintrc.json @@ -0,0 +1,40 @@ +{ + "env": { + "browser": true, + "es2021": false, + "node": false + }, + "extends": [ + "eslint:recommended", + "plugin:react/recommended", + "plugin:@typescript-eslint/recommended", + "plugin:react-hooks/recommended" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaFeatures": { + "jsx": true + }, + "ecmaVersion": 12, + "sourceType": "module" + }, + "plugins": [ + "react", + "@typescript-eslint", + "react-hooks" + ], + "rules": { + "react/react-in-jsx-scope": "off", + "react/prop-types": "off", + "@typescript-eslint/explicit-module-boundary-types": "off", + "@typescript-eslint/no-explicit-any": "warn", + "@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }], + "react-hooks/rules-of-hooks": "error", + "react-hooks/exhaustive-deps": "warn" + }, + "settings": { + "react": { + "version": "detect" + } + } +} \ No newline at end of file diff --git a/webapp/chat-app/.gitignore b/webapp/chat-app/.gitignore new file mode 100644 index 00000000..f1f26100 --- /dev/null +++ b/webapp/chat-app/.gitignore @@ -0,0 +1,23 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +node_modules +.pnp +.pnp.js + +# testing +coverage + +# production +build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/webapp/chat-app/.prettierrc b/webapp/chat-app/.prettierrc new file mode 100644 index 00000000..a4878bf8 --- /dev/null +++ b/webapp/chat-app/.prettierrc @@ -0,0 +1,9 @@ +{ + "semi": true, + "trailingComma": "es5", + "singleQuote": true, + "printWidth": 100, + "tabWidth": 2, + "useTabs": false, + "endOfLine": "auto" +} \ No newline at end of file diff --git a/webapp/chat-app/src/App.test.js b/webapp/chat-app/src/App.test.js index 1f03afee..67bcf101 100644 --- a/webapp/chat-app/src/App.test.js +++ b/webapp/chat-app/src/App.test.js @@ -1,8 +1,18 @@ -import { render, screen } from '@testing-library/react'; +import {render, screen} from '@testing-library/react'; import App from './App'; +console.log('Starting App component tests...'); + + test('renders learn react link', () => { + console.log('Testing: Rendering App component'); render(); + console.log('Testing: Searching for "learn react" text'); const linkElement = screen.getByText(/learn react/i); + console.log('Testing: Verifying element is in document'); expect(linkElement).toBeInTheDocument(); + console.log('Test completed successfully'); }); +afterAll(() => { + console.log('All App component tests completed'); +}); \ No newline at end of file diff --git a/webapp/chat-app/src/App.tsx b/webapp/chat-app/src/App.tsx index 68c60200..a833f20a 100644 --- a/webapp/chat-app/src/App.tsx +++ b/webapp/chat-app/src/App.tsx @@ -8,23 +8,51 @@ import ThemeProvider from './themes/ThemeProvider'; import {Menu} from "./components/Menu/Menu"; const App: React.FC = () => { + console.log('[App] Component rendering'); + const sessionId = websocket.getSessionId(); + const isConnected = websocket.isConnected(); + console.log('[App] WebSocket state:', { + sessionId, + isConnected, + }); + React.useEffect(() => { + console.log('[App] Component mounted'); + return () => { + console.log('[App] Component unmounting'); + }; + }, []); return ( - - -
- - -
-
+ {(() => { + console.log('[App] Rendering Provider with store'); + return ( + + {(() => { + console.log('[App] Rendering ThemeProvider'); + return ( + <> + +
+ + +
+ + ); + })()} +
+ ); + })()}
); }; +// Add version info to help with debugging +console.log('[App] Version 1.0.0 loaded'); + -export default App; +export default App; \ No newline at end of file diff --git a/webapp/chat-app/src/components/Chat/index.tsx b/webapp/chat-app/src/components/Chat/index.tsx index f80b8af9..ab0ed949 100644 --- a/webapp/chat-app/src/components/Chat/index.tsx +++ b/webapp/chat-app/src/components/Chat/index.tsx @@ -1,7 +1,7 @@ -import React from 'react'; -import styled from 'styled-components'; -import { DefaultTheme } from 'styled-components'; -import { Message } from '../../types'; +import React, {useEffect} from 'react'; +import styled, {DefaultTheme} from 'styled-components'; +import {Message} from '../../types'; +import {logger} from '../../utils/logger'; const ChatContainer = styled.div` display: flex; @@ -26,6 +26,26 @@ interface ChatProps { } const Chat: React.FC = ({ messages, onSendMessage }) => { + // Log component mount and updates + useEffect(() => { + logger.component('Chat', 'Component mounted'); + logger.component('Chat', 'Initial messages:', messages); + return () => { + logger.component('Chat', 'Component unmounting'); + }; + }, []); + // Log when messages change + useEffect(() => { + console.log('[Chat] Messages updated:', messages); + }, [messages]); + // Wrap onSendMessage to add logging + const handleSendMessage = (content: string) => { + console.log('[Chat] Sending message:', content); + onSendMessage(content); + }; + // Log render + console.log('[Chat] Rendering with', messages.length, 'messages'); + return ( @@ -37,5 +57,8 @@ const Chat: React.FC = ({ messages, onSendMessage }) => { ); }; +// Add display name for better debugging +Chat.displayName = 'Chat'; + export default Chat; \ No newline at end of file diff --git a/webapp/chat-app/src/components/ChatInterface.tsx b/webapp/chat-app/src/components/ChatInterface.tsx index 0d5d83ac..f815f1df 100644 --- a/webapp/chat-app/src/components/ChatInterface.tsx +++ b/webapp/chat-app/src/components/ChatInterface.tsx @@ -24,36 +24,50 @@ const ChatInterface: React.FC = ({ websocket, isConnected, }) => { + console.log('[ChatInterface] Rendering with props:', {propSessionId, isConnected}); const [sessionId] = useState(() => propSessionId || window.location.hash.slice(1) || 'new'); const dispatch = useDispatch(); const ws = useWebSocket(sessionId); useEffect(() => { + console.log('[ChatInterface] Setting up message handler for sessionId:', sessionId); + const handleMessage = (data: string) => { + console.log('[ChatInterface] Received message:', data); + const [id, version, content] = data.split(','); const timestamp = Date.now(); + const messageObject = { + id: `${id}-${timestamp}`, + content: content, + version, + type: id.startsWith('u') ? 'user' as const : 'response' as const, + timestamp, + }; + console.log('[ChatInterface] Dispatching message:', messageObject); - dispatch( - addMessage({ - id: `${id}-${timestamp}`, // Make IDs more unique - content: content, - version, - type: id.startsWith('u') ? 'user' : 'response', - timestamp, - }) - ); + dispatch(addMessage(messageObject)); }; websocket.addMessageHandler(handleMessage); - return () => websocket.removeMessageHandler(handleMessage); + return () => { + console.log('[ChatInterface] Cleaning up message handler for sessionId:', sessionId); + websocket.removeMessageHandler(handleMessage); + }; }, [dispatch, ws]); + const handleSendMessage = (msg: string) => { + console.log('[ChatInterface] Sending message:', msg); + ws.send(msg); + }; + return ( - ws.send(msg)}/> + ); }; +console.log('[ChatInterface] Component defined'); export default ChatInterface; \ No newline at end of file diff --git a/webapp/chat-app/src/components/Header.tsx b/webapp/chat-app/src/components/Header.tsx index 5ea39535..b078251f 100644 --- a/webapp/chat-app/src/components/Header.tsx +++ b/webapp/chat-app/src/components/Header.tsx @@ -21,10 +21,25 @@ interface HeaderProps { const Header: React.FC = ({onThemeChange}) => { const [currentTheme, setTheme] = useTheme(); + React.useEffect(() => { + console.log('Header mounted with theme:', currentTheme); + return () => { + console.log('Header unmounting'); + }; + }, []); + React.useEffect(() => { + console.log('Theme changed to:', currentTheme); + }, [currentTheme]); + const handleThemeChange = (e: React.ChangeEvent) => { + const newTheme = e.target.value as ThemeName; + console.log('Theme selection changed:', newTheme); + setTheme(newTheme); + }; + return ( - setTheme(e.target.value as any)}> + @@ -34,5 +49,8 @@ const Header: React.FC = ({onThemeChange}) => { ); }; +// Log when the component is defined +console.log('Header component defined'); + export default Header; \ No newline at end of file diff --git a/webapp/chat-app/src/components/InputArea.tsx b/webapp/chat-app/src/components/InputArea.tsx index 901c0b0a..cf0f79b5 100644 --- a/webapp/chat-app/src/components/InputArea.tsx +++ b/webapp/chat-app/src/components/InputArea.tsx @@ -22,21 +22,33 @@ interface InputAreaProps { const InputArea: React.FC = ({onSendMessage}) => { const [message, setMessage] = useState(''); + console.log('[InputArea] Rendering with message:', message); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); + console.log('[InputArea] Form submitted with message:', message); if (message.trim()) { + console.log('[InputArea] Sending message:', message); onSendMessage(message); setMessage(''); + console.log('[InputArea] Message sent and input cleared'); + } else { + console.log('[InputArea] Empty message, not sending'); } }; + const handleMessageChange = (e: React.ChangeEvent) => { + const newMessage = e.target.value; + console.log('[InputArea] Message changed:', newMessage); + setMessage(newMessage); + }; + return (