File size: 1,434 Bytes
703af34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// scripts/chat.js

const getElement = (id) => document.getElementById(id);

async function sendMessage() {
    const userInput = getElement('user-input');
    const chatMessages = getElement('chat-messages');

    if (userInput.value.trim() === '') return;

    // ... (keep the complete sendMessage logic from the previous response here)
    // ... (This includes adding user message, creating AI bubble, and the fetch call)
}

function quickPrompt(prompt) {
    getElement('user-input').value = prompt;
    sendMessage();
}

function updateRecommendationsFromAI(aiResponse) {
    // This is a placeholder. You can enhance this logic.
    let filter = 'all';
    if (aiResponse.includes('comedy')) filter = 'comedy';
    else if (aiResponse.includes('thriller')) filter = 'thriller';
    else if (aiResponse.includes('romance')) filter = 'romance';
    
    // In a truly modular system, this would emit an event that ui.js listens for.
    // For simplicity, we'll call a function defined in the global scope (see app.js).
    window.loadRecommendations(filter);
}


export function initChat() {
    getElement('send-btn').addEventListener('click', sendMessage);
    getElement('user-input').addEventListener('keypress', (e) => {
        if (e.key === 'Enter') {
            sendMessage();
        }
    });

    // Make quickPrompt globally accessible for the inline HTML onclick attributes
    window.quickPrompt = quickPrompt;
}