feat: reorganize and add single selection to chip lists

This commit is contained in:
alphafetus committed 2026-01-07 00:22:46 -05:00
1 parent 105e6b3e55
commit 8d9faf126d
6 files changed
+214 -61

No files matched your search

+44 -4
View File
@@ -1,9 +1,13 @@
use std::collections::HashMap;
#[cfg(feature = "ssr")]
use crate::pages::utils::server_utils::create_dynamo_client;
#[cfg(feature = "ssr")]
use aws_sdk_dynamodb::error::ProvideErrorMetadata;
#[cfg(feature = "ssr")]
use leptos::logging::log;
use crate::common::{
ComparisonData, ComparisonType, MapListComparison, NumberComparison, NumberListComparison,
TextComparison, TextListComparison, ValueType,
@@ -314,8 +318,6 @@ fn make_comp_list() -> Vec<ComparisonData> {
#[server(CreateTestComparisons, endpoint = "/comparisons/create-test")]
pub async fn create_test_comparisons() -> Result<(), ServerFnError> {
use leptos::logging::log;
let client = create_dynamo_client().await;
log!("Creating test comparisons");
@@ -340,8 +342,6 @@ pub async fn create_test_comparisons() -> Result<(), ServerFnError> {
#[server]
pub async fn get_comparison_info() -> Result<Vec<ComparisonData>, ServerFnError> {
use leptos::logging::log;
let client = create_dynamo_client().await;
log!("Getting all comparisons from the database");
@@ -368,3 +368,43 @@ pub async fn get_comparison_info() -> Result<Vec<ComparisonData>, ServerFnError>
}
}
}
#[server]
pub async fn get_comparisons_categorized() -> Result<HashMap<String, Vec<ComparisonData>>, ServerFnError> {
let client = create_dynamo_client().await;
log!("Getting all comparisons from the database, by category.");
match client
.scan()
.table_name("leptos-comparison-test")
.send()
.await
{
Ok(output) => {
if let Some(items) = output.items {
log!("Found comparisons, categorizing.");
let items: Vec<ComparisonData> = serde_dynamo::from_items(items)?;
let categorized = items.iter().fold(
HashMap::<String, Vec<ComparisonData>>::new(), |mut map, comp| {
// Load each comparison into a map, then return that map.
map.entry(comp.category.clone())
.and_modify(|vec| vec.push(comp.clone()))
.or_insert(vec![comp.clone()]);
map
}
);
Ok(categorized)
} else {
Err(ServerFnError::new("Couldn't find any comparisons."))
}
}
Err(err) => {
let msg = err.message().unwrap_or("An unknown error occurred");
Err(ServerFnError::new(msg))
}
}
}