Technical Task 2: Error & loading state integration across all admin pages #902
Merged
Conversation
Signed-off-by: mankiratt <smankirat526@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.
Technical Task 2: Error & Loading State Integration Across All HMI Admin Pages
Overview
This pull request introduces
admin-page-state.js, a centralised reusable utility for managing loading and error states across all HMI admin dashboard pages, and integrates it across every page in the admin panel.New File —
admin-page-state.jsCreated a shared utility using the IIFE pattern that exposes a factory function
createAdminPageState(). Each page calls this once and gets back a clean API:showLoading()hideLoading()showError(message)hideError()resetPageState()The dismiss button is automatically wired on creation — no manual listener needed on any page.
UI Components
Two polished UI components are included on every page:
Error Banner — bold red (
#e03131) with left accent border, shadow, and fade-in animation. Displays a user-facing message when any API call fails.Loading Spinner — Echo brand green (
#2F6E4F / #26583f) with matching left accent border and shadow. Displays while any fetch is in-flight.Both components use custom CSS added to
styles.min.cssand are consistent across all pages.Pages Integrated
Live API pages — full error and loading handling wired
dashboard.html/cumulativeDonationsadmin-request.html/api/requests,/api/requests/:id,/api/updateConservationStatus/:animaldonations.html/donationsadmin-nodes.html/iot/nodesalerts.html/sensors/alertsscript.jsandcharts.jsreboot.html/sensors/:id/reboot,/sensors/reboots/recentsensor_health/settings.html/sensors/__default__/settingsStatic/dummy data pages — ready for future API integration
resetPageState()is called on load so banners are hidden immediately. When these pages are connected to real APIs in future, error handling can be wired with no HTML changes needed.sensor-health.htmlnotifications.htmlprofile.htmlprojects.htmlhmi-data-insights.htmlfeedback.htmladd-project.htmlError Handling Coverage
For all live API pages, the following error types are handled and surface a user-facing message via the error banner:
AbortControllerfires after per-page timeoutTypeErrorcaught incatchblockres.okchecked before parsingres.json()insidetry/catchdonations.htmlFiles Changed
New
admin/js/admin-page-state.jsModified
admin/css/styles.min.css— added banner and spinner stylesadmin/dashboard.htmladmin/admin-request.htmladmin/donations.htmladmin/admin-nodes.htmladmin/sensor-health.htmladmin/notifications.htmladmin/profile.htmladmin/projects.htmladmin/hmi-data-insights.htmladmin/feedback.htmladmin/template.htmladmin/sensor_health/alerts.htmladmin/sensor_health/reboot.htmladmin/sensor_health/settings.htmladmin/sensor_health/add-project.htmladmin/sensor_health/script.jsadmin/sensor_health/charts.js