megacommit
This commit is contained in:
@@ -0,0 +1,231 @@
|
||||
<!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>
|
||||
<link rel="stylesheet" href="static/css/index.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<div class="chat-container">
|
||||
<!--<div class="chat-container" style="background-image: url('cdn/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">
|
||||
<img class="user-avatar" src="cdn/profile/0"></img>
|
||||
<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="cdn/map.png" alt="Map" />
|
||||
</div>
|
||||
<div class="location-content">
|
||||
<div class="location-icon">
|
||||
<img src="cdn/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('cdn/background.png'); backdrop-filter: blur(10px); background-size: cover; background-position: center; background-repeat: no-repeat;">-->
|
||||
<div class="messages-container"></div>
|
||||
|
||||
<!-- Input Container -->
|
||||
<div class="input-container">
|
||||
<div class="input-wrapper">
|
||||
<input type="text" placeholder="Start Typing..." />
|
||||
<button class="send-button">
|
||||
<img src="cdn/icons/send.svg" alt="Send" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const user_id = {{ user_id }};
|
||||
var users = {};
|
||||
|
||||
// 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:8000/events");
|
||||
|
||||
function insertMessage(message) {
|
||||
const date = new Date(message.timestamp).toLocaleTimeString("en-US", {
|
||||
hour: "numeric",
|
||||
minute: "2-digit",
|
||||
hour12: true,
|
||||
});
|
||||
console.log(users, message);
|
||||
|
||||
const uid = message.user_id;
|
||||
const uname = users[`${uid}`];
|
||||
|
||||
console.log(users, uid, uname);
|
||||
|
||||
const messageEl = document.createElement("div");
|
||||
messageEl.className = "message";
|
||||
messageEl.innerHTML = `
|
||||
<img class="user-avatar" src="cdn/profile/${uid}">
|
||||
<div class="message-content">
|
||||
<div class="message-header">
|
||||
<span class="username">${uname}</span>
|
||||
<span class="timestamp">${date}</span>
|
||||
</div>
|
||||
<div class="message-text">${message.text}</div>
|
||||
</div>
|
||||
`;
|
||||
messagesContainer.appendChild(messageEl);
|
||||
messagesContainer.scrollTop =
|
||||
messagesContainer.scrollHeight;
|
||||
}
|
||||
|
||||
messageSource.onmessage = (event) => insertMessage(JSON.parse(event.data));
|
||||
|
||||
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:8000/chat", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
userid: user_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();
|
||||
}
|
||||
});
|
||||
|
||||
// get previous messages
|
||||
fetch("http://localhost:8000/messages")
|
||||
.then(response => response.json())
|
||||
.then(messages => {
|
||||
messages.forEach(message => {
|
||||
insertMessage(message);
|
||||
});
|
||||
});
|
||||
|
||||
fetch("http://localhost:8000/users/")
|
||||
.then(response => response.json())
|
||||
.then(items => {
|
||||
items.forEach(user => {
|
||||
fetch(`http://localhost:8000/users/${user}`)
|
||||
.then(response => response.text())
|
||||
.then(username => {
|
||||
users[user] = username;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,275 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Discord Clone - Sign Up</title>
|
||||
<link rel="stylesheet" href="static/css/index.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<div class="signup-container">
|
||||
<div class="signup-header">
|
||||
<div class="logo">DC</div>
|
||||
<h1>Create Account</h1>
|
||||
<p>Join the conversation today</p>
|
||||
</div>
|
||||
|
||||
<div class="signup-form">
|
||||
<div class="success-message" id="successMessage">
|
||||
Account created successfully! Redirecting...
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="username">Username</label>
|
||||
<input
|
||||
type="text"
|
||||
id="username"
|
||||
name="username"
|
||||
placeholder="Enter your username"
|
||||
required
|
||||
/>
|
||||
<div class="error-message">Username is required</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">Email</label>
|
||||
<input
|
||||
type="email"
|
||||
id="email"
|
||||
name="email"
|
||||
placeholder="Enter your email"
|
||||
required
|
||||
/>
|
||||
<div class="error-message">Please enter a valid email</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password">Password</label>
|
||||
<div class="input-wrapper">
|
||||
<input
|
||||
type="password"
|
||||
id="password"
|
||||
name="password"
|
||||
placeholder="Enter your password"
|
||||
required
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="password-toggle"
|
||||
id="passwordToggle"
|
||||
>
|
||||
SHOW
|
||||
</button>
|
||||
</div>
|
||||
<div class="error-message">
|
||||
Password must be at least 8 characters
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="confirmPassword">Confirm Password</label>
|
||||
<div class="input-wrapper">
|
||||
<input
|
||||
type="password"
|
||||
id="confirmPassword"
|
||||
name="confirmPassword"
|
||||
placeholder="Confirm your password"
|
||||
required
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="password-toggle"
|
||||
id="confirmPasswordToggle"
|
||||
>
|
||||
SHOW
|
||||
</button>
|
||||
</div>
|
||||
<div class="error-message">Passwords do not match</div>
|
||||
</div>
|
||||
|
||||
<div class="checkbox-group">
|
||||
<input type="checkbox" id="terms" name="terms" required />
|
||||
<label for="terms">
|
||||
I agree to the <a href="#">Terms of Service</a> and
|
||||
<a href="#">Privacy Policy</a>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<button type="button" class="submit-button" id="submitButton">
|
||||
Create Account
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="signup-footer">
|
||||
Already have an account? <a href="#">Log in</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const form = {
|
||||
username: document.getElementById("username"),
|
||||
email: document.getElementById("email"),
|
||||
password: document.getElementById("password"),
|
||||
confirmPassword: document.getElementById("confirmPassword"),
|
||||
terms: document.getElementById("terms"),
|
||||
};
|
||||
|
||||
const submitButton = document.getElementById("submitButton");
|
||||
const successMessage = document.getElementById("successMessage");
|
||||
|
||||
// Password toggle functionality
|
||||
const passwordToggle = document.getElementById("passwordToggle");
|
||||
const confirmPasswordToggle = document.getElementById(
|
||||
"confirmPasswordToggle",
|
||||
);
|
||||
|
||||
passwordToggle.addEventListener("click", function () {
|
||||
const type =
|
||||
form.password.type === "password" ? "text" : "password";
|
||||
form.password.type = type;
|
||||
this.textContent = type === "password" ? "SHOW" : "HIDE";
|
||||
});
|
||||
|
||||
confirmPasswordToggle.addEventListener("click", function () {
|
||||
const type =
|
||||
form.confirmPassword.type === "password"
|
||||
? "text"
|
||||
: "password";
|
||||
form.confirmPassword.type = type;
|
||||
this.textContent = type === "password" ? "SHOW" : "HIDE";
|
||||
});
|
||||
|
||||
// Validation functions
|
||||
function validateUsername() {
|
||||
const value = form.username.value.trim();
|
||||
const isValid = value.length >= 3;
|
||||
toggleError(form.username, !isValid);
|
||||
return isValid;
|
||||
}
|
||||
|
||||
function validateEmail() {
|
||||
const value = form.email.value.trim();
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
const isValid = emailRegex.test(value);
|
||||
toggleError(form.email, !isValid);
|
||||
return isValid;
|
||||
}
|
||||
|
||||
function validatePassword() {
|
||||
const value = form.password.value;
|
||||
const isValid = value.length >= 8;
|
||||
toggleError(form.password, !isValid);
|
||||
return isValid;
|
||||
}
|
||||
|
||||
function validateConfirmPassword() {
|
||||
const isValid =
|
||||
form.confirmPassword.value === form.password.value &&
|
||||
form.confirmPassword.value.length > 0;
|
||||
toggleError(form.confirmPassword, !isValid);
|
||||
return isValid;
|
||||
}
|
||||
|
||||
function toggleError(input, hasError) {
|
||||
const formGroup = input.closest(".form-group");
|
||||
if (hasError) {
|
||||
formGroup.classList.add("error");
|
||||
} else {
|
||||
formGroup.classList.remove("error");
|
||||
}
|
||||
}
|
||||
|
||||
// Add blur validation
|
||||
form.username.addEventListener("blur", validateUsername);
|
||||
form.email.addEventListener("blur", validateEmail);
|
||||
form.password.addEventListener("blur", validatePassword);
|
||||
form.confirmPassword.addEventListener(
|
||||
"blur",
|
||||
validateConfirmPassword,
|
||||
);
|
||||
|
||||
// Form submission
|
||||
submitButton.addEventListener("click", async function () {
|
||||
// Validate all fields
|
||||
const isUsernameValid = validateUsername();
|
||||
const isEmailValid = validateEmail();
|
||||
const isPasswordValid = validatePassword();
|
||||
const isConfirmPasswordValid = validateConfirmPassword();
|
||||
const areTermsAccepted = form.terms.checked;
|
||||
|
||||
if (
|
||||
!isUsernameValid ||
|
||||
!isEmailValid ||
|
||||
!isPasswordValid ||
|
||||
!isConfirmPasswordValid ||
|
||||
!areTermsAccepted
|
||||
) {
|
||||
if (!areTermsAccepted) {
|
||||
alert("Please accept the Terms of Service");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Disable button and show loading
|
||||
submitButton.disabled = true;
|
||||
submitButton.innerHTML =
|
||||
'<span class="loading-spinner"></span>Creating Account...';
|
||||
|
||||
// Prepare data
|
||||
const formData = {
|
||||
username: form.username.value.trim(),
|
||||
// email: form.email.value.trim(),
|
||||
password: form.password.value,
|
||||
};
|
||||
|
||||
try {
|
||||
// Replace with your actual backend endpoint
|
||||
const response = await fetch(
|
||||
"http://localhost:8000/signup",
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(formData),
|
||||
},
|
||||
);
|
||||
|
||||
if (response.ok) {
|
||||
// Show success message
|
||||
successMessage.classList.add("show");
|
||||
submitButton.innerHTML = "Account Created!";
|
||||
|
||||
// Optional: Redirect after success
|
||||
setTimeout(() => {
|
||||
// window.location.href = '/chat';
|
||||
console.log("Redirecting to chat...");
|
||||
}, 2000);
|
||||
} else {
|
||||
const error = await response.json();
|
||||
throw new Error(error.message || "Signup failed");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Signup error:", error);
|
||||
alert(
|
||||
error.message ||
|
||||
"Failed to create account. Please try again.",
|
||||
);
|
||||
submitButton.disabled = false;
|
||||
submitButton.innerHTML = "Create Account";
|
||||
}
|
||||
});
|
||||
|
||||
// Allow Enter key to submit
|
||||
Object.values(form).forEach((input) => {
|
||||
if (input.tagName === "INPUT") {
|
||||
input.addEventListener("keypress", function (e) {
|
||||
if (e.key === "Enter") {
|
||||
submitButton.click();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user