diff --git a/README.md b/README.md index 8b6d5ef..c69b966 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -#Advent of Code +#Advent of Code# My solutions to the challenges for Advent of Code 2023 diff --git a/src/App.css b/src/App.css index 226b7f3..c3d3a10 100644 --- a/src/App.css +++ b/src/App.css @@ -33,7 +33,8 @@ } .card { - padding: 2em; + padding: 1em; + max-width:50em; } .split-card { @@ -46,8 +47,8 @@ } .large-editor-textarea { - margin: 16px; + margin: 6px; border-radius:1em; - height:20em; + height:25em; width:100%; } \ No newline at end of file diff --git a/src/App.tsx b/src/App.tsx index 724b7fe..097525f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,33 +2,36 @@ import './App.css'; import reactLogo from './assets/react.svg'; import { ChangeEvent, useCallback, useRef, useState } from 'react'; import { DayPicker } from 'react-day-picker'; -import { getPuzzlesByDay } from 'data/puzzles/getPuzzlesByDay'; import { PuzzleResult } from 'models'; -import { solvePuzzle } from 'data/solutions/solvePuzzle'; +import { solvePuzzle } from 'data/solvePuzzle'; +import { NotificationBox } from 'components/notification-box/NotificationBox'; import 'react-day-picker/dist/style.css'; -import 'components/notification-box/NotificationBox.css'; -import NotificationBox from 'components/notification-box/NotificationBox'; +import { Toggler } from 'components/toggler/Toggler'; function App() { - let puzzles: string[] = []; + const errorText = `Uh oh, we couldn't find an answer for that puzzle!`; const puzzleInputRef = useRef(null); const [selectedDate, setSelectedDate] = useState(); - // const [ selectedPuzzle, setSelectedPuzzle ] = useState(); const [puzzleInput, setPuzzleInput] = useState(); - const [answer, setAnswer] = useState(); + const [answer, setAnswer] = useState(null); + const [badAnswer, setBadAnswer] = useState(false); + const [answerPart2, setAnswerPart2] = useState(false); const handleChangeDate = async (date: Date) => { - puzzles = []; + setAnswer(null); setSelectedDate(date); - const day = date.getDate(); - const thisDaysPuzzles = await getPuzzlesByDay(day); - puzzles.push(...thisDaysPuzzles); + }; + + const handleToggle = async (checked: boolean) => { + setAnswer(null); + setAnswerPart2(checked); }; const handleChangePuzzleInput = useCallback( (e: ChangeEvent) => { + setAnswer(null); const { value } = e.currentTarget; setPuzzleInput(value); }, @@ -36,14 +39,15 @@ function App() { ); const handleSolvePuzzle = async () => { + setAnswer(null); const day = selectedDate?.getDate(); - const answer = !!day && (await solvePuzzle(day, puzzleInput || '')); + const answer = !!day && (await solvePuzzle(day, answerPart2, puzzleInput || '')); answer && setAnswer(answer); + const badAnswer = !!(answer && answer.answer === '' && !answer.values.length); + setBadAnswer(badAnswer); }; const disabled = !(puzzleInput && selectedDate); - const badAnswer = !!(answer && answer.answer === '' && !answer.values.length); - const errorText = `Uh oh, we couldn't find an answer for that puzzle!`; return (
@@ -54,44 +58,44 @@ function App() {

Advent of Code Solutions

- Please select a date and a puzzle, then enter some input, and click - "Solve" to see the output. + Please select a date and enter some input, and click "Solve" to see the + answer!

-
-

Date

- -
- {/*
-

Puzzle

-
    - {puzzles.map((puzzle, index) => -
  • {puzzle}
  • - )} -
-
*/} -
-

Input

-