Delete script.js
Browse files
script.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
| 1 |
-
document.addEventListener('DOMContentLoaded', () => {
|
| 2 |
-
fetchTeamData();
|
| 3 |
-
setupEventListeners();
|
| 4 |
-
feather.replace();
|
| 5 |
-
});
|
| 6 |
-
|
| 7 |
-
// Fetch Data from Public API (RandomUser.me)
|
| 8 |
-
async function fetchTeamData() {
|
| 9 |
-
const grid = document.getElementById('team-grid');
|
| 10 |
-
const btn = document.getElementById('refresh-team');
|
| 11 |
-
|
| 12 |
-
// Add loading state visual
|
| 13 |
-
if(btn) {
|
| 14 |
-
const icon = btn.querySelector('[data-feather]');
|
| 15 |
-
if(icon) icon.classList.add('animate-spin');
|
| 16 |
-
btn.disabled = true;
|
| 17 |
-
btn.innerHTML = 'Loading...';
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
try {
|
| 21 |
-
const response = await fetch('https://randomuser.me/api/?results=4&nat=us,gb,ca,au,de');
|
| 22 |
-
const data = await response.json();
|
| 23 |
-
renderTeam(data.results);
|
| 24 |
-
} catch (error) {
|
| 25 |
-
console.error('Error fetching team:', error);
|
| 26 |
-
grid.innerHTML = `
|
| 27 |
-
<div class="col-span-full text-center text-red-500 p-8 bg-red-50 rounded-xl border border-red-100">
|
| 28 |
-
<i data-feather="alert-circle" class="inline-block mb-2"></i>
|
| 29 |
-
<p>Failed to load team data. Please try again.</p>
|
| 30 |
-
</div>
|
| 31 |
-
`;
|
| 32 |
-
feather.replace();
|
| 33 |
-
} finally {
|
| 34 |
-
// Reset button state
|
| 35 |
-
if(btn) {
|
| 36 |
-
btn.disabled = false;
|
| 37 |
-
btn.innerHTML = `<i data-feather="refresh-cw" class="w-4 h-4"></i> Refresh Team`;
|
| 38 |
-
feather.replace();
|
| 39 |
-
}
|
| 40 |
-
}
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
// Render Team Cards
|
| 44 |
-
function renderTeam(users) {
|
| 45 |
-
const grid = document.getElementById('team-grid');
|
| 46 |
-
grid.innerHTML = '';
|
| 47 |
-
|
| 48 |
-
users.forEach((user, index) => {
|
| 49 |
-
const card = document.createElement('div');
|
| 50 |
-
card.className = 'bg-white rounded-2xl p-6 shadow-sm border border-slate-100 text-center hover:shadow-md transition-all duration-300 group animate-fade-in';
|
| 51 |
-
card.style.animationDelay = `${index * 100}ms`;
|
| 52 |
-
|
| 53 |
-
card.innerHTML = `
|
| 54 |
-
<div class="relative w-24 h-24 mx-auto mb-4">
|
| 55 |
-
<img src="${user.picture.large}" alt="${user.name.first}" class="w-full h-full rounded-full object-cover ring-4 ring-indigo-50 group-hover:ring-primary transition-all">
|
| 56 |
-
<div class="absolute bottom-0 right-0 w-6 h-6 bg-green-500 border-2 border-white rounded-full"></div>
|
| 57 |
-
</div>
|
| 58 |
-
<h3 class="font-bold text-lg text-slate-800 capitalize">${user.name.first} ${user.name.last}</h3>
|
| 59 |
-
<p class="text-primary text-sm font-medium mb-3">Product Designer</p>
|
| 60 |
-
<p class="text-slate-500 text-xs mb-4">${user.location.city}, ${user.location.country}</p>
|
| 61 |
-
<div class="flex justify-center gap-3">
|
| 62 |
-
<a href="#" class="text-slate-400 hover:text-blue-500 transition-colors"><i data-feather="linkedin" class="w-4 h-4"></i></a>
|
| 63 |
-
<a href="#" class="text-slate-400 hover:text-gray-800 transition-colors"><i data-feather="github" class="w-4 h-4"></i></a>
|
| 64 |
-
<a href="#" class="text-slate-400 hover:text-blue-400 transition-colors"><i data-feather="twitter" class="w-4 h-4"></i></a>
|
| 65 |
-
</div>
|
| 66 |
-
`;
|
| 67 |
-
grid.appendChild(card);
|
| 68 |
-
});
|
| 69 |
-
feather.replace();
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
function setupEventListeners() {
|
| 73 |
-
const refreshBtn = document.getElementById('refresh-team');
|
| 74 |
-
if (refreshBtn) {
|
| 75 |
-
refreshBtn.addEventListener('click', fetchTeamData);
|
| 76 |
-
}
|
| 77 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|