diff --git a/website/blog/2024-12-01-advent-of-pbt-day-1/AdventOfTheDayBuilder.tsx b/website/blog/2024-12-01-advent-of-pbt-day-1/AdventOfTheDayBuilder.tsx index 3ba5e56fc2e..ec9861734a9 100644 --- a/website/blog/2024-12-01-advent-of-pbt-day-1/AdventOfTheDayBuilder.tsx +++ b/website/blog/2024-12-01-advent-of-pbt-day-1/AdventOfTheDayBuilder.tsx @@ -147,12 +147,44 @@ export function buildAdventOfTheDay(options: Options) { placeholder={`Example of answer:\n${placeholderForm}`} >
- +
+ + +
); } + function SolvedTimes() { + const [times, setTimes] = useState(null); + useEffect(() => { + async function update() { + try { + const response = await fetch(`https://api.counterapi.dev/v1/fast-check/AdventOfPBT2024Day${day}Success`); + const data = await response.json(); + const count = data.count || 0; + setTimes(count); + } catch (err) { + setTimes(-1); + } + } + update(); + }, []); + + return ( + + {times === null + ? 'Loading the solve count...' + : times === 0 + ? 'Be the first to solve this challenge!' + : times === -1 + ? 'Unable to retrieve the solve count at the moment.' + : `This puzzle has been solved ${times} time${times > 1 ? 's' : ''}!`} + + ); + } + return { AdventPlaygroundOfTheDay, FormOfTheDay }; }