From 41441b546ec6b6fcea9467b74787f3be118c7853 Mon Sep 17 00:00:00 2001 From: Malted Date: Sat, 31 Aug 2024 17:59:28 -0400 Subject: [PATCH] Add progress bar --- components/replit/form.js | 22 ++++++--- pages/api/replit/progress.js | 5 +- pages/replit.js | 88 +++++++++++++++++++++++++++++++----- 3 files changed, 94 insertions(+), 21 deletions(-) diff --git a/components/replit/form.js b/components/replit/form.js index 056558cc..75d00818 100644 --- a/components/replit/form.js +++ b/components/replit/form.js @@ -12,10 +12,19 @@ const ReplitForm = ({ cssDark }) => { const [isSubmitted, setIsSubmitted] = useState(false) const [buttonText, setButtonText] = useState('Submit') const [formData, setFormData] = useState({}) + const [stickerPositions, setStickerPositions] = useState([]) let jsConfetti = useRef() let draggedSticker = useRef() useEffect(() => { + stickers.forEach((_, idx) => { + stickerPositions.push({ + rotation: `${(Math.random() - 0.5) * 80}deg`, + position: getRandomPointOnUnitSquare() + }) + }) + setStickerPositions(stickerPositions) + jsConfetti.current = new JSConfetti() document.onmousedown = e => { @@ -71,6 +80,7 @@ const ReplitForm = ({ cssDark }) => { if (res.ok) { setButtonText(data.message) if (data.success) { + localStorage.setItem('token', formData.token) jsConfetti.current.addConfetti({ confettiColors: [ theme.colors.red, @@ -254,7 +264,6 @@ const ReplitForm = ({ cssDark }) => { {stickers.map((sticker, idx) => { - const pos = getRandomPointOnUnitSquare() return ( { className="sticker" sx={{ position: 'absolute', - rotate: `${(Math.random() - 0.5) * 80}deg`, - left: `${pos[0] * 100}%`, - top: `${pos[1] * 100}%`, - translate: '-50% -50%' + rotate: stickerPositions[idx]?.rotation, + left: `${stickerPositions[idx]?.position[0] * 100}%`, + top: `${stickerPositions[idx]?.position[1] * 100}%`, + translate: '-50% -50%', + zIndex: 5 }} draggable="false" key={idx} @@ -301,8 +311,6 @@ const ReplitForm = ({ cssDark }) => { return ( { + const [progress, setProgress] = useState(null) + + useEffect(() => { + const interval = setInterval(async () => { + const token = localStorage.getItem('token') + if (!token) return + + try { + const response = await fetch(`/api/replit/progress?token=${token}`) + if (!response.ok) throw new Error('Failed to fetch progress') + const data = await response.json() + console.info(data) + setProgress(data) + } catch (err) { + console.error("Couldn't get progress:", err) + } + }, 1000) + + return () => clearInterval(interval) + }, []) + const steps = [ 'Enter your email', 'Enter your replit token', @@ -111,7 +142,14 @@ const ReplitPage = () => { - + { /> - - - Hey! This is an unreleased project - hold off from filling this out - for now. -
- If you want to help test, contact @Malted on the Slack! -
-
+ + {progress ? ( + + + {progress.successful} of {progress.repl_count} repls processed! + {progress.failed.timed_out + progress.failed.failed > 0 ? ( + + {' '} + (+ {progress.failed.timed_out + progress.failed.failed}{' '} + error + {progress.failed.timed_out + progress.failed.failed !== 1 + ? 's' + : null} + ) + + ) : null} + + + + + ) : null} -