diff --git a/public/favicon.png b/public/favicon.png new file mode 100644 index 0000000..4c3043e Binary files /dev/null and b/public/favicon.png differ diff --git a/public/qr-url-to-prod.png b/public/qr-url-to-prod.png new file mode 100644 index 0000000..3cfd1d2 Binary files /dev/null and b/public/qr-url-to-prod.png differ diff --git a/src/app/about/page.tsx b/src/app/about/page.tsx index 5af79eb..98de955 100644 --- a/src/app/about/page.tsx +++ b/src/app/about/page.tsx @@ -2,11 +2,11 @@ import Link from "next/link"; export default function About() { return ( -
+
About
-
+
We want to thank{" "} + + + + {children} ); diff --git a/src/app/page.tsx b/src/app/page.tsx index 85e8764..8f5c386 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -15,9 +15,17 @@ const complexityColor: Record = { export default function Home() { const [puzzle, setPuzzle] = useState(); const [complexity, setComplexity] = useState(); - const years = [2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022]; + const availableYears = [2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022]; const days = Array.from({ length: 25 }, (_, i) => i + 1); + const [years, setYears] = useState([2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022]); + + const toggleYear = (year: number) => { + years.includes(year) + ? setYears(years.filter(y => y !== year)) + : setYears([year, ...years]); + }; + const handleClick = async (name: Complexities) => { setComplexity(name); const puzzle: Puzzle = { @@ -28,13 +36,14 @@ export default function Home() { complexity: 0, noSolutionDiff: 0, }; + const yearsToConsider = years.length ? years : availableYears; setPuzzle(puzzle); const incrementTime = 150; let timer = setInterval(() => { - const year = getRandom(years); + const year = getRandom(yearsToConsider); const day = getRandom(days); setPuzzle({ ...puzzle, year, day }); }, incrementTime); @@ -42,18 +51,35 @@ export default function Home() { setTimeout(async () => { clearInterval(timer); - setPuzzle(await getRandomPuzzle(name)); + setPuzzle(await getRandomPuzzle(name, yearsToConsider)); }, 3000); }; return ( -
+
-
+
Advent of Code Random Puzzle Picker
-
Pick a complexity
-
+
Pick a complexity and years
+
+ {availableYears.map(y => ( + + ))} +
+
); diff --git a/src/puzzles.ts b/src/puzzles.ts index 0c22bc7..4902ffd 100644 --- a/src/puzzles.ts +++ b/src/puzzles.ts @@ -25,8 +25,8 @@ interface PuzzleComplexity { noSolutionCount: number; } -async function getPuzzleClasses(medals: Medals) { - const years = Object.keys(medals); +async function getPuzzleClasses(medals: Medals, onlyForYears: number[]) { + const years = Object.keys(medals).filter(y => onlyForYears.includes(parseInt(y))); const complexity: Record = {}; for (const year of years) { const yearUsers = Object.keys(medals[year]); @@ -110,8 +110,8 @@ export type Puzzle = { noSolutionDiff: number; }; -export async function getRandomPuzzle(name: Complexities) { - const [classes, puzzles, noSolutionAverage] = await getPuzzleClasses(medals); +export async function getRandomPuzzle(name: Complexities, years: number[]) { + const [classes, puzzles, noSolutionAverage] = await getPuzzleClasses(medals, years); const puzzleId = getRandom(classes[name]); const puzzle = puzzles.find((puzzle) => puzzle.id === puzzleId); return {