Below is a basic implementation of the frontend for the app you described using HTML, CSS, and JavaScript. This example includes a login screen, a room selection sidebar, and a weekly calendar for reserving time slots. Note that this is a simplified version, and you may want to enhance it further (e.g., with backend integration, better styling, or more features).
Features:
Login Screen : A simple login form (no real authentication, just a mockup).
Room Selection Sidebar : A list of pre-set rooms on the left (20% of the screen).
Weekly Calendar : A weekly calendar on the right (80% of the screen) where users can click to reserve 1-hour time slots.
Reservations : Users can reserve time slots, and the reserved slots are visually highlighted.
Code:
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Room Reservation App</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: Arial, sans-serif;
}
body, html {
height: 100%;
overflow: hidden;
}
/* Login Screen */
#login-screen {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f0f0;
}
#login-form {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
#login-form input, #login-form button {
display: block;
width: 100%;
margin: 10px 0;
padding: 10px;
font-size: 16px;
}
/* Main App Layout */
#app {
display: none;
height: 100vh;
}
#sidebar {
width: 20%;
background-color: #2c3e50;
color: white;
height: 100%;
padding: 20px;
overflow-y: auto;
}
#sidebar h2 {
margin-bottom: 20px;
}
#room-list {
list-style: none;
}
#room-list li {
padding: 10px;
margin-bottom: 10px;
background-color: #34495e;
cursor: pointer;
border-radius: 4px;
}
#room-list li:hover {
background-color: #1abc9c;
}
#main-content {
width: 80%;
height: 100%;
padding: 20px;
overflow-y: auto;
background-color: #ecf0f1;
}
#calendar {
display: grid;
grid-template-columns: repeat(7, 1fr);
gap: 5px;
}
.day {
background-color: white;
border: 1px solid #ddd;
padding: 10px;
min-height: 400px;
}
.day h3 {
text-align: center;
margin-bottom: 10px;
}
.time-slot {
padding: 5px;
margin: 2px 0;
background-color: #f9f9f9;
cursor: pointer;
border-radius: 4px;
}
.time-slot:hover {
background-color: #e0e0e0;
}
.reserved {
background-color: #1abc9c;
color: white;
}
.reserved:hover {
background-color: #16a085;
}
</style>
</head>
<body>
<!-- Login Screen -->
<div id="login-screen">
<div id="login-form">
<h2>Login</h2>
<input type="text" id="username" placeholder="Username">
<input type="password" id="password" placeholder="Password">
<button onclick="login()">Login</button>
</div>
</div>
<!-- Main App -->
<div id="app" style="display: flex;">
<!-- Sidebar for Room Selection -->
<div id="sidebar">
<h2>Select Room</h2>
<ul id="room-list">
<li onclick="selectRoom('Room 101')">Room 101</li>
<li onclick="selectRoom('Room 102')">Room 102</li>
<li onclick="selectRoom('Room 103')">Room 103</li>
<li onclick="selectRoom('Room 104')">Room 104</li>
<li onclick="selectRoom('Room 105')">Room 105</li>
</ul>
</div>
<!-- Main Content (Calendar) -->
<div id="main-content">
<h2 id="selected-room">Please select a room</h2>
<div id="calendar"></div>
</div>
</div>
<script>
let currentUser = null;
let selectedRoom = null;
let reservations = {};
// Mock login function
function login() {
const username = document.getElementById('username').value;
if (username) {
currentUser = username;
document.getElementById('login-screen').style.display = 'none';
document.getElementById('app').style.display = 'flex';
} else {
alert('Please enter a username');
}
}
// Select a room and load the calendar
function selectRoom(room) {
selectedRoom = room;
document.getElementById('selected-room').textContent = `Room: ${room}`;
loadCalendar();
}
// Load the weekly calendar
function loadCalendar() {
const calendar = document.getElementById('calendar');
calendar.innerHTML = '';
const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
const hours = Array.from({ length: 24 }, (_, i) => `${i}:00 - ${i + 1}:00`);
days.forEach(day => {
const dayDiv = document.createElement('div');
dayDiv.className = 'day';
dayDiv.innerHTML = `<h3>${day}</h3>`;
hours.forEach(hour => {
const slotDiv = document.createElement('div');
slotDiv.className = 'time-slot';
slotDiv.textContent = hour;
// Check if this slot is reserved
const slotKey = `${selectedRoom}-${day}-${hour}`;
if (reservations[slotKey]) {
slotDiv.classList.add('reserved');
slotDiv.textContent = `${hour} (Reserved by ${reservations[slotKey]})`;
}
// Add click event to reserve the slot
slotDiv.onclick = () => reserveSlot(day, hour, slotDiv);
dayDiv.appendChild(slotDiv);
});
calendar.appendChild(dayDiv);
});
}
// Reserve a time slot
function reserveSlot(day, hour, slotDiv) {
if (!selectedRoom) {
alert('Please select a room first');
return;
}
const slotKey = `${selectedRoom}-${day}-${hour}`;
if (reservations[slotKey]) {
alert('This slot is already reserved');
return;
}
reservations[slotKey] = currentUser;
slotDiv.classList.add('reserved');
slotDiv.textContent = `${hour} (Reserved by ${currentUser})`;
}
</script>
</body>
</html>
Explanation of the Code:
HTML Structure :
The login screen (#login-screen) is shown initially, and the main app (#app) is hidden.
The main app is divided into a sidebar (#sidebar) for room selection and a main content area (#main-content) for the calendar.
CSS :
The layout uses flexbox to split the screen into a 20% sidebar and an 80% main content area.
The calendar is a grid with 7 columns (one for each day of the week).
Time slots are styled to be clickable, and reserved slots are highlighted in a different color.
JavaScript :
The login() function simulates a login by hiding the login screen and showing the app.
The selectRoom() function updates the selected room and loads the calendar.
The loadCalendar() function generates a weekly calendar with 24-hour time slots for each day.
The reserveSlot() function allows users to reserve a time slot, storing the reservation in a reservations object and updating the UI.
How to Use:
Open the HTML file in a browser.
Enter a username in the login form and click "Login".
Select a room from the sidebar.
Click on any time slot in the calendar to reserve it. Reserved slots will show the username of the person who reserved them.
Enhancements You Might Want to Add:
Backend Integration : Store reservations in a database and add real user authentication.
Validation : Prevent users from reserving overlapping time slots or reserving slots in the past.
Styling : Improve the design with better colors, fonts, and animations.
Features : Add the ability to cancel reservations, view all reservations, or filter the calendar by date.
Let me know if you need help with any of these enhancements or further clarification!