Files
chatapp/index.html
T
2025-10-04 14:32:13 +01:00

749 lines
24 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Discord Clone - Group Chat</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
background: #0a0a0a;
color: #e0e0e0;
height: 100vh;
overflow: hidden;
}
.chat-container {
display: flex;
flex-direction: column;
height: 100vh;
max-width: 50vh;
margin: 0 auto;
background: #121212;
position: relative;
overflow: hidden;
}
/* Chat Header */
.chat-header {
padding: 10px;
background: #1a1a1a;
border-bottom: 1px solid #252525;
}
.chat-title {
display: flex;
align-items: center;
gap: 12px;
}
.status-dot {
width: 10px;
height: 10px;
background: #ff4444;
border-radius: 50%;
animation: pulse 2s infinite;
}
@keyframes pulse {
0%,
100% {
transform: scale(1);
opacity: 1;
}
50% {
transform: scale(1.3);
opacity: 0.7;
}
}
.chat-title h1 {
font-size: 17px;
font-weight: 600;
color: #ffffff;
}
/* Live Location Notification Bubble */
.notification-container {
padding: 15px 20px 10px 20px;
display: flex;
flex-direction: column;
gap: 10px;
position: absolute;
top: 70px;
left: 0;
right: 0;
z-index: 10;
pointer-events: none;
}
.live-location-bubble {
padding: 0;
border-radius: 20px;
position: relative;
overflow: hidden;
cursor: pointer;
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
border: 1px solid rgba(138, 43, 226, 0.3);
box-shadow:
0 8px 32px rgba(106, 90, 205, 0.2),
inset 0 1px 0 rgba(255, 255, 255, 0.1);
pointer-events: auto;
max-height: 64px;
background: transparent;
}
.live-location-bubble::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(
135deg,
rgba(106, 90, 205, 0.25) 0%,
rgba(72, 61, 139, 0.2) 50%,
rgba(123, 104, 238, 0.15) 100%
);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
z-index: 0;
}
.live-location-bubble.expanded::before {
opacity: 0;
}
.live-location-bubble > * {
position: relative;
z-index: 1;
}
.live-location-bubble.expanded {
max-height: 400px;
cursor: default;
}
.map-container {
width: 100%;
height: 0;
opacity: 0;
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
overflow: hidden;
}
.live-location-bubble.expanded .map-container {
height: 260px;
opacity: 1;
}
.map-container img {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
}
.location-content {
display: flex;
align-items: center;
gap: 12px;
padding: 16px 20px;
background: linear-gradient(
135deg,
rgba(106, 90, 205, 0.25) 0%,
rgba(72, 61, 139, 0.2) 50%,
rgba(123, 104, 238, 0.15) 100%
);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
}
.live-location-bubble.expanded .location-content {
background: linear-gradient(
to bottom,
rgba(106, 90, 205, 0.45) 0%,
rgba(72, 61, 139, 0.4) 50%,
rgba(123, 104, 238, 0.35) 100%
);
}
.location-content {
display: flex;
align-items: center;
gap: 12px;
}
.live-location-bubble::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
height: 1px;
background: linear-gradient(
90deg,
transparent,
rgba(255, 255, 255, 0.2),
transparent
);
}
.live-location-bubble:hover {
transform: translateY(-2px);
box-shadow:
0 12px 40px rgba(106, 90, 205, 0.35),
inset 0 1px 0 rgba(255, 255, 255, 0.15);
background: linear-gradient(
135deg,
rgba(106, 90, 205, 0.3) 0%,
rgba(72, 61, 139, 0.25) 50%,
rgba(123, 104, 238, 0.2) 100%
);
}
.live-location-bubble.active {
background: linear-gradient(
135deg,
rgba(106, 90, 205, 0.35) 0%,
rgba(72, 61, 139, 0.3) 50%,
rgba(123, 104, 238, 0.25) 100%
);
border-color: rgba(138, 43, 226, 0.5);
}
.location-content {
display: flex;
align-items: center;
gap: 12px;
}
.location-icon {
width: 32px;
height: 32px;
background: rgba(255, 255, 255, 0.15);
backdrop-filter: blur(10px);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
border: 1px solid rgba(255, 255, 255, 0.2);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
transition: all 0.3s ease;
flex-shrink: 0;
}
.location-icon svg {
width: 18px;
height: 18px;
fill: #ea4335;
filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
}
.live-location-bubble.expanded .location-icon {
display: none;
}
.join-button {
display: none;
padding: 8px 20px;
background: rgba(255, 255, 255, 0.15);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 20px;
color: #ffffff;
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: all 0.2s ease;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
flex-shrink: 0;
}
.live-location-bubble.expanded .join-button {
display: block;
}
.join-button:hover {
background: rgba(255, 255, 255, 0.25);
transform: scale(1.05);
}
.join-button:active {
transform: scale(0.95);
}
.join-button.active {
background: rgba(106, 90, 205, 0.4);
border-color: rgba(138, 43, 226, 0.5);
}
.live-location-bubble.active .location-icon {
background: rgba(255, 255, 255, 0.25);
}
.location-text {
font-size: 15px;
font-weight: 600;
color: #ffffff;
flex: 1;
letter-spacing: 0.3px;
}
.location-users {
display: flex;
align-items: center;
}
.location-user-pic {
width: 32px;
height: 32px;
border-radius: 35%;
margin-left: -15px;
position: relative;
z-index: 1;
transition: all 0.2s ease;
}
.location-user-pic:first-child {
margin-left: 0;
}
.location-user-pic:hover {
z-index: 10;
transform: scale(1.15);
}
.location-count {
width: 32px;
height: 32px;
border-radius: 35%;
background: rgba(0, 0, 0, 0.5);
backdrop-filter: blur(10px);
margin-left: -15px;
display: flex;
align-items: center;
justify-content: center;
font-size: 10px;
font-weight: 600;
color: #ffffff;
z-index: 2;
}
.messages-container::before {
content: "";
flex: 1 0 auto;
}
/* Messages Container */
.messages-container {
display: flex;
flex-direction: column;
/*justify-content: flex-end;*/
flex: 1;
padding: 15px 0 15px 0;
overflow-y: scroll;
background: #121212;
}
.message {
margin: 8px 20px;
padding: 12px 16px;
border-radius: 12px;
background: rgba(30, 30, 30, 0.4);
backdrop-filter: blur(10px);
border: 1px solid #252525;
animation: slideIn 0.3s ease-out;
transition: all 0.2s ease;
display: flex;
gap: 12px;
}
.message:hover {
background: #1f1f1f;
border-color: #2a2a2a;
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.user-avatar {
width: 48px;
height: 48px;
border-radius: 25%;
background-size: cover;
border: 2px solid #252525;
flex-shrink: 0;
background-image: url('assets/profile_pics/default.jpg');
}
.user-avatar.blue {
background: linear-gradient(135deg, #4169e1, #6495ed);
}
.message-content {
flex: 1;
min-width: 0;
}
.message-header {
display: flex;
align-items: baseline;
gap: 8px;
margin-bottom: 4px;
}
.username {
font-weight: 600;
font-size: 15px;
color: #e0e0e0;
}
.timestamp {
font-size: 11px;
color: #666;
font-weight: 400;
}
.message-text {
font-size: 14px;
color: #b0b0b0;
line-height: 1.4;
word-wrap: break-word;
}
/* Input Container */
.input-container {
padding: 10px;
background: #1a1a1a;
border-top: 1px solid #252525;
}
.input-wrapper {
display: flex;
align-items: center;
gap: 10px;
background: #252525;
border-radius: 10px;
padding: 5px 5px;
border: 1px solid #2a2a2a;
transition: all 0.2s ease;
}
.input-wrapper:focus-within {
background: #2a2a2a;
border-color: #6a5acd;
box-shadow: 0 0 0 3px rgba(106, 90, 205, 0.1);
}
.input-wrapper input {
flex: 1;
background: none;
border: none;
color: #e0e0e0;
font-size: 14px;
outline: none;
}
.input-wrapper input::placeholder {
color: #666;
}
.send-button {
width: 32px;
height: 32px;
background: none;
border-radius: 10px;
border: none;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-size: 14px;
transition: all 0.2s ease;
flex-shrink: 0;
}
.send-button:hover {
transform: scale(1.1);
box-shadow: 0 4px 15px rgba(106, 90, 205, 0.4);
background: rgba(255, 255, 255, 0.4);
}
.send-button:active {
transform: scale(0.95);
}
/* Scrollbar styling */
.messages-container::-webkit-scrollbar {
width: 6px;
}
.messages-container::-webkit-scrollbar-track {
background: #1a1a1a;
}
.messages-container::-webkit-scrollbar-thumb {
background: #333;
border-radius: 3px;
}
.messages-container::-webkit-scrollbar-thumb:hover {
background: #444;
}
</style>
</head>
<body>
<div class="chat-container">
<!--<div class="chat-container" style="background-image: url('assets/background.png'); backdrop-filter: blur(10px); background-size: cover; background-position: center; background-repeat: no-repeat;">-->
<!-- Chat Header -->
<div class="chat-header">
<div class="chat-title">
<div class="user-avatar"></div>
<h1>Chat title</h1>
</div>
</div>
<!-- Live Location Notification Bubble -->
<div class="notification-container">
<div class="live-location-bubble" id="locationBubble">
<div class="map-container">
<img src="map.png" alt="Map" />
</div>
<div class="location-content">
<div class="location-icon">
<img src="icons/location.svg" alt="Location"></img>
</div>
<button class="join-button" id="joinButton">
Join
</button>
<div class="location-text">Live Location</div>
<div class="location-users" id="locationUsers">
<!-- Users will be added dynamically -->
</div>
</div>
</div>
</div>
<!-- Messages Container -->
<!--<div class="messages-container" style="background-image: url('assets/background.png'); backdrop-filter: blur(10px); background-size: cover; background-position: center; background-repeat: no-repeat;">-->
<div class="messages-container">
<div class="message">
<div class="user-avatar"></div>
<div class="message-content">
<div class="message-header">
<span class="username">Username</span>
<span class="timestamp">12:34 PM</span>
</div>
<div class="message-text">example message fr</div>
</div>
</div>
<div class="message">
<div class="user-avatar blue"></div>
<div class="message-content">
<div class="message-header">
<span class="username">Username2</span>
<span class="timestamp">12:35 PM</span>
</div>
<div class="message-text">example message fr</div>
</div>
</div>
<div class="message">
<div class="user-avatar blue"></div>
<div class="message-content">
<div class="message-header">
<span class="username">Username2</span>
<span class="timestamp">12:36 PM</span>
</div>
<div class="message-text">example message fr</div>
</div>
</div>
</div>
<!-- Input Container -->
<div class="input-container">
<div class="input-wrapper">
<input type="text" placeholder="Start Typing..." />
<button class="send-button">
<img src="icons/send.svg" alt="Send" />
</button>
</div>
</div>
</div>
<script>
const users = [
{
id: 0,
username: "LLM"
},
{
id: 1,
username: "/Zxq5 🚀/",
}
];
// Location tracker state
const locationUsers = [
{ id: 1, color: "linear-gradient(135deg, #ff6b6b, #ff8e8e)" },
{ id: 2, color: "linear-gradient(135deg, #4ecdc4, #7fdbda)" },
{ id: 3, color: "linear-gradient(135deg, #45b7d1, #6cc5e0)" },
];
let hiddenUsersCount = 5; // Users not shown in the visible stack
let currentUserInLocation = false;
function updateLocationUsers() {
const container = document.getElementById("locationUsers");
container.innerHTML = "";
const maxVisible = 3;
const visibleUsers = locationUsers.slice(0, maxVisible);
visibleUsers.forEach((user) => {
const pic = document.createElement("div");
pic.className = "location-user-pic";
pic.style.background = user.color;
container.appendChild(pic);
});
// Calculate total hidden users (hidden users + current user if tracking)
const totalHidden =
hiddenUsersCount + (currentUserInLocation ? 1 : 0);
// Add count indicator if there are more users
if (totalHidden > 0) {
const count = document.createElement("div");
count.className = "location-count";
count.textContent = `+${totalHidden}`;
container.appendChild(count);
}
}
// Toggle location tracking
const locationBubble = document.getElementById("locationBubble");
const joinButton = document.getElementById("joinButton");
let isExpanded = false;
locationBubble.addEventListener("click", function (e) {
// Don't toggle expanded state if clicking the join button
if (e.target.id === "joinButton") return;
isExpanded = !isExpanded;
this.classList.toggle("expanded", isExpanded);
});
joinButton.addEventListener("click", function (e) {
e.stopPropagation();
currentUserInLocation = !currentUserInLocation;
this.classList.toggle("active", currentUserInLocation);
this.textContent = currentUserInLocation ? "Leave" : "Join";
locationBubble.classList.toggle(
"active",
currentUserInLocation,
);
// Animate click
this.style.transform = "scale(0.95)";
setTimeout(() => {
this.style.transform = "";
}, 150);
updateLocationUsers();
});
// Initialize location users
updateLocationUsers();
// Handle message sending
const input = document.querySelector("input");
const sendButton = document.querySelector(".send-button");
const messagesContainer = document.querySelector(
".messages-container",
);
const messageSource = new EventSource("http://localhost:8001/events");
messageSource.onmessage = (event) => {
const message = JSON.parse(event.data);
const date = new Date(message.timestamp).toLocaleTimeString("en-US", {
hour: "numeric",
minute: "2-digit",
hour12: true,
});
console.log(users, message);
const user = users.find((u) => u.id == message.userid);
console.log(user);
const messageEl = document.createElement("div");
messageEl.className = "message";
messageEl.innerHTML = `
<img class="user-avatar" src="assets/profile_pics/${user.id}.jpg" alt="${user.username}">
<div class="message-content">
<div class="message-header">
<span class="username">${user.username}</span>
<span class="timestamp">${date}</span>
</div>
<div class="message-text">${message.text}</div>
</div>
`;
messagesContainer.appendChild(messageEl);
messagesContainer.scrollTop =
messagesContainer.scrollHeight;
}
function getCurrentTime() {
const now = new Date();
return now.toLocaleTimeString("en-US", {
hour: "numeric",
minute: "2-digit",
hour12: true,
});
}
function sendMessage() {
const message = input.value.trim();
if (message) {
fetch("http://localhost:8001/chat", {
method: "POST",
body: JSON.stringify({
userid: users[1].id,
text: message,
timestamp: new Date().getTime(),
}),
headers: {
"Content-type": "application/json; charset=UTF-8"
}
});
input.value = "";
}
}
sendButton.addEventListener("click", sendMessage);
input.addEventListener("keypress", function (e) {
if (e.key === "Enter") {
sendMessage();
}
});
</script>
</body>
</html>