feat(home): replace demo with entity count dashboard

Home page now shows one clickable summary card per entity type
(Networks, Hosts, Applications). Each card displays the total count
fetched from the database via a single get_summary() server function,
then navigates to the corresponding page on click.

Counts are pre-rendered server-side via <Suspense> so the page is
useful even before the WASM bundle loads.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-15 22:49:25 +02:00
parent 589aab7e3d
commit 3ee39b96bb
3 changed files with 103 additions and 63 deletions

View File

@@ -17,3 +17,4 @@
pub mod applications;
pub mod hosts;
pub mod networks;
pub mod summary;

45
src/api/summary.rs Normal file
View File

@@ -0,0 +1,45 @@
// api/summary.rs — Dashboard summary server function
//
// Returns the count of each main entity in a single server round-trip.
// The home page uses this to display a quick-glance dashboard without
// loading the full list of each entity.
use leptos::prelude::*;
use serde::{Deserialize, Serialize};
// Counts for every top-level entity shown on the dashboard.
// Add a field here when a new entity type is introduced.
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct Summary {
pub network_count: i64,
pub host_count: i64,
pub application_count: i64,
}
#[server]
pub async fn get_summary() -> Result<Summary, ServerFnError> {
use sqlx::AnyPool;
use leptos::prelude::use_context;
let pool = use_context::<AnyPool>()
.ok_or_else(|| ServerFnError::new("Database pool not found in context"))?;
// Three lightweight COUNT queries — no full table scans on the payload side.
// sqlx returns COUNT(*) as i64 for both SQLite and PostgreSQL.
let network_count: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM networks")
.fetch_one(&pool)
.await
.map_err(|e| ServerFnError::new(e.to_string()))?;
let host_count: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM hosts")
.fetch_one(&pool)
.await
.map_err(|e| ServerFnError::new(e.to_string()))?;
let application_count: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM applications")
.fetch_one(&pool)
.await
.map_err(|e| ServerFnError::new(e.to_string()))?;
Ok(Summary { network_count, host_count, application_count })
}