|
| 1 | +--- |
| 2 | +import { getCollection } from 'astro:content'; |
| 3 | +import { getEntry, render } from 'astro:content'; |
| 4 | +import Layout from '@layouts/MarkdownLayout.astro'; |
| 5 | +import SprintCard from '@components/SprintCard.astro'; |
| 6 | +import Markdown from "@ui/Markdown.astro"; |
| 7 | +
|
| 8 | +const entry = await getEntry('pages', 'sprints_info'); |
| 9 | +
|
| 10 | +if (!entry) { |
| 11 | + throw new Error('Could not find page entry.'); |
| 12 | +} |
| 13 | +
|
| 14 | +const sprints = await getCollection("sprints", ({ data }) => { |
| 15 | + return import.meta.env.MODE === "production" ? data.draft !== true : true; |
| 16 | +}); |
| 17 | +
|
| 18 | +--- |
| 19 | + |
| 20 | +<Layout title=`${entry.title}` description=`${entry.description}` toc=true> |
| 21 | + |
| 22 | + <Markdown content={entry.body} /> |
| 23 | + <div class="flex flex-wrap gap-8 justify-center my-8"> |
| 24 | + <div class="flex flex-col gap-2"> |
| 25 | + <label for="level-filter" class="font-semibold text-gray-700 text-lg">Python Level:</label> |
| 26 | + <select id="level-filter" class="px-4 py-2 border border-gray-300 rounded-lg bg-white text-lg min-w-[150px] focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"> |
| 27 | + <option value="">All Levels</option> |
| 28 | + <option value="Any">Any</option> |
| 29 | + <option value="Beginner">Beginner</option> |
| 30 | + <option value="Intermediate">Intermediate</option> |
| 31 | + <option value="Advanced">Advanced</option> |
| 32 | + </select> |
| 33 | + </div> |
| 34 | + </div> |
| 35 | + |
| 36 | + <div class="text-center mb-8"> |
| 37 | + <p class="text-gray-600 font-medium">{sprints.length} active {sprints.length === 1 ? 'sprint' : 'sprints'}</p> |
| 38 | + </div> |
| 39 | + |
| 40 | + <section class="max-w-4xl mx-auto" id="sprints-list"> |
| 41 | + {sprints.map((sprint) => ( |
| 42 | + <SprintCard slug={sprint.slug} /> |
| 43 | + ))} |
| 44 | + </section> |
| 45 | + |
| 46 | + {sprints.length === 0 && ( |
| 47 | + <div class="text-center py-12"> |
| 48 | + <p class="text-gray-500 text-lg">No sprints are currently available. Check back soon!</p> |
| 49 | + </div> |
| 50 | + )} |
| 51 | +</Layout> |
| 52 | + |
| 53 | + <script> |
| 54 | + document.addEventListener('DOMContentLoaded', () => { |
| 55 | + const levelFilter = document.getElementById('level-filter') as HTMLSelectElement; |
| 56 | + const sprintsList = document.getElementById('sprints-list'); |
| 57 | + const sprintsCount = document.querySelector('.text-center.mb-8 p'); |
| 58 | + |
| 59 | + function filterSprints() { |
| 60 | + const selectedLevel = levelFilter.value; |
| 61 | + const sprintCards = sprintsList?.querySelectorAll('.sprint-card'); |
| 62 | + |
| 63 | + let visibleCount = 0; |
| 64 | + |
| 65 | + sprintCards?.forEach((card) => { |
| 66 | + const cardElement = card as HTMLElement; |
| 67 | + const pythonLevel = cardElement.getAttribute('data-python-level'); |
| 68 | + |
| 69 | + const levelMatch = !selectedLevel || pythonLevel === selectedLevel; |
| 70 | + |
| 71 | + if (levelMatch) { |
| 72 | + cardElement.style.display = 'block'; |
| 73 | + visibleCount++; |
| 74 | + } else { |
| 75 | + cardElement.style.display = 'none'; |
| 76 | + } |
| 77 | + }); |
| 78 | + |
| 79 | + if (sprintsCount) { |
| 80 | + sprintsCount.textContent = `${visibleCount} active ${visibleCount === 1 ? 'sprint' : 'sprints'}`; |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + levelFilter?.addEventListener('change', filterSprints); |
| 85 | + }); |
| 86 | + </script> |
0 commit comments