Skip to content

Commit

Permalink
list of past values, ugly edition
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Davids authored and Peter Davids committed Feb 23, 2020
1 parent 00a4a9a commit 489d4a2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@ input::-webkit-inner-spin-button {

.the-icon svg {
font-size: 4rem;
}
}

.past-value-list-container {
position: absolute;
left:0;
right:0;
margin-left:auto;
margin-right:auto;
}
21 changes: 19 additions & 2 deletions src/TheWholeThing/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react'
import React, { useState, useEffect } from 'react'
import TextField from '@material-ui/core/TextField'
import IconButton from '@material-ui/core/IconButton'
import ArrowRightIcon from '@material-ui/icons/ArrowRight'
Expand All @@ -7,8 +7,18 @@ import Confetti from 'react-confetti'
const TheWholeThing = () => {
const [ subtext, setSubtext ] = useState("Enter a number")
const [ value, setValue ] = useState("")
const [ valueList, setValueList ] = useState([])
const [ celebrate, setCelebrate ] = useState(false)

useEffect(() => {
if(valueList.length === 0) {
valueList.push(`Start: ${value}`)
} else {
valueList.push(`${value} ${subtext}`)
}
setValueList(valueList)
}, [ value, valueList, subtext ]);

const handleKeyDown = (event) => {
if (event.key === 'Enter') {
handleClick()
Expand All @@ -17,12 +27,12 @@ const TheWholeThing = () => {

const handleChange = (event) => {
setValue(event.target.value)
setValueList([])
setCelebrate(false)
}

const handleClick = () => {
const intValue = parseInt(value)
// todo rewrite to compute collatz value in separate function and do it first
if (!intValue || intValue < 0) {
setValue("")
setSubtext("Enter a number")
Expand Down Expand Up @@ -67,6 +77,13 @@ const TheWholeThing = () => {
>
<ArrowRightIcon fontSize="inherit" />
</IconButton>
<div className="past-value-list-container">
{ valueList.slice(0).reverse().map(value =>
<div>
{ value }
</div>)
}
</div>
</>
}

Expand Down

0 comments on commit 489d4a2

Please sign in to comment.