Skip to content

Commit

Permalink
📝 Add back buggy "solved times" at the end of each advent (#5503)
Browse files Browse the repository at this point in the history
Reverts #5501
  • Loading branch information
dubzzz authored Dec 9, 2024
1 parent 32e68f2 commit 833dc71
Showing 1 changed file with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,44 @@ export function buildAdventOfTheDay(options: Options) {
placeholder={`Example of answer:\n${placeholderForm}`}
></textarea>
<br />
<button type="submit">Submit</button>
<div>
<button type="submit">Submit</button>
<SolvedTimes />
</div>
</form>
</>
);
}

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 (
<span style={{ marginLeft: '1rem' }}>
{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' : ''}!`}
</span>
);
}

return { AdventPlaygroundOfTheDay, FormOfTheDay };
}

Expand Down

0 comments on commit 833dc71

Please sign in to comment.