Skip to content

Commit 601d325

Browse files
committed
Change the text color of AI bot and have AI initiate the chat
1 parent 365a93b commit 601d325

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

src/components/ChatBox.tsx

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useRef, useState} from 'react';
1+
import React, {useRef, useState, useEffect} from 'react';
22
import {
33
View,
44
Text,
@@ -27,17 +27,22 @@ const ChatBox: React.FC = () => {
2727

2828
const generateAIResponse = () => {
2929
const responses = [
30-
"I'm here to help!",
31-
"That's interesting. Can you tell me more?",
32-
'I see. What do you think?',
33-
'Great question! Let me think...',
34-
'Hmm, let me look into that.',
30+
'我在這裡協助你!',
31+
'這聽起來很有趣,可以多跟我分享嗎?',
32+
'了解了!你的想法是什麼呢?',
33+
'嗯...讓我查查看。',
34+
'我們一起努力吧!',
35+
'加油!你做得很好!',
36+
'聽起來你很認真呢!',
37+
'繼續保持這個好習慣吧!',
3538
];
3639
return responses[Math.floor(Math.random() * responses.length)];
3740
};
3841

3942
const sendMessage = () => {
40-
if (message.trim() === '') {return;}
43+
if (message.trim() === '') {
44+
return;
45+
}
4146

4247
setMessages(prev => [
4348
...prev,
@@ -53,6 +58,11 @@ const ChatBox: React.FC = () => {
5358
}, 1000);
5459
};
5560

61+
useEffect(() => {
62+
const initialWelcome = '嗨!我是你的小幫手,有需要幫忙的地方嗎?🦕';
63+
setMessages([{id: generateUniqueId(), text: initialWelcome, sender: 'ai'}]);
64+
}, []);
65+
5666
return (
5767
<KeyboardAvoidingView
5868
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
@@ -72,7 +82,12 @@ const ChatBox: React.FC = () => {
7282
styles.chatBubble,
7383
item.sender === 'user' ? styles.userBubble : styles.aiBubble,
7484
]}>
75-
<Text style={styles.chatText}>{item.text}</Text>
85+
<Text
86+
style={
87+
item.sender === 'user' ? styles.chatTextUser : styles.chatTextAI
88+
}>
89+
{item.text}
90+
</Text>
7691
</View>
7792
))}
7893
</ScrollView>
@@ -125,10 +140,14 @@ const styles = StyleSheet.create({
125140
backgroundColor: '#e0e0e0',
126141
alignSelf: 'flex-start',
127142
},
128-
chatText: {
143+
chatTextUser: {
129144
color: '#fff',
130145
fontSize: 16,
131146
},
147+
chatTextAI: {
148+
color: '#333',
149+
fontSize: 16,
150+
},
132151
chatInputContainer: {
133152
flexDirection: 'row',
134153
alignItems: 'center',

0 commit comments

Comments
 (0)