From 564ed2ee975de448866b23b650f0a5da4a428342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Max-Ow=C3=B3lab=C3=AD?= Date: Mon, 10 Aug 2026 07:25:19 +0100 Subject: [PATCH] feat: resolves issue #16 - add loading state while routes are calculated --- CHANGELOG.md | 2 ++ src/App.jsx | 19 +++++++++++++--- src/styles.css | 23 ++++++++++++++++++++ tests/App.test.jsx | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 tests/App.test.jsx diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e6fb2c..9666444 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - "Copy details" button on each route card — copies the route path, fee, and time as plain text to the clipboard (resolves #21). +- Loading state while routes are being calculated: short artificial delay + plus spinner, stylable ahead of Phase 2's real network calls (resolves #16). - Unit test for `availableCurrencies()` (resolves #27). - Component tests for `RouteList` covering the not-searched, empty, and populated states (resolves #25). diff --git a/src/App.jsx b/src/App.jsx index c750245..092a9b5 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -13,19 +13,25 @@ export default function App() { const [searched, setSearched] = useState(false) const [lastQuery, setLastQuery] = useState(null) const [engineError, setEngineError] = useState(null) + const [loading, setLoading] = useState(false) const currencies = availableCurrencies() - function handleSubmit({ fromCurrency, toCurrency, amount }) { + async function handleSubmit({ fromCurrency, toCurrency, amount }) { + if (loading) return setEngineError(null) + setSearched(false) + setLoading(true) try { + await new Promise((resolve) => setTimeout(resolve, 500)) const found = findRoutesCached({ fromCurrency, toCurrency, amount, anchors: mockAnchors }) setRoutes(found) setLastQuery({ fromCurrency, toCurrency, amount }) setSearched(true) } catch (err) { setEngineError(err.message) - setSearched(false) + } finally { + setLoading(false) } } @@ -51,7 +57,14 @@ export default function App() {

)} - + {loading ? ( +
+
+ ) : ( + + )}