Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build Talk Page using HTML,CSS, JAVA SCRIPT #216

Open
sarasvatidadhore opened this issue Dec 29, 2024 · 0 comments
Open

Build Talk Page using HTML,CSS, JAVA SCRIPT #216

sarasvatidadhore opened this issue Dec 29, 2024 · 0 comments

Comments

@sarasvatidadhore
Copy link

#index.html

<title>Professional Chat</title>
Profile

John Doe

Contact

Jane Smith

Online
Send
<script type="module" src="/src/js/main.js"></script>

#153
border-radius: 8px;
font-size: 1rem;
cursor: pointer;
transition: opacity 0.2s;
}

button:hover {
opacity: 0.9;
}

#index.js
// run node index.js in the terminal

console.log(Hello Node.js v${process.versions.node}!);

#JS
#contacts.js
export function renderContacts(contacts) {
const contactsList = document.getElementById('contactsList');

contacts.forEach(contact => {
    const contactElement = document.createElement('div');
    contactElement.className = 'contact';
    contactElement.innerHTML = `
        <img src="https://api.dicebear.com/6.x/avataaars/svg?seed=${contact.name}" alt="${contact.name}" class="avatar small">
        <div class="contact-info">
            <h4>${contact.name}</h4>
            <p>${contact.lastMessage}</p>
        </div>
    `;
    
    contactElement.addEventListener('click', () => {
        document.querySelectorAll('.contact').forEach(el => el.classList.remove('active'));
        contactElement.classList.add('active');
    });
    
    contactsList.appendChild(contactElement);
});

}

#messages.js
import { formatRelative } from 'date-fns';

export function renderMessages(messages) {
const messagesList = document.getElementById('messagesList');

messages.forEach(message => {
    const messageElement = document.createElement('div');
    messageElement.className = `message ${message.sent ? 'sent' : 'received'}`;
    
    const time = formatRelative(new Date(message.timestamp), new Date());
    
    messageElement.innerHTML = `
        <div class="message-content">${message.text}</div>
        <div class="message-time">${time}</div>
    `;
    
    messagesList.appendChild(messageElement);
});

messagesList.scrollTop = messagesList.scrollHeight;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant