I'll create a unique messaging interface inspired by WhatsApp but with different elements and features. Let's call our app "MoodChat" - a messaging app that incorporates mood indicators and a shared task manager. Here's the implementation:
To use this interface, you would need to set up a Next.js project with Tailwind CSS and the necessary UI components. The @/components/ui
components (Avatar, Input, Button) are assumed to be from a UI library like shadcn/ui, which you'd need to install and set up in your project.
Remember, this is a static frontend implementation. To make it fully functional, you'd need to add state management, backend integration, and real-time updates. Let me know if you want to expand on any particular aspect of this interface!
I'll modify the interface to implement the functionality you've described using HTML, Tailwind CSS, Express, and EJS. We'll create a simple messaging application where users first see a list of received messages, and when clicked, it opens a chat window.
Let's start by setting up the project structure and implementing the required functionality.
Let's begin with the Express server setup:
// server.js
const express = require('express');
const path = require('path');
const app = express();
const port = 3000;
// Sample data
const messages = [
{ id: 1, sender: 'Alice', content: 'Hey, how are you?', timestamp: '10:30 AM' },
{ id: 2, sender: 'Bob', content: 'Can we meet tomorrow?', timestamp: '11:45 AM' },
{ id: 3, sender: 'Charlie', content: 'Don\'t forget about the project!', timestamp: '2:15 PM' },
];
// Set the view engine to EJS
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
// Serve static files
app.use(express.static(path.join(__dirname, 'public')));
// Routes
app.get('/', (req, res) => {
res.render('index', { messages });
});
app.get('/chat/:id', (req, res) => {
const id = parseInt(req.params.id);
const message = messages.find(m => m.id === id);
res.render('chat', { message });
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});
Now, let's create the EJS templates. First, the main page showing the list of messages:
<!-- views/index.ejs -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Message List</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100">
<div class="container mx-auto p-4">
<h1 class="text-2xl font-bold mb-4">Received Messages</h1>
<div class="space-y-2">
<% messages.forEach(message => { %>
<a href="/chat/<%= message.id %>" class="block bg-white p-4 rounded shadow hover:shadow-md transition">
<div class="flex justify-between items-center">
<span class="font-semibold"><%= message.sender %></span>
<span class="text-sm text-gray-500"><%= message.timestamp %></span>
</div>
<p class="text-gray-600 truncate"><%= message.content %></p>
</a>
<% }); %>
</div>
</div>
</body>
</html>
Next, let's create the chat window template:
<!-- views/chat.ejs -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat with <%= message.sender %></title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100">
<div class="container mx-auto p-4">
<div class="bg-white rounded-lg shadow-md overflow-hidden">
<div class="bg-blue-500 text-white p-4 flex justify-between items-center">
<h1 class="text-xl font-semibold"><%= message.sender %></h1>
<a href="/" class="text-sm hover:underline">Back to Messages</a>
</div>
<div id="chatWindow" class="h-96 overflow-y-auto p-4 space-y-4">
<div class="flex justify-start">
<div class="bg-gray-200 rounded-lg p-3 max-w-3/4">
<p><%= message.content %></p>
<span class="text-xs text-gray-500 mt-1 block"><%= message.timestamp %></span>
</div>
</div>
<!-- More messages will be added here dynamically -->
</div>
<div class="border-t p-4">
<form id="messageForm" class="flex space-x-2">
<input type="text" id="messageInput" placeholder="Type a message..." class="flex-grow p-2 border rounded" required>
<button type="submit" class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600">Send</button>
</form>
</div>
</div>
</div>
<script>
const chatWindow = document.getElementById('chatWindow');
const messageForm = document.getElementById('messageForm');
const messageInput = document.getElementById('messageInput');
messageForm.addEventListener('submit', (e) => {
e.preventDefault();
const message = messageInput.value.trim();
if (message) {
addMessage(message, 'You');
messageInput.value = '';
}
});
function addMessage(content, sender) {
const messageElement = document.createElement('div');
messageElement.className = `flex ${sender === 'You' ? 'justify-end' : 'justify-start'}`;
messageElement.innerHTML = `
<div class="${sender === 'You' ? 'bg-blue-500 text-white' : 'bg-gray-200'} rounded-lg p-3 max-w-3/4">
<p>${content}</p>
<span class="text-xs ${sender === 'You' ? 'text-blue-100' : 'text-gray-500'} mt-1 block">${new Date().toLocaleTimeString()}</span>
</div>
`;
chatWindow.appendChild(messageElement);
chatWindow.scrollTop = chatWindow.scrollHeight;
}
</script>
</body>
</html>
Now, let's create a simple CSS file to ensure Tailwind CSS works correctly:
/* public/styles.css */
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
To run this application, you'll need to set up your project with the following steps:
Initialize a new Node.js project:
npm init -y
Install the required dependencies:
npm install express ejs
Create the file structure:
project-root/
├── server.js
├── views/
│ ├── index.ejs
│ └── chat.ejs
└── public/
└── styles.css
Run the server:
node server.js
This implementation provides a simple messaging interface with the following features:
/
) that displays a list of received messages./chat/:id
) for that specific conversation.To make this a fully functional chat application, you would need to add real-time functionality (e.g., using WebSockets), implement user authentication, and connect it to a database to store and retrieve messages. However, this example provides a solid foundation for the UI and basic interaction you requested.