File size: 5,213 Bytes
b815ccc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Main JavaScript for CreatorVerse Hub

// Initialize the application
document.addEventListener('DOMContentLoaded', function() {
    initializeApp();
});

function initializeApp() {
    console.log('CreatorVerse Hub initialized');
    
    // Add intersection observer for animations
    setupScrollAnimations();
    
    // Initialize any interactive elements
    setupInteractiveElements();
    
    // Handle mobile navigation
    setupMobileNavigation();
}

// Scroll animations
function setupScrollAnimations() {
    const observerOptions = {
        threshold: 0.1,
        rootMargin: '0px 0px -50px 0px'
    };

    const observer = new IntersectionObserver(function(entries) {
        entries.forEach(function(entry) {
            if (entry.isIntersecting) {
                entry.target.classList.add('fade-in-up');
            }
        });
    }, observerOptions);

    // Observe all elements with the animate-on-scroll class
    document.querySelectorAll('.animate-on-scroll').forEach(function(el) {
        observer.observe(el);
    });
}

// Interactive elements
function setupInteractiveElements() {
    // Add click handlers for creator cards
    const creatorCards = document.querySelectorAll('.creator-card');
    creatorCards.forEach(function(card) {
        card.addEventListener('click', function() {
            const creatorLink = this.querySelector('a').href;
            window.location.href = creatorLink;
        });
    });

    // Setup search functionality
    const searchInput = document.getElementById('searchInput');
    if (searchInput) {
        searchInput.addEventListener('input', debounce(function(e) {
            performSearch(e.target.value);
        }, 300));
    }
}

// Mobile navigation
function setupMobileNavigation() {
    const mobileMenuButton = document.getElementById('mobileMenuButton');
    const mobileMenu = document.getElementById('mobileMenu');

    if (mobileMenuButton && mobileMenu) {
        mobileMenuButton.addEventListener('click', function() {
            mobileMenu.classList.toggle('hidden');
        });
    }
}

// Search functionality
function performSearch(query) {
    if (query.length < 2) return;

    console.log('Searching for:', query);
    
    // In a real implementation, this would make an API call
    // For now, we'll just log and show a notification
    showNotification(`Searching for "${query}"...`);
}

// Notification system
function showNotification(message, type = 'info') {
    // Create notification element
    const notification = document.createElement('div');
    notification.className = `fixed top-4 right-4 p-4 rounded-lg shadow-lg z-50 transform transition-transform duration-300 ${
        type === 'error' ? 'bg-red-500' : 
        type === 'success' ? 'bg-green-500' : 'bg-primary'
    } text-white`;
    notification.textContent = message;
    
    document.body.appendChild(notification);
    
    // Remove notification after 3 seconds
    setTimeout(function() {
        notification.style.transform = 'translateX(100%)';
        setTimeout(function() {
            if (notification.parentNode) {
                notification.parentNode.removeChild(notification);
        }, 300);
    }, 3000);
}

// Utility function for debouncing
function debounce(func, wait) {
    let timeout;
    return function executedFunction(...args) {
        const later = function() {
            clearTimeout(timeout);
            func(...args);
        };
        clearTimeout(timeout);
        timeout = setTimeout(later, wait);
    };
}

// API functions for creator data
async function fetchFeaturedCreators() {
    try {
        // In a real implementation, this would fetch from your API
        const response = await fetch('/api/creators/featured');
        const creators = await response.json();
        return creators;
    } catch (error) {
        console.error('Error fetching featured creators:', error);
        return [];
    }
}

// Handle user authentication state
function checkAuthState() {
    const token = localStorage.getItem('authToken');
    if (token) {
        updateUIForLoggedInUser();
    } else {
        updateUIForGuest();
    }
}

function updateUIForLoggedInUser() {
    const authButtons = document.querySelectorAll('.auth-buttons');
    authButtons.forEach(function(container) {
        container.innerHTML = `
            <a href="/profile" class="bg-secondary hover:bg-yellow-500 text-white font-bold py-2 px-6 rounded-full transition duration-300">
                My Profile
            </a>
        `;
    });
}

function updateUIForGuest() {
    const authButtons = document.querySelectorAll('.auth-buttons');
    authButtons.forEach(function(container) {
        container.innerHTML = `
            <a href="/login" class="text-dark hover:text-primary font-semibold transition duration-300">
                Log In
            </a>
            <a href="/signup" class="bg-primary hover:bg-purple-600 text-white font-bold py-2 px-6 rounded-full transition duration-300">
                Sign Up
            </a>
        `;
    });
}

// Export functions for use in other modules
window.CreatorVerse = {
    showNotification,
    fetchFeaturedCreators,
    checkAuthState
};