update
This commit is contained in:
parent
5d451a4847
commit
16eb366ce1
@ -0,0 +1,25 @@
|
||||
import Navbar from './components/Navbar.js';
|
||||
import ChatBox from './components/ChatBox.js';
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const loginForm = document.getElementById('loginForm');
|
||||
const dashboard = document.getElementById('dashboard');
|
||||
const loginRegister = document.getElementById('login-register');
|
||||
|
||||
loginForm.addEventListener('submit', (e) => {
|
||||
e.preventDefault();
|
||||
loginRegister.classList.add('d-none');
|
||||
dashboard.classList.remove('d-none');
|
||||
loadComponents();
|
||||
});
|
||||
|
||||
document.getElementById('logoutButton').addEventListener('click', () => {
|
||||
location.reload();
|
||||
});
|
||||
|
||||
function loadComponents() {
|
||||
const chatboxContainer = document.getElementById('chatbox');
|
||||
const chatbox = new ChatBox();
|
||||
chatboxContainer.appendChild(chatbox.render());
|
||||
}
|
||||
});
|
@ -0,0 +1,26 @@
|
||||
import Message from './Message.js';
|
||||
|
||||
export default class ChatBox {
|
||||
render() {
|
||||
const container = document.createElement('div');
|
||||
container.classList.add('d-flex', 'flex-column', 'h-100');
|
||||
|
||||
container.innerHTML = `
|
||||
<div id="messages" class="flex-grow-1 p-3 overflow-auto"></div>
|
||||
<form id="messageForm" class="d-flex">
|
||||
<input type="text" id="messageInput" class="form-control me-2" placeholder="Type your message..." required>
|
||||
<button type="submit" class="btn btn-success">Send</button>
|
||||
</form>
|
||||
`;
|
||||
|
||||
container.querySelector('#messageForm').addEventListener('submit', (e) => {
|
||||
e.preventDefault();
|
||||
const messageText = container.querySelector('#messageInput').value;
|
||||
const message = new Message(messageText, 'sent');
|
||||
container.querySelector('#messages').appendChild(message.render());
|
||||
container.querySelector('#messageInput').value = '';
|
||||
});
|
||||
|
||||
return container;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
export default class Message {
|
||||
constructor(text, type) {
|
||||
this.text = text;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
render() {
|
||||
const message = document.createElement('div');
|
||||
message.className = 'message ' + (this.type === 'sent' ? 'sent' : '');
|
||||
message.textContent = this.text;
|
||||
return message;
|
||||
}
|
||||
}
|
@ -1,122 +1,11 @@
|
||||
/* Global Styles */
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
background-color: #f0f2f5;
|
||||
color: #333;
|
||||
background: linear-gradient(to right, #74ebd5, #acb6e5);
|
||||
}
|
||||
|
||||
#app {
|
||||
width: 100%;
|
||||
max-width: 420px;
|
||||
border: 1px solid #ddd;
|
||||
.card {
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
background-color: #fff;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 90vh;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
/* Header */
|
||||
header {
|
||||
background-color: #075e54;
|
||||
color: #fff;
|
||||
padding: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.header-content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.settings-btn {
|
||||
font-size: 18px;
|
||||
background: none;
|
||||
border: none;
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Chat Box */
|
||||
#chat-box {
|
||||
flex: 1;
|
||||
padding: 15px;
|
||||
overflow-y: auto;
|
||||
background-color: #e5ddd5;
|
||||
}
|
||||
|
||||
.message {
|
||||
max-width: 75%;
|
||||
margin-bottom: 10px;
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
line-height: 1.4;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.message.sent {
|
||||
background-color: #dcf8c6;
|
||||
align-self: flex-end;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.message.received {
|
||||
background-color: #fff;
|
||||
align-self: flex-start;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
/* Message Form */
|
||||
#message-form {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 10px;
|
||||
background-color: #f0f2f5;
|
||||
border-top: 1px solid #ddd;
|
||||
}
|
||||
|
||||
#message-input {
|
||||
flex: 1;
|
||||
padding: 10px;
|
||||
font-size: 16px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 20px;
|
||||
margin-right: 10px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 10px 15px;
|
||||
font-size: 20px;
|
||||
color: #fff;
|
||||
background-color: #075e54;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Responsive Design */
|
||||
@media (max-width: 480px) {
|
||||
#app {
|
||||
height: 100vh;
|
||||
max-width: 100%;
|
||||
border-radius: 0;
|
||||
}
|
||||
h2 {
|
||||
font-weight: 600;
|
||||
}
|
@ -1,30 +1,41 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<html lang="id">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>ChatsApp</title>
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
<!-- Font BOXICO-->
|
||||
<link href='https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css' rel='stylesheet'>
|
||||
|
||||
<title>Registrasi - ChatsApp</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
<header>
|
||||
<div class="header-content">
|
||||
<h1>ChatsApp</h1>
|
||||
<button class="settings-btn"><i class='bx bx-cog'></i></button> <!-- Disini we tambahin font icon biar gak manul lu bikin icon pake emote dari keyboard njir :| -->
|
||||
<body class="bg-light">
|
||||
<div class="container d-flex justify-content-center align-items-center min-vh-100">
|
||||
<div class="card shadow" style="width: 400px;">
|
||||
<div class="card-body">
|
||||
<h2 class="card-title text-center">Registrasi</h2>
|
||||
<form id="registerForm">
|
||||
<div class="form-group">
|
||||
<label for="username">Nama Pengguna</label>
|
||||
<input type="text" class="form-control" id="username" name="username" required placeholder="Masukkan Nama Pengguna">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email">Email</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required placeholder="Masukkan Email">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">Kata Sandi</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required placeholder="Masukkan Kata Sandi">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary btn-block">Daftar</button>
|
||||
</form>
|
||||
<div class="text-center mt-3">
|
||||
<small>Sudah punya akun? <a href="#">Masuk</a></small>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<main>
|
||||
<section id="chat-box"></section>
|
||||
<form id="message-form">
|
||||
<input type="text" id="message-input" placeholder="Type a message...">
|
||||
<button type="submit">➤</button>
|
||||
</form>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.0.7/dist/umd/popper.min.js"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
||||
<script src="js/main.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -1,29 +1,14 @@
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const chatBox = document.getElementById("chat-box");
|
||||
const messageForm = document.getElementById("message-form");
|
||||
const messageInput = document.getElementById("message-input");
|
||||
document.getElementById('registerForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const username = document.getElementById('username').value;
|
||||
const email = document.getElementById('email').value;
|
||||
const password = document.getElementById('password').value;
|
||||
|
||||
// Function to add message to chat box
|
||||
function addMessage(text, type) {
|
||||
const messageElement = document.createElement("div");
|
||||
messageElement.textContent = text;
|
||||
messageElement.classList.add("message", type);
|
||||
chatBox.appendChild(messageElement);
|
||||
chatBox.scrollTop = chatBox.scrollHeight;
|
||||
}
|
||||
|
||||
// Handle message send
|
||||
messageForm.addEventListener("submit", (e) => {
|
||||
e.preventDefault();
|
||||
const messageText = messageInput.value.trim();
|
||||
if (messageText !== "") {
|
||||
addMessage(messageText, "sent");
|
||||
messageInput.value = "";
|
||||
|
||||
// Simulate received message after 1 second
|
||||
setTimeout(() => {
|
||||
addMessage("This is an auto-reply!", "received");
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
// Logika untuk mengirim data ke server bisa ditambahkan di sini
|
||||
console.log('Registrasi:', { username, email, password });
|
||||
alert('Registrasi berhasil!');
|
||||
|
||||
// Reset form setelah pengiriman
|
||||
this.reset();
|
||||
});
|
Loading…
Reference in New Issue
Block a user