Spaces:
Running
Running
Need to add posibility to send messages
Browse files- README.md +8 -5
- components/navbar.js +48 -0
- index.html +91 -19
- script.js +130 -0
- style.css +19 -19
README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
| 1 |
---
|
| 2 |
-
title: Chatty
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Chatty McMessageFace 💬
|
| 3 |
+
colorFrom: gray
|
| 4 |
+
colorTo: purple
|
| 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,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class CustomNavbar extends HTMLElement {
|
| 2 |
+
connectedCallback() {
|
| 3 |
+
this.attachShadow({ mode: 'open' });
|
| 4 |
+
this.shadowRoot.innerHTML = `
|
| 5 |
+
<style>
|
| 6 |
+
.navbar {
|
| 7 |
+
background-color: white;
|
| 8 |
+
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
| 9 |
+
}
|
| 10 |
+
.search-input {
|
| 11 |
+
transition: all 0.3s ease;
|
| 12 |
+
}
|
| 13 |
+
.search-input:focus {
|
| 14 |
+
width: 200px;
|
| 15 |
+
}
|
| 16 |
+
.active-tab {
|
| 17 |
+
border-bottom: 2px solid #6366f1;
|
| 18 |
+
color: #6366f1;
|
| 19 |
+
}
|
| 20 |
+
</style>
|
| 21 |
+
<nav class="navbar px-4 py-3 flex items-center justify-between border-b border-gray-200">
|
| 22 |
+
<div class="flex items-center">
|
| 23 |
+
<h1 class="text-xl font-bold text-indigo-600">Chatty</h1>
|
| 24 |
+
<span class="ml-1 text-xl font-bold text-gray-800">McMessageFace</span>
|
| 25 |
+
</div>
|
| 26 |
+
|
| 27 |
+
<div class="relative hidden md:block">
|
| 28 |
+
<input type="text" placeholder="Search..." class="search-input w-32 bg-gray-100 rounded-full py-1 px-4 pl-8 focus:outline-none focus:ring-1 focus:ring-indigo-500">
|
| 29 |
+
<i data-feather="search" class="absolute left-2 top-2 text-gray-400"></i>
|
| 30 |
+
</div>
|
| 31 |
+
|
| 32 |
+
<div class="flex items-center space-x-4">
|
| 33 |
+
<button class="p-2 rounded-full hover:bg-gray-100">
|
| 34 |
+
<i data-feather="message-square"></i>
|
| 35 |
+
</button>
|
| 36 |
+
<button class="p-2 rounded-full hover:bg-gray-100">
|
| 37 |
+
<i data-feather="bell"></i>
|
| 38 |
+
</button>
|
| 39 |
+
<div class="w-8 h-8 rounded-full bg-indigo-500 flex items-center justify-center text-white font-bold cursor-pointer">
|
| 40 |
+
<i data-feather="user"></i>
|
| 41 |
+
</div>
|
| 42 |
+
</div>
|
| 43 |
+
</nav>
|
| 44 |
+
`;
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
customElements.define('custom-navbar', CustomNavbar);
|
index.html
CHANGED
|
@@ -1,19 +1,91 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
</
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Chatty McMessageFace</title>
|
| 7 |
+
<link rel="stylesheet" href="style.css">
|
| 8 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 9 |
+
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
| 10 |
+
<script src="https://unpkg.com/feather-icons"></script>
|
| 11 |
+
</head>
|
| 12 |
+
<body class="bg-gray-100 h-screen">
|
| 13 |
+
<custom-navbar></custom-navbar>
|
| 14 |
+
<div class="container mx-auto px-4 py-6 h-[calc(100%-80px)]">
|
| 15 |
+
<div class="bg-white rounded-lg shadow-lg h-full flex flex-col">
|
| 16 |
+
<!-- Chat header -->
|
| 17 |
+
<div class="border-b border-gray-200 p-4 flex items-center">
|
| 18 |
+
<div class="w-10 h-10 rounded-full bg-indigo-500 flex items-center justify-center text-white font-bold">
|
| 19 |
+
<i data-feather="user"></i>
|
| 20 |
+
</div>
|
| 21 |
+
<div class="ml-3">
|
| 22 |
+
<h2 class="font-semibold text-lg">John Doe</h2>
|
| 23 |
+
<p class="text-gray-500 text-sm">Online</p>
|
| 24 |
+
</div>
|
| 25 |
+
<div class="ml-auto flex space-x-2">
|
| 26 |
+
<button class="p-2 rounded-full hover:bg-gray-100">
|
| 27 |
+
<i data-feather="phone"></i>
|
| 28 |
+
</button>
|
| 29 |
+
<button class="p-2 rounded-full hover:bg-gray-100">
|
| 30 |
+
<i data-feather="video"></i>
|
| 31 |
+
</button>
|
| 32 |
+
<button class="p-2 rounded-full hover:bg-gray-100">
|
| 33 |
+
<i data-feather="more-vertical"></i>
|
| 34 |
+
</button>
|
| 35 |
+
</div>
|
| 36 |
+
</div>
|
| 37 |
+
|
| 38 |
+
<!-- Messages area -->
|
| 39 |
+
<div class="flex-1 p-4 overflow-y-auto" id="messages">
|
| 40 |
+
<!-- Messages will be loaded here -->
|
| 41 |
+
<div class="space-y-4">
|
| 42 |
+
<!-- Sample incoming message -->
|
| 43 |
+
<div class="flex items-start">
|
| 44 |
+
<div class="w-8 h-8 rounded-full bg-gray-300 flex items-center justify-center text-gray-600 text-xs mr-2">
|
| 45 |
+
JD
|
| 46 |
+
</div>
|
| 47 |
+
<div class="max-w-xs lg:max-w-md bg-gray-200 rounded-lg p-3">
|
| 48 |
+
<p>Hey there! How's it going?</p>
|
| 49 |
+
<p class="text-xs text-gray-500 mt-1">10:30 AM</p>
|
| 50 |
+
</div>
|
| 51 |
+
</div>
|
| 52 |
+
|
| 53 |
+
<!-- Sample outgoing message -->
|
| 54 |
+
<div class="flex items-start justify-end">
|
| 55 |
+
<div class="max-w-xs lg:max-w-md bg-indigo-500 text-white rounded-lg p-3">
|
| 56 |
+
<p>I'm doing great! Just working on this new messaging app.</p>
|
| 57 |
+
<p class="text-xs text-indigo-200 mt-1">10:32 AM</p>
|
| 58 |
+
</div>
|
| 59 |
+
<div class="w-8 h-8 rounded-full bg-indigo-500 flex items-center justify-center text-white text-xs ml-2">
|
| 60 |
+
ME
|
| 61 |
+
</div>
|
| 62 |
+
</div>
|
| 63 |
+
</div>
|
| 64 |
+
</div>
|
| 65 |
+
|
| 66 |
+
<!-- Message input -->
|
| 67 |
+
<div class="border-t border-gray-200 p-4">
|
| 68 |
+
<div class="flex items-center">
|
| 69 |
+
<button class="p-2 rounded-full hover:bg-gray-100 mr-2">
|
| 70 |
+
<i data-feather="plus"></i>
|
| 71 |
+
</button>
|
| 72 |
+
<input type="text" placeholder="Type a message..." class="flex-1 border border-gray-300 rounded-full py-2 px-4 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent">
|
| 73 |
+
<button class="p-2 rounded-full hover:bg-gray-100 ml-2">
|
| 74 |
+
<i data-feather="mic"></i>
|
| 75 |
+
</button>
|
| 76 |
+
<button class="ml-2 bg-indigo-500 text-white p-2 rounded-full hover:bg-indigo-600">
|
| 77 |
+
<i data-feather="send"></i>
|
| 78 |
+
</button>
|
| 79 |
+
</div>
|
| 80 |
+
</div>
|
| 81 |
+
</div>
|
| 82 |
+
</div>
|
| 83 |
+
|
| 84 |
+
<script src="components/navbar.js"></script>
|
| 85 |
+
<script src="script.js"></script>
|
| 86 |
+
<script>
|
| 87 |
+
feather.replace();
|
| 88 |
+
</script>
|
| 89 |
+
<script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
|
| 90 |
+
</body>
|
| 91 |
+
</html>
|
script.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 3 |
+
// Initialize message storage
|
| 4 |
+
const messageStorage = JSON.parse(localStorage.getItem('chatMessages')) || [];
|
| 5 |
+
|
| 6 |
+
// Load saved messages
|
| 7 |
+
function loadMessages() {
|
| 8 |
+
const messagesContainer = document.getElementById('messages');
|
| 9 |
+
messagesContainer.querySelector('.space-y-4').innerHTML = '';
|
| 10 |
+
|
| 11 |
+
messageStorage.forEach(msg => {
|
| 12 |
+
const messageDiv = document.createElement('div');
|
| 13 |
+
messageDiv.className = `flex items-start ${msg.isOutgoing ? 'justify-end' : ''} message`;
|
| 14 |
+
|
| 15 |
+
if (msg.isOutgoing) {
|
| 16 |
+
messageDiv.innerHTML = `
|
| 17 |
+
<div class="max-w-xs lg:max-w-md bg-indigo-500 text-white rounded-lg p-3">
|
| 18 |
+
<p>${msg.content}</p>
|
| 19 |
+
<p class="text-xs text-indigo-200 mt-1">${msg.timestamp}</p>
|
| 20 |
+
</div>
|
| 21 |
+
<div class="w-8 h-8 rounded-full bg-indigo-500 flex items-center justify-center text-white text-xs ml-2">
|
| 22 |
+
ME
|
| 23 |
+
</div>
|
| 24 |
+
`;
|
| 25 |
+
} else {
|
| 26 |
+
messageDiv.innerHTML = `
|
| 27 |
+
<div class="w-8 h-8 rounded-full bg-gray-300 flex items-center justify-center text-gray-600 text-xs mr-2">
|
| 28 |
+
JD
|
| 29 |
+
</div>
|
| 30 |
+
<div class="max-w-xs lg:max-w-md bg-gray-200 rounded-lg p-3">
|
| 31 |
+
<p>${msg.content}</p>
|
| 32 |
+
<p class="text-xs text-gray-500 mt-1">${msg.timestamp}</p>
|
| 33 |
+
</div>
|
| 34 |
+
`;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
messagesContainer.querySelector('.space-y-4').appendChild(messageDiv);
|
| 38 |
+
});
|
| 39 |
+
|
| 40 |
+
messagesContainer.scrollTop = messagesContainer.scrollHeight;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
// Load any existing messages
|
| 44 |
+
loadMessages();
|
| 45 |
+
|
| 46 |
+
// Function to add a new message
|
| 47 |
+
function addMessage(content, isOutgoing = true) {
|
| 48 |
+
const messagesContainer = document.getElementById('messages');
|
| 49 |
+
const messageDiv = document.createElement('div');
|
| 50 |
+
messageDiv.className = `flex items-start ${isOutgoing ? 'justify-end' : ''} message`;
|
| 51 |
+
|
| 52 |
+
const timestamp = new Date().toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
|
| 53 |
+
|
| 54 |
+
// Save message to storage
|
| 55 |
+
messageStorage.push({
|
| 56 |
+
content,
|
| 57 |
+
isOutgoing,
|
| 58 |
+
timestamp
|
| 59 |
+
});
|
| 60 |
+
localStorage.setItem('chatMessages', JSON.stringify(messageStorage));
|
| 61 |
+
|
| 62 |
+
if (isOutgoing) {
|
| 63 |
+
messageDiv.innerHTML = `
|
| 64 |
+
<div class="max-w-xs lg:max-w-md bg-indigo-500 text-white rounded-lg p-3">
|
| 65 |
+
<p>${content}</p>
|
| 66 |
+
<p class="text-xs text-indigo-200 mt-1">${timestamp}</p>
|
| 67 |
+
</div>
|
| 68 |
+
<div class="w-8 h-8 rounded-full bg-indigo-500 flex items-center justify-center text-white text-xs ml-2">
|
| 69 |
+
ME
|
| 70 |
+
</div>
|
| 71 |
+
`;
|
| 72 |
+
} else {
|
| 73 |
+
messageDiv.innerHTML = `
|
| 74 |
+
<div class="w-8 h-8 rounded-full bg-gray-300 flex items-center justify-center text-gray-600 text-xs mr-2">
|
| 75 |
+
JD
|
| 76 |
+
</div>
|
| 77 |
+
<div class="max-w-xs lg:max-w-md bg-gray-200 rounded-lg p-3">
|
| 78 |
+
<p>${content}</p>
|
| 79 |
+
<p class="text-xs text-gray-500 mt-1">${timestamp}</p>
|
| 80 |
+
</div>
|
| 81 |
+
`;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
messagesContainer.querySelector('.space-y-4').appendChild(messageDiv);
|
| 85 |
+
messagesContainer.scrollTop = messagesContainer.scrollHeight;
|
| 86 |
+
}
|
| 87 |
+
// Handle message submission
|
| 88 |
+
const input = document.querySelector('input[type="text"]');
|
| 89 |
+
function sendMessage() {
|
| 90 |
+
if (input.value.trim() !== '') {
|
| 91 |
+
addMessage(input.value);
|
| 92 |
+
input.value = '';
|
| 93 |
+
|
| 94 |
+
// Simulate reply after 1-3 seconds
|
| 95 |
+
setTimeout(() => {
|
| 96 |
+
const replies = [
|
| 97 |
+
"That's interesting!",
|
| 98 |
+
"Tell me more about that.",
|
| 99 |
+
"I see what you mean.",
|
| 100 |
+
"Sounds good to me!",
|
| 101 |
+
"What else is new?",
|
| 102 |
+
"I agree with you."
|
| 103 |
+
];
|
| 104 |
+
const randomReply = replies[Math.floor(Math.random() * replies.length)];
|
| 105 |
+
addMessage(randomReply, false);
|
| 106 |
+
}, 1000 + Math.random() * 2000);
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
input.addEventListener('keypress', function(e) {
|
| 111 |
+
if (e.key === 'Enter') {
|
| 112 |
+
sendMessage();
|
| 113 |
+
}
|
| 114 |
+
});
|
| 115 |
+
// Send button click handler
|
| 116 |
+
const sendButton = document.querySelector('button:has(i[data-feather="send"])');
|
| 117 |
+
sendButton.addEventListener('click', sendMessage);
|
| 118 |
+
|
| 119 |
+
// Clear chat button
|
| 120 |
+
const clearButton = document.createElement('button');
|
| 121 |
+
clearButton.className = 'ml-2 bg-red-500 text-white p-2 rounded-full hover:bg-red-600';
|
| 122 |
+
clearButton.innerHTML = '<i data-feather="trash-2"></i>';
|
| 123 |
+
clearButton.addEventListener('click', function() {
|
| 124 |
+
localStorage.removeItem('chatMessages');
|
| 125 |
+
messageStorage.length = 0;
|
| 126 |
+
loadMessages();
|
| 127 |
+
});
|
| 128 |
+
document.querySelector('.border-t.border-gray-200.p-4 .flex').appendChild(clearButton);
|
| 129 |
+
feather.replace();
|
| 130 |
+
});
|
style.css
CHANGED
|
@@ -1,28 +1,28 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
}
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
}
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
margin-bottom: 10px;
|
| 15 |
-
margin-top: 5px;
|
| 16 |
}
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
margin: 0 auto;
|
| 21 |
-
padding: 16px;
|
| 22 |
-
border: 1px solid lightgray;
|
| 23 |
-
border-radius: 16px;
|
| 24 |
}
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Custom scrollbar for messages */
|
| 2 |
+
#messages::-webkit-scrollbar {
|
| 3 |
+
width: 6px;
|
| 4 |
}
|
| 5 |
|
| 6 |
+
#messages::-webkit-scrollbar-track {
|
| 7 |
+
background: #f1f1f1;
|
| 8 |
+
border-radius: 10px;
|
| 9 |
}
|
| 10 |
|
| 11 |
+
#messages::-webkit-scrollbar-thumb {
|
| 12 |
+
background: #c1c1c1;
|
| 13 |
+
border-radius: 10px;
|
|
|
|
|
|
|
| 14 |
}
|
| 15 |
|
| 16 |
+
#messages::-webkit-scrollbar-thumb:hover {
|
| 17 |
+
background: #a1a1a1;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
}
|
| 19 |
|
| 20 |
+
/* Animation for new messages */
|
| 21 |
+
@keyframes fadeIn {
|
| 22 |
+
from { opacity: 0; transform: translateY(10px); }
|
| 23 |
+
to { opacity: 1; transform: translateY(0); }
|
| 24 |
}
|
| 25 |
+
|
| 26 |
+
.message {
|
| 27 |
+
animation: fadeIn 0.3s ease-out;
|
| 28 |
+
}
|