File size: 2,491 Bytes
be29055
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
document.addEventListener('DOMContentLoaded', () => {
    const feedContainer = document.getElementById('feed-container');
    
    // Mock Data Generation using Real Public APIs structure
    async function fetchPosts() {
        try {
            // Fetching random users to simulate posts
            const response = await fetch('https://randomuser.me/api/?results=5');
            const data = await response.json();
            
            feedContainer.innerHTML = ''; // Clear loader
            
            data.results.forEach((user, index) => {
                // Generate Post Data
                const postData = {
                    name: `${user.name.first} ${user.name.last}`,
                    avatar: user.picture.large,
                    time: `${Math.floor(Math.random() * 12) + 1}h`,
                    content: `Just had an amazing experience today! Can't believe how fast technology is evolving. #Life #GoodVibes`,
                    image: `http://static.photos/${getRandomCategory()}/640x360/${Math.floor(Math.random() * 100)}`,
                    likes: Math.floor(Math.random() * 500) + 10,
                    comments: Math.floor(Math.random() * 50) + 1
                };
                
                // Create Custom Element
                const postElement = document.createElement('post-card');
                postElement.setAttribute('data-name', postData.name);
                postElement.setAttribute('data-avatar', postData.avatar);
                postElement.setAttribute('data-time', postData.time);
                postElement.setAttribute('data-content', postData.content);
                postElement.setAttribute('data-image', postData.image);
                postElement.setAttribute('data-likes', postData.likes);
                postElement.setAttribute('data-comments', postData.comments);
                
                feedContainer.appendChild(postElement);
            });
            
            // Refresh icons for new elements
            feather.replace();

        } catch (error) {
            console.error('Error fetching posts:', error);
            feedContainer.innerHTML = '<p class="text-center text-red-500">Failed to load posts. Please refresh.</p>';
        }
    }

    function getRandomCategory() {
        const categories = ['nature', 'cityscape', 'technology', 'food', 'workspace', 'travel'];
        return categories[Math.floor(Math.random() * categories.length)];
    }

    fetchPosts();
});