|
| 1 | +--- |
| 2 | +import { getCollection } from 'astro:content'; |
| 3 | +import Layout from '@layouts/SectionLayout.astro'; // Adjust path as needed |
| 4 | +import SprintCard from '@components/SprintCard.astro'; |
| 5 | +import Headline from "@ui/Headline.astro" |
| 6 | +
|
| 7 | +// Get all sprint entries |
| 8 | +const sprints = await getCollection("sprints", ({ data }) => { |
| 9 | + return import.meta.env.MODE === "production" ? data.draft !== true : true; |
| 10 | +}); |
| 11 | +
|
| 12 | +// Sort sprints by title or any other criteria |
| 13 | +const sortedSprints = sprints.sort((a, b) => |
| 14 | + a.data.title.localeCompare(b.data.title) |
| 15 | +); |
| 16 | +
|
| 17 | +// Filter by status if needed |
| 18 | +const activeSprints = sortedSprints.filter(sprint => |
| 19 | + sprint.data.status === 'active' |
| 20 | +); |
| 21 | +
|
| 22 | +// Extract unique rooms for filter |
| 23 | +const uniqueRooms = Array.from(new Set(activeSprints.map(sprint => sprint.data.room))); |
| 24 | +--- |
| 25 | + |
| 26 | +<Layout title="Sprints & Workshops" description="All in one"> |
| 27 | + <main class="min-h-screen py-8"> |
| 28 | + <div class="max-w-6xl mx-auto px-4"> |
| 29 | + <header class="text-center mb-12"> |
| 30 | + <h1 class="text-5xl font-bold text-gray-900 mb-4">Sprints & Workshops</h1> |
| 31 | + <p class="text-xl text-gray-600 max-w-2xl mx-auto leading-relaxed"> |
| 32 | + Join collaborative coding sessions and hands-on workshops. |
| 33 | + Connect with maintainers, contribute to open source projects, |
| 34 | + and learn new skills alongside fellow Python enthusiasts. |
| 35 | + </p> |
| 36 | + </header> |
| 37 | + |
| 38 | + <div class="flex flex-wrap gap-8 justify-center mb-8"> |
| 39 | + <div class="flex flex-col gap-2"> |
| 40 | + <label for="level-filter" class="font-semibold text-gray-700 text-sm">Python Level:</label> |
| 41 | + <select id="level-filter" class="px-4 py-2 border border-gray-300 rounded-lg bg-white text-sm min-w-[150px] focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"> |
| 42 | + <option value="">All Levels</option> |
| 43 | + <option value="Any">Any</option> |
| 44 | + <option value="Beginner">Beginner</option> |
| 45 | + <option value="Intermediate">Intermediate</option> |
| 46 | + <option value="Advanced">Advanced</option> |
| 47 | + </select> |
| 48 | + </div> |
| 49 | + |
| 50 | + <div class="flex flex-col gap-2"> |
| 51 | + <label for="room-filter" class="font-semibold text-gray-700 text-sm">Room:</label> |
| 52 | + <select id="room-filter" class="px-4 py-2 border border-gray-300 rounded-lg bg-white text-sm min-w-[150px] focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"> |
| 53 | + <option value="">All Rooms</option> |
| 54 | + {uniqueRooms.map((room) => ( |
| 55 | + <option value={room}>{room}</option> |
| 56 | + ))} |
| 57 | + </select> |
| 58 | + </div> |
| 59 | + </div> |
| 60 | + |
| 61 | + <div class="text-center mb-8"> |
| 62 | + <p class="text-gray-600 font-medium">{activeSprints.length} active {activeSprints.length === 1 ? 'sprint' : 'sprints'}</p> |
| 63 | + </div> |
| 64 | + |
| 65 | + <section class="max-w-4xl mx-auto" id="sprints-list"> |
| 66 | + {activeSprints.map((sprint) => ( |
| 67 | + <SprintCard slug={sprint.slug} /> |
| 68 | + ))} |
| 69 | + </section> |
| 70 | + |
| 71 | + {activeSprints.length === 0 && ( |
| 72 | + <div class="text-center py-12"> |
| 73 | + <p class="text-gray-500 text-lg">No sprints are currently available. Check back soon!</p> |
| 74 | + </div> |
| 75 | + )} |
| 76 | + </div> |
| 77 | + </main> |
| 78 | + |
| 79 | + <script> |
| 80 | + // Client-side filtering |
| 81 | + document.addEventListener('DOMContentLoaded', () => { |
| 82 | + const levelFilter = document.getElementById('level-filter') as HTMLSelectElement; |
| 83 | + const roomFilter = document.getElementById('room-filter') as HTMLSelectElement; |
| 84 | + const sprintsList = document.getElementById('sprints-list'); |
| 85 | + const sprintsCount = document.querySelector('.text-center.mb-8 p'); |
| 86 | + |
| 87 | + function filterSprints() { |
| 88 | + const selectedLevel = levelFilter.value; |
| 89 | + const selectedRoom = roomFilter.value; |
| 90 | + const sprintCards = sprintsList?.querySelectorAll('.sprint-card'); |
| 91 | + |
| 92 | + let visibleCount = 0; |
| 93 | + |
| 94 | + sprintCards?.forEach((card) => { |
| 95 | + const cardElement = card as HTMLElement; |
| 96 | + const pythonLevel = cardElement.getAttribute('data-python-level'); |
| 97 | + const room = cardElement.getAttribute('data-room'); |
| 98 | + |
| 99 | + const levelMatch = !selectedLevel || pythonLevel === selectedLevel; |
| 100 | + const roomMatch = !selectedRoom || room === selectedRoom; |
| 101 | + |
| 102 | + if (levelMatch && roomMatch) { |
| 103 | + cardElement.style.display = 'block'; |
| 104 | + visibleCount++; |
| 105 | + } else { |
| 106 | + cardElement.style.display = 'none'; |
| 107 | + } |
| 108 | + }); |
| 109 | + |
| 110 | + if (sprintsCount) { |
| 111 | + sprintsCount.textContent = `${visibleCount} active ${visibleCount === 1 ? 'sprint' : 'sprints'}`; |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + levelFilter?.addEventListener('change', filterSprints); |
| 116 | + roomFilter?.addEventListener('change', filterSprints); |
| 117 | + }); |
| 118 | + </script> |
| 119 | +</Layout> |
0 commit comments