Skip to content

Commit

Permalink
Basic api intregraion done
Browse files Browse the repository at this point in the history
  • Loading branch information
bhujoshi committed Mar 9, 2024
1 parent acd4371 commit 9746117
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 46 deletions.
2 changes: 1 addition & 1 deletion network/axios.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const getAxiosClient = async function () {
accept: 'application/json',
'Content-Type': 'application/json',
'X-User-Email': userAuthInfo?.email || null,
'X-User-Token': userAuthInfo?.userToken || null,
'X-User-Token': userAuthInfo?.token || null,
'X-User-Device-Id': userDeviceId || null
}
});
Expand Down
54 changes: 42 additions & 12 deletions screens/ChatSessionScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,62 @@ import React, { useState } from 'react';
import { material } from 'react-native-typography';
import { logEvent } from '../libs/Helpers';
import { useTranslation } from 'react-i18next';
import { createChatSession, getChatSession } from '../network/chat_session';

const ChatSessionScreen = () => {
const { t } = useTranslation();
const [messages, setMessages] = useState([]);
const [inputText, setInputText] = useState('');

const handleSend = () => {
// Logic to send the message
const newMessage = {
text: inputText,
sender: 'user' // or 'ai' for AI messages
console.log('check the route is working or not ???');
const handleSend = async () => {
const message = {
chat_session: {
chat_session_type: 'color_palette',
messages_attributes: [
{
message: inputText,
sender_type: 'user'
}
]
}
};
setMessages([...messages, newMessage]);
setInputText('');
try {
const chatSession = await createChatSession(message);
console.log('chat session', chatSession);
console.log('chat session', chatSession.data.messages);
setMessages([...messages, ...chatSession.data.messages]);
const interval = setInterval(async () => {
const messageResponse = await getChatSession(
chatSession.data.id,
chatSession.data.messages[0].id
);
if (messageResponse.data.length > 0) {
console.log('messageResponse', messageResponse);
clearInterval(interval);
setMessages((messages) => [...messages, ...messageResponse.data]);
}
}, 1000);
// setMessages([...messages, newMessage]);
setInputText('');
} catch (error) {
console.error('Error sending message', error);
}
// setMessages([...messages, newMessage]);
// setInputText('');
};

logEvent('chat_session_screen');

console.log('messages', messages);

return (
<ScrollView style={styles.container} showsVerticalScrollIndicator={false}>
<View>
{/* Render the messages */}
{messages.map((message, index) => (
<Text key={index} style={styles.message}>
{message.text}
</Text>
<View key={index}>
<Text style={styles.message}>{message.message}</Text>
<Text style={styles.message}>{message.sender_type}</Text>
</View>
))}
</View>
<View style={styles.inputContainer}>
Expand Down
Loading

0 comments on commit 9746117

Please sign in to comment.