authorizedcabal commited on
Commit
a7fc468
·
verified ·
1 Parent(s): 6b3c6cb

generate a simple chat application with the left pane having images of people and the last message and the right larger pane having a chat window

Browse files
Files changed (5) hide show
  1. README.md +8 -5
  2. components/navbar.js +37 -0
  3. index.html +74 -19
  4. script.js +210 -0
  5. style.css +56 -19
README.md CHANGED
@@ -1,10 +1,13 @@
1
  ---
2
- title: Chatterbox Frenzy
3
- emoji: 🚀
4
- colorFrom: gray
5
- colorTo: yellow
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
  ---
2
+ title: ChatterBox Frenzy 🗣️
3
+ colorFrom: blue
4
+ colorTo: pink
5
+ emoji: 🐳
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite-v3
10
  ---
11
 
12
+ # Welcome to your new DeepSite project!
13
+ This project was created with [DeepSite](https://huggingface.co/deepsite).
components/navbar.js ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class CustomNavbar extends HTMLElement {
2
+ connectedCallback() {
3
+ this.attachShadow({ mode: 'open' });
4
+ this.shadowRoot.innerHTML = `
5
+ <style>
6
+ nav {
7
+ background: linear-gradient(to right, #3b82f6, #2563eb);
8
+ }
9
+ .nav-container {
10
+ max-width: 1200px;
11
+ margin: 0 auto;
12
+ }
13
+ .logo {
14
+ font-family: 'Arial', sans-serif;
15
+ }
16
+ </style>
17
+ <nav class="text-white shadow-md py-4">
18
+ <div class="nav-container px-4 flex justify-between items-center">
19
+ <div class="logo flex items-center gap-2">
20
+ <i data-feather="message-square" class="w-6 h-6"></i>
21
+ <span class="text-xl font-bold">ChatterBox</span>
22
+ </div>
23
+ <div class="flex items-center gap-2">
24
+ <button class="p-2 rounded-full hover:bg-blue-600">
25
+ <i data-feather="settings"></i>
26
+ </button>
27
+ <button class="p-2 rounded-full hover:bg-blue-600">
28
+ <i data-feather="user"></i>
29
+ </button>
30
+ </div>
31
+ </div>
32
+ </nav>
33
+ `;
34
+ }
35
+ }
36
+
37
+ customElements.define('custom-navbar', CustomNavbar);
index.html CHANGED
@@ -1,19 +1,74 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en" class="light">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>ChatterBox Frenzy</title>
7
+ <link rel="stylesheet" href="style.css">
8
+ <script src="https://cdn.tailwindcss.com"></script>
9
+ <script src="https://unpkg.com/feather-icons"></script>
10
+ <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
11
+ </head>
12
+ <body class="bg-gray-50 dark:bg-gray-900">
13
+ <custom-navbar></custom-navbar>
14
+
15
+ <main class="container mx-auto px-4 py-8 max-w-7xl">
16
+ <div class="flex flex-col md:flex-row gap-6 rounded-xl overflow-hidden shadow-lg bg-white dark:bg-gray-800 h-[calc(100vh-180px)]">
17
+ <!-- Left Pane - Contacts List -->
18
+ <div class="w-full md:w-1/3 border-r border-gray-200 dark:border-gray-700 overflow-y-auto">
19
+ <div class="p-4 border-b border-gray-200 dark:border-gray-700">
20
+ <h2 class="text-xl font-bold text-gray-800 dark:text-white">Conversations</h2>
21
+ <div class="relative mt-3">
22
+ <input type="text" placeholder="Search chats..." class="w-full px-4 py-2 rounded-full bg-gray-100 dark:bg-gray-700 text-gray-800 dark:text-white placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-blue-500">
23
+ <i data-feather="search" class="absolute right-3 top-2.5 text-gray-500"></i>
24
+ </div>
25
+ </div>
26
+
27
+ <div id="contacts-list" class="divide-y divide-gray-200 dark:divide-gray-700">
28
+ <!-- Contacts will be dynamically added here -->
29
+ </div>
30
+ </div>
31
+
32
+ <!-- Right Pane - Chat Window -->
33
+ <div class="flex-1 flex flex-col">
34
+ <!-- Chat Header -->
35
+ <div id="chat-header" class="p-4 border-b border-gray-200 dark:border-gray-700 flex items-center gap-3 bg-gray-50 dark:bg-gray-700">
36
+ <div id="active-contact-details" class="flex-1">
37
+ <h3 class="text-lg font-semibold text-gray-800 dark:text-white">Select a chat</h3>
38
+ </div>
39
+ <button id="theme-toggle" class="p-2 rounded-full hover:bg-gray-200 dark:hover:bg-gray-600">
40
+ <i data-feather="moon" class="text-gray-700 dark:text-white"></i>
41
+ </button>
42
+ </div>
43
+
44
+ <!-- Messages Container -->
45
+ <div id="messages-container" class="flex-1 p-4 overflow-y-auto">
46
+ <div class="flex flex-col h-full items-center justify-center text-gray-500 dark:text-gray-400">
47
+ <i data-feather="message-square" class="w-16 h-16 mb-4"></i>
48
+ <p class="text-lg">Select a conversation to start chatting</p>
49
+ </div>
50
+ </div>
51
+
52
+ <!-- Message Input -->
53
+ <div class="p-4 border-t border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-700">
54
+ <div id="message-input-container" class="hidden">
55
+ <form id="message-form" class="flex gap-2">
56
+ <input type="text" id="message-input" placeholder="Type your message..." class="flex-1 px-4 py-2 rounded-full bg-white dark:bg-gray-600 text-gray-800 dark:text-white placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-blue-500">
57
+ <button type="submit" class="p-2 rounded-full bg-blue-500 text-white hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500">
58
+ <i data-feather="send"></i>
59
+ </button>
60
+ </form>
61
+ </div>
62
+ </div>
63
+ </div>
64
+ </div>
65
+ </main>
66
+
67
+ <script src="components/navbar.js"></script>
68
+ <script src="script.js"></script>
69
+ <script>
70
+ feather.replace();
71
+ </script>
72
+ <script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
73
+ </body>
74
+ </html>
script.js ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ document.addEventListener('DOMContentLoaded', function() {
2
+ // Mock data for contacts and messages
3
+ const contacts = [
4
+ {
5
+ id: 1,
6
+ name: 'Alex Johnson',
7
+ avatar: 'http://static.photos/people/200x200/1',
8
+ lastMessage: 'Hey, how are you doing?',
9
+ time: '10:30 AM',
10
+ messages: [
11
+ { text: 'Hey there!', sent: false, time: '10:20 AM' },
12
+ { text: 'Hey, how are you doing?', sent: false, time: '10:30 AM' }
13
+ ]
14
+ },
15
+ {
16
+ id: 2,
17
+ name: 'Sarah Miller',
18
+ avatar: 'http://static.photos/people/200x200/2',
19
+ lastMessage: 'Can we meet tomorrow?',
20
+ time: 'Yesterday',
21
+ messages: [
22
+ { text: 'Hi Sarah!', sent: true, time: 'Yesterday, 4:20 PM' },
23
+ { text: 'Can we meet tomorrow?', sent: false, time: 'Yesterday, 4:25 PM' },
24
+ { text: 'Sure, what time?', sent: true, time: 'Yesterday, 4:30 PM' }
25
+ ]
26
+ },
27
+ {
28
+ id: 3,
29
+ name: 'Mark Williams',
30
+ avatar: 'http://static.photos/people/200x200/3',
31
+ lastMessage: 'I sent you the files',
32
+ time: 'Tuesday',
33
+ messages: [
34
+ { text: 'Did you get the documents?', sent: false, time: 'Tuesday, 11:15 AM' },
35
+ { text: 'Not yet, can you send them again?', sent: true, time: 'Tuesday, 11:30 AM' },
36
+ { text: 'I sent you the files', sent: false, time: 'Tuesday, 11:45 AM' }
37
+ ]
38
+ },
39
+ {
40
+ id: 4,
41
+ name: 'Emily Chen',
42
+ avatar: 'http://static.photos/people/200x200/4',
43
+ lastMessage: 'Thanks for your help!',
44
+ time: 'Monday',
45
+ messages: [
46
+ { text: 'I need some advice', sent: false, time: 'Monday, 9:00 AM' },
47
+ { text: 'Of course, what do you need?', sent: true, time: 'Monday, 9:30 AM' },
48
+ { text: 'Thanks for your help!', sent: false, time: 'Monday, 10:15 AM' }
49
+ ]
50
+ },
51
+ {
52
+ id: 5,
53
+ name: 'David Rodriguez',
54
+ avatar: 'http://static.photos/people/200x200/5',
55
+ lastMessage: 'See you at the meeting',
56
+ time: 'Last week',
57
+ messages: [
58
+ { text: 'Are we still meeting tomorrow?', sent: true, time: 'Friday, 3:00 PM' },
59
+ { text: 'Yes, at 2 PM', sent: false, time: 'Friday, 3:30 PM' },
60
+ { text: 'See you at the meeting', sent: false, time: 'Friday, 4:00 PM' }
61
+ ]
62
+ }
63
+ ];
64
+
65
+ // DOM elements
66
+ const contactsList = document.getElementById('contacts-list');
67
+ const messagesContainer = document.getElementById('messages-container');
68
+ const messageInputContainer = document.getElementById('message-input-container');
69
+ const messageForm = document.getElementById('message-form');
70
+ const messageInput = document.getElementById('message-input');
71
+ const chatHeader = document.getElementById('chat-header');
72
+ const activeContactDetails = document.getElementById('active-contact-details');
73
+ const themeToggle = document.getElementById('theme-toggle');
74
+
75
+ // Current selected contact
76
+ let currentContact = null;
77
+
78
+ // Theme toggle functionality
79
+ themeToggle.addEventListener('click', function() {
80
+ const html = document.querySelector('html');
81
+ if (html.classList.contains('light')) {
82
+ html.classList.remove('light');
83
+ html.classList.add('dark');
84
+ feather.replace();
85
+ themeToggle.innerHTML = feather.icons['sun'].toSvg();
86
+ } else {
87
+ html.classList.remove('dark');
88
+ html.classList.add('light');
89
+ feather.replace();
90
+ themeToggle.innerHTML = feather.icons['moon'].toSvg();
91
+ }
92
+ });
93
+
94
+ // Render contacts list
95
+ function renderContacts() {
96
+ contactsList.innerHTML = '';
97
+ contacts.forEach(contact => {
98
+ const contactItem = document.createElement('div');
99
+ contactItem.className = 'contact-item p-4 flex items-center gap-3 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-700';
100
+ contactItem.dataset.contactId = contact.id;
101
+
102
+ contactItem.innerHTML = `
103
+ <img src="${contact.avatar}" alt="${contact.name}" class="w-12 h-12 rounded-full object-cover">
104
+ <div class="flex-1 min-w-0">
105
+ <h4 class="font-semibold text-gray-800 dark:text-white truncate">${contact.name}</h4>
106
+ <p class="text-sm text-gray-600 dark:text-gray-400 truncate">${contact.lastMessage}</p>
107
+ </div>
108
+ <span class="text-xs text-gray-500 dark:text-gray-400">${contact.time}</span>
109
+ `;
110
+
111
+ contactItem.addEventListener('click', () => selectContact(contact.id));
112
+ contactsList.appendChild(contactItem);
113
+ });
114
+ }
115
+
116
+ // Select a contact to chat with
117
+ function selectContact(contactId) {
118
+ currentContact = contacts.find(c => c.id === contactId);
119
+ if (!currentContact) return;
120
+
121
+ // Update active contact details
122
+ activeContactDetails.innerHTML = `
123
+ <div class="flex items-center gap-3">
124
+ <img src="${currentContact.avatar}" alt="${currentContact.name}" class="w-10 h-10 rounded-full object-cover">
125
+ <h3 class="text-lg font-semibold text-gray-800 dark:text-white">${currentContact.name}</h3>
126
+ </div>
127
+ `;
128
+
129
+ // Show message input
130
+ messageInputContainer.classList.remove('hidden');
131
+
132
+ // Render messages
133
+ renderMessages(currentContact.messages);
134
+ }
135
+
136
+ // Render messages for selected contact
137
+ function renderMessages(messages) {
138
+ messagesContainer.innerHTML = '';
139
+
140
+ messages.forEach(message => {
141
+ const messageElement = document.createElement('div');
142
+ messageElement.className = `message-bubble mb-3 p-3 rounded-xl ${
143
+ message.sent ? 'sent self-end' : 'received self-start'
144
+ }`;
145
+
146
+ messageElement.innerHTML = `
147
+ <p class="whitespace-pre-wrap">${message.text}</p>
148
+ <span class="text-xs opacity-70 block mt-1 ${
149
+ message.sent ? 'text-blue-100' : 'text-gray-500 dark:text-gray-400'
150
+ }">${message.time}</span>
151
+ `;
152
+
153
+ messagesContainer.appendChild(messageElement);
154
+ });
155
+
156
+ // Scroll to bottom
157
+ messagesContainer.scrollTop = messagesContainer.scrollHeight;
158
+ }
159
+
160
+ // Send new message
161
+ messageForm.addEventListener('submit', function(e) {
162
+ e.preventDefault();
163
+ const messageText = messageInput.value.trim();
164
+ if (!messageText || !currentContact) return;
165
+
166
+ // Add message to current contact
167
+ const newMessage = {
168
+ text: messageText,
169
+ sent: true,
170
+ time: new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
171
+ };
172
+
173
+ currentContact.messages.push(newMessage);
174
+ currentContact.lastMessage = messageText;
175
+ currentContact.time = 'Just now';
176
+
177
+ // Update UI
178
+ renderMessages(currentContact.messages);
179
+ renderContacts();
180
+ messageInput.value = '';
181
+
182
+ // Simulate reply after 1-3 seconds
183
+ setTimeout(() => {
184
+ const replies = [
185
+ "Sounds good!",
186
+ "I'll get back to you soon.",
187
+ "Thanks for letting me know.",
188
+ "Interesting, tell me more.",
189
+ "Can we talk about this later?"
190
+ ];
191
+
192
+ const replyMessage = {
193
+ text: replies[Math.floor(Math.random() * replies.length)],
194
+ sent: false,
195
+ time: new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
196
+ };
197
+
198
+ currentContact.messages.push(replyMessage);
199
+ currentContact.lastMessage = replyMessage.text;
200
+ currentContact.time = 'Just now';
201
+
202
+ renderMessages(currentContact.messages);
203
+ renderContacts();
204
+ }, 1000 + Math.random() * 2000);
205
+ });
206
+
207
+ // Initialize
208
+ renderContacts();
209
+ feather.replace();
210
+ });
style.css CHANGED
@@ -1,28 +1,65 @@
1
- body {
2
- padding: 2rem;
3
- font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
4
  }
5
 
6
- h1 {
7
- font-size: 16px;
8
- margin-top: 0;
9
  }
10
 
11
- p {
12
- color: rgb(107, 114, 128);
13
- font-size: 15px;
14
- margin-bottom: 10px;
15
- margin-top: 5px;
16
  }
17
 
18
- .card {
19
- max-width: 620px;
20
- margin: 0 auto;
21
- padding: 16px;
22
- border: 1px solid lightgray;
23
- border-radius: 16px;
24
  }
25
 
26
- .card p:last-child {
27
- margin-bottom: 0;
28
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Custom scrollbar */
2
+ ::-webkit-scrollbar {
3
+ width: 8px;
4
  }
5
 
6
+ ::-webkit-scrollbar-track {
7
+ background: #f1f1f1;
8
+ border-radius: 10px;
9
  }
10
 
11
+ ::-webkit-scrollbar-thumb {
12
+ background: #888;
13
+ border-radius: 10px;
 
 
14
  }
15
 
16
+ ::-webkit-scrollbar-thumb:hover {
17
+ background: #555;
 
 
 
 
18
  }
19
 
20
+ .dark ::-webkit-scrollbar-track {
21
+ background: #374151;
22
  }
23
+
24
+ .dark ::-webkit-scrollbar-thumb {
25
+ background: #6b7280;
26
+ }
27
+
28
+ .dark ::-webkit-scrollbar-thumb:hover {
29
+ background: #9ca3af;
30
+ }
31
+
32
+ /* Message bubbles */
33
+ .message-bubble {
34
+ max-width: 75%;
35
+ word-wrap: break-word;
36
+ }
37
+
38
+ .message-bubble.received {
39
+ background-color: #e5e7eb;
40
+ color: #111827;
41
+ }
42
+
43
+ .message-bubble.sent {
44
+ background-color: #3b82f6;
45
+ color: white;
46
+ }
47
+
48
+ .dark .message-bubble.received {
49
+ background-color: #374151;
50
+ color: #f3f4f6;
51
+ }
52
+
53
+ .dark .message-bubble.sent {
54
+ background-color: #2563eb;
55
+ color: white;
56
+ }
57
+
58
+ /* Contact item hover */
59
+ .contact-item:hover {
60
+ background-color: #f3f4f6;
61
+ }
62
+
63
+ .dark .contact-item:hover {
64
+ background-color: #4b5563;
65
+ }