Spaces:
Running
Running
File size: 4,553 Bytes
fe58990 | 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | // Main application logic
document.addEventListener('DOMContentLoaded', function() {
// Check if user is logged in
const isLoggedIn = localStorage.getItem('isLoggedIn') === 'true';
if (isLoggedIn) {
updateUIForLoggedInUser();
}
// Instagram connection handler
document.getElementById('connectInstagram')?.addEventListener('click', function() {
if (!isLoggedIn) {
alert('Por favor, faça login primeiro.');
document.querySelector('custom-auth-modal').shadowRoot.querySelector('.modal').classList.remove('hidden');
return;
}
// In a real app, this would redirect to Instagram OAuth
alert('Redirecionando para o Instagram para autenticação...');
// Simulate loading reels after connection
setTimeout(() => {
loadSampleReels();
}, 1500);
});
});
function updateUIForLoggedInUser() {
const username = localStorage.getItem('username');
const navbar = document.querySelector('custom-navbar');
if (navbar && navbar.shadowRoot) {
const loginBtn = navbar.shadowRoot.querySelector('#loginBtn');
const userMenu = navbar.shadowRoot.querySelector('#userMenu');
if (loginBtn) loginBtn.classList.add('hidden');
if (userMenu) {
userMenu.classList.remove('hidden');
userMenu.querySelector('span').textContent = username;
}
}
}
function loadSampleReels() {
const reelsContainer = document.getElementById('reelsContainer');
if (!reelsContainer) return;
reelsContainer.innerHTML = '';
// Sample reels data - in a real app, this would come from an API
const sampleReels = [
{ id: 1, thumbnail: 'http://static.photos/travel/320x240/1', caption: 'Viagem incrível!', comments: 24 },
{ id: 2, thumbnail: 'http://static.photos/food/320x240/2', caption: 'Receita nova 🍕', comments: 42 },
{ id: 3, thumbnail: 'http://static.photos/nature/320x240/3', caption: 'Pôr do sol maravilhoso', comments: 15 },
{ id: 4, thumbnail: 'http://static.photos/sport/320x240/4', caption: 'Treino pesado hoje!', comments: 8 },
{ id: 5, thumbnail: 'http://static.photos/technology/320x240/5', caption: 'Novo gadget!', comments: 31 },
{ id: 6, thumbnail: 'http://static.photos/minimal/320x240/6', caption: 'Design limpo', comments: 12 }
];
sampleReels.forEach(reel => {
const reelElement = document.createElement('div');
reelElement.className = 'bg-white rounded-xl overflow-hidden shadow-sm reel-card';
reelElement.innerHTML = `
<img src="${reel.thumbnail}" alt="${reel.caption}" class="w-full h-48 object-cover">
<div class="p-4">
<p class="text-gray-800 font-medium mb-2 line-clamp-2">${reel.caption}</p>
<div class="flex justify-between items-center">
<span class="text-gray-500 text-sm"><i data-feather="message-square" class="w-4 h-4 inline mr-1"></i> ${reel.comments}</span>
<button class="add-bot-btn text-indigo-600 hover:text-indigo-800 font-medium text-sm" data-reel-id="${reel.id}">
<i data-feather="plus-circle" class="w-4 h-4 inline mr-1"></i> Adicionar bot
</button>
</div>
</div>
`;
reelsContainer.appendChild(reelElement);
});
// Add event listeners to all "Add bot" buttons
document.querySelectorAll('.add-bot-btn').forEach(button => {
button.addEventListener('click', function() {
const reelId = this.getAttribute('data-reel-id');
const botConfig = document.querySelector('custom-bot-config');
if (botConfig && botConfig.shadowRoot) {
botConfig.shadowRoot.querySelector('.modal').classList.remove('hidden');
botConfig.shadowRoot.querySelector('input[name="reelId"]').value = reelId;
}
});
});
feather.replace();
}
// Handle successful login
window.handleLoginSuccess = function(username) {
localStorage.setItem('isLoggedIn', 'true');
localStorage.setItem('username', username);
updateUIForLoggedInUser();
const authModal = document.querySelector('custom-auth-modal');
if (authModal && authModal.shadowRoot) {
authModal.shadowRoot.querySelector('.modal').classList.add('hidden');
}
// Load reels after login
loadSampleReels();
}; |