summary refs log tree commit diff stats
path: root/src/components/select_placeholder.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-10-23 01:36:39 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-10-23 01:36:39 +0200
commit7bff22756beec82b4a1470e2d325b706dc56e5f2 (patch)
tree1566965125cfd5fbd73d654e9ee6ca8256301411 /src/components/select_placeholder.rs
parentfeat(form): Re-write the form macro as a proc macro (diff)
downloadweb-client-7bff22756beec82b4a1470e2d325b706dc56e5f2.zip
feat(buy): Provide basic buy interface
Diffstat (limited to 'src/components/select_placeholder.rs')
-rw-r--r--src/components/select_placeholder.rs40
1 files changed, 19 insertions, 21 deletions
diff --git a/src/components/select_placeholder.rs b/src/components/select_placeholder.rs
index 947931c..2e0f783 100644
--- a/src/components/select_placeholder.rs
+++ b/src/components/select_placeholder.rs
@@ -1,37 +1,24 @@
 use leptos::{
-    IntoView,
-    attr::{AttributeValue, IntoAttributeValue},
-    component,
+    IntoView, component,
+    error::Error,
     html::Select,
     prelude::{
         ClassAttribute, CollectView, ElementChild, GlobalAttributes, NodeRef, NodeRefAttribute,
     },
+    server::LocalResource,
     view,
 };
 
-use crate::components::get_id;
+use crate::components::{async_fetch::AsyncFetch, get_id};
 
 #[component]
-pub fn SelectPlaceholder<T>(
+pub fn SelectPlaceholder(
     label: &'static str,
     node_ref: NodeRef<Select>,
-    options: Vec<(&'static str, T)>,
-) -> impl IntoView
-where
-    T: IntoAttributeValue,
-    <T as IntoAttributeValue>::Output: Send + AttributeValue,
-{
+    options: LocalResource<Result<Vec<(String, String)>, Error>>,
+) -> impl IntoView {
     let id = get_id();
 
-    let options = options
-        .into_iter()
-        .map(|(label, value)| {
-            view! {
-                <option value=value>{label}</option>
-            }
-        })
-        .collect_view();
-
     view! {
         <div class="relative h-14">
             <select
@@ -54,7 +41,18 @@ where
                 "
                 node_ref=node_ref
             >
-                {options}
+                {move || AsyncFetch! {
+                    @map_error_in_producer
+                    from_resource = options
+                    producer = |options| {
+                        options
+                            .into_iter()
+                            .map(|(label, value)| {
+                                view! { <option value=value>{label}</option> }
+                            })
+                            .collect_view()
+                    }
+                }}
             </select>
 
             // TODO: Reference `var(--tw-border-2)` instead of the `2 px` <2025-10-01>