-
Notifications
You must be signed in to change notification settings - Fork 0
/
messaging-interface.html
147 lines (128 loc) · 4.18 KB
/
messaging-interface.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<!DOCTYPE html>
<html>
<head>
<style>
.chat-container {
width: 100%;
max-width: 800px;
margin: 20px auto;
border: 1px solid #ccc;
border-radius: 5px;
overflow: hidden;
}
.chat-messages {
height: 400px;
overflow-y: auto;
padding: 20px;
background-color: #f9f9f9;
}
.message {
margin-bottom: 15px;
padding: 10px;
border-radius: 10px;
max-width: 70%;
}
.sent {
background-color: #007bff;
color: white;
margin-left: auto;
}
.received {
background-color: #e9ecef;
color: black;
}
.message-input-container {
display: flex;
padding: 20px;
background-color: white;
border-top: 1px solid #ccc;
}
#message-input {
flex-grow: 1;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
margin-right: 10px;
}
#send-button {
padding: 10px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
#send-button:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<div class="chat-container">
<div class="chat-messages" id="chat-messages">
<!-- Messages will be added here dynamically -->
</div>
<div class="message-input-container">
<input type="text" id="message-input" placeholder="Type your message...">
<button id="send-button">Send</button>
</div>
</div>
<script>
class ChatInterface {
constructor() {
this.messages = [];
this.messageInput = document.getElementById('message-input');
this.sendButton = document.getElementById('send-button');
this.chatMessages = document.getElementById('chat-messages');
this.setupEventListeners();
}
setupEventListeners() {
this.sendButton.addEventListener('click', () => this.sendMessage());
this.messageInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
this.sendMessage();
}
});
}
sendMessage() {
const messageText = this.messageInput.value.trim();
if (messageText === '') return;
const message = {
text: messageText,
timestamp: new Date(),
type: 'sent'
};
this.addMessageToChat(message);
this.messageInput.value = '';
this.scrollToBottom();
// Simulate receiving a response (remove this in production)
this.simulateResponse();
}
addMessageToChat(message) {
const messageElement = document.createElement('div');
messageElement.classList.add('message', message.type);
messageElement.textContent = message.text;
this.chatMessages.appendChild(messageElement);
this.messages.push(message);
}
scrollToBottom() {
this.chatMessages.scrollTop = this.chatMessages.scrollHeight;
}
// This is just for demonstration - remove in production
simulateResponse() {
setTimeout(() => {
const response = {
text: 'This is a simulated response.',
timestamp: new Date(),
type: 'received'
};
this.addMessageToChat(response);
this.scrollToBottom();
}, 1000);
}
}
// Initialize the chat interface
const chat = new ChatInterface();
</script>
</body>
</html>