diff --git a/pages/dev/counter.js b/pages/dev/counter.js new file mode 100644 index 0000000..c8fe396 --- /dev/null +++ b/pages/dev/counter.js @@ -0,0 +1,72 @@ +import Footer from '@/components/Footer' +import Header from '@/components/Header' +import Head from 'next/head' +import { useEffect, useState } from 'react'; +import { Box, Container, Flex, Heading, useColorMode } from 'theme-ui' + +function currentAmount(startTime, untilYesterday, lastDay) { + const elapsed = Date.now() - startTime; + const fullDay = 1000 * 60 * 60 * 24; + const additional = elapsed / fullDay * lastDay; + + return untilYesterday + additional; +} + +export default function Counter({ untilYesterday, lastDay, startTime, initialValue }) { + const [transactionAmount, setTransactionAmount] = useState(initialValue); + + useEffect(() => { + const interval = setInterval(() => { + setTransactionAmount(currentAmount(startTime, untilYesterday, lastDay)); + }, 50); + return () => clearInterval(interval); + }, []); + return ( + <> +
+