My Blog

My WordPress Blog

My Blog

My WordPress Blog

Social Media Dashboard

Sample Social Media Dashboard

1. HTML Structure

<!DOCTYPE html>
<html lang="en">
<head>
&lt;meta charset="UTF-8">
&lt;meta name="viewport" content="width=device-width, initial-scale=1.0">
&lt;title>Social Media Dashboard&lt;/title>
&lt;link rel="stylesheet" href="styles.css">
</head> <body>
&lt;div class="dashboard">
    &lt;h1>Social Media Dashboard&lt;/h1>
    &lt;div id="posts">&lt;/div>
&lt;/div>
&lt;script src="script.js">&lt;/script>
</body> </html>

2. CSS Styles (styles.css)

body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
} .dashboard {
max-width: 800px;
margin: auto;
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
} .post {
border-bottom: 1px solid #ddd;
padding: 10px 0;
} .post:last-child {
border-bottom: none;
} .post h2 {
margin: 0;
font-size: 18px;
} .post p {
margin: 5px 0;
} .post .engagement {
color: #888;
}

3. JavaScript Logic (script.js)

const postsContainer = document.getElementById('posts');

// Mock API data
const mockApiData = [
{
    id: 1,
    title: "Post One",
    content: "This is the content of post one.",
    likes: 25,
    shares: 5
},
{
    id: 2,
    title: "Post Two",
    content: "This is the content of post two.",
    likes: 15,
    shares: 3
},
{
    id: 3,
    title: "Post Three",
    content: "This is the content of post three.",
    likes: 30,
    shares: 10
}
]; // Function to render posts function renderPosts(posts) {
posts.forEach(post => {
    const postDiv = document.createElement('div');
    postDiv.classList.add('post');
    postDiv.innerHTML = `
        &lt;h2>${post.title}&lt;/h2>
        &lt;p>${post.content}&lt;/p>
        &lt;div class="engagement">
            &lt;span>${post.likes} Likes&lt;/span> | 
            &lt;span>${post.shares} Shares&lt;/span>
        &lt;/div>
    `;
    postsContainer.appendChild(postDiv);
});
} // Simulate fetching data from an API function fetchPosts() {
// Simulating an API call with setTimeout
setTimeout(() => {
    renderPosts(mockApiData);
}, 1000);
} // Initialize the dashboard fetchPosts();

Explanation

  1. HTML: The HTML file sets up the structure for the dashboard, including a title and a container for the posts.
  2. CSS: The styles give the dashboard a clean, modern look. You can adjust colors and spacing to fit your needs.
  3. JavaScript:
    • A mock data array simulates posts you’d get from a social media API.
    • The renderPosts function dynamically creates and displays each post.
    • fetchPosts simulates an API call using setTimeout to delay rendering.
Social Media Dashboard

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top