feat(frontend): Task 7 - shared UI utilities, loading states, retry handling#906
Merged
Conversation
…andling - Extended showToast with typed success/error/warning/info notifications - Added withRetry for automatic retry with user-facing toast feedback - Added getApiErrorMessage for consistent user-safe error strings - Added showPageBanner/hidePageBanner for persistent notices - Added confirmDialog, guardRequest, debounce, guardFormSubmit helpers - Removed duplicate getApiErrorMessage from routes.js - Fixed session guard logic in middleware/index.js - Fixed map.routes.js port and removed next() after res.send() crashes - Fixed user.routes.js headers-already-sent crash - Fixed server.js proxyToApi crash on connection failure
Signed-off-by: Vamshi-Gollapelly <vamshigollapelly225@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
This update continues the frontend reliability work from Sprint 2
and extends it to more parts of the app.
What changed and why
HMI-utils.js
Added several reusable helper functions that other parts of the
frontend can now use:
showToast() now supports four types: success, error, warning,
and info. Each one has a different colour so users can quickly
tell what kind of message it is. Toasts also have a close button
and auto-dismiss after a few seconds.
withRetry() wraps any API call and automatically tries again if
it fails. It shows a warning toast between each attempt so the
user knows what is happening.
getApiErrorMessage() takes an error from a failed request and
returns a short, plain-English message instead of showing a
raw error or stack trace to the user.
showPageBanner() and hidePageBanner() show a coloured bar at the
top of the page for things that need to stay visible, like a
critical alert. Unlike toasts, these do not disappear on their own.
confirmDialog() is a simple yes/no popup that works like
window.confirm() but does not block the browser. It returns
true or false depending on what the user clicks.
guardRequest() stops the same request from being sent twice if
the user clicks a button more than once before the first one
finishes.
debounce() stops a function from firing on every single keystroke,
which is useful for search inputs.
guardFormSubmit() disables the submit button while a form is
being sent, shows a loading label, and then shows a success or
error toast when done.
routes.js
Removed the copy from routes.js so there is only one version.
again on a network failure before showing an error to the user.
map.js
the shared helpers in HMI-utils.js. The file now just imports
and uses the shared ones instead.
index.html
function that did the same thing as showToast(). Removed the
custom one and replaced all of those calls with showToast().
is consistent across the whole app.
actually available to the rest of the page.
middleware/index.js
like /map that should be public were requiring a login, and some
protected routes were being skipped entirely. Fixed this so
public and protected routes are clearly separated.
Bug fixes
which caused the server to crash. Removed those calls.
Added a check so it handles that gracefully instead.
What it looks like