PR with too many features #58

Merged
BobdaFett merged 56 commits from feat/admin-page into main 2026-02-10 14:31:49 +00:00
Showing only changes of commit 7ba22e5d24 - Show all commits
+18 -10
View File
@@ -75,8 +75,8 @@ pub fn MultiEntry(
#[prop()] #[prop()]
data_map: RwSignal<HashMap<String, ValueType>>, data_map: RwSignal<HashMap<String, ValueType>>,
/// The type and order of the inputs for each `Entry` component within this `MultiEntry` component. /// The type and order of the inputs for each `Entry` component within this `MultiEntry` component.
#[prop(optional)] #[prop(optional, into)]
schema: Vec<InputType>, schema: Signal<Vec<InputType>>,
) -> impl IntoView { ) -> impl IntoView {
// Make the values within the list reactive. Each of these values should be a ValueType::Map, // Make the values within the list reactive. Each of these values should be a ValueType::Map,
// so we can pass these directly to the application. // so we can pass these directly to the application.
@@ -85,9 +85,8 @@ pub fn MultiEntry(
.get_untracked() .get_untracked()
.get(&data_member) .get(&data_member)
.unwrap_or(&ValueType::List(None)) .unwrap_or(&ValueType::List(None))
.as_list() .as_list().ok().flatten()
.unwrap_or(Some(Vec::<ValueType>::new())) .unwrap_or(Vec::new())
.unwrap_or(Vec::new()),
); );
// This effect updates the data_map with any new values from the data_reactive list, every time // This effect updates the data_map with any new values from the data_reactive list, every time
@@ -103,13 +102,21 @@ pub fn MultiEntry(
let add_entry = move |_| data_reactive.update(|list| list.push(new_entry())); let add_entry = move |_| data_reactive.update(|list| list.push(new_entry()));
view! { view! {
<div class="flex flex-col flex-1 gap-2"> <div class="flex flex-col flex-1">
<div class="flex flex-col gap-2 p-2">
<span class="font-bold">{label}</span> <span class="font-bold">{label}</span>
<Show when=move || !description.get().is_empty()> <Show when=move || !description.get().is_empty()>
<span>{description}</span> <span>{description}</span>
</Show> </Show>
</div>
<div class="flex flex-col gap-2 p-2"> <div class="flex flex-col gap-2 p-2">
// Render the entries // Render the entries
<Show
when=move || !data_reactive.get().is_empty()
fallback=|| view! {
<div class="mx-auto">"You haven't added any entries yet."</div>
}
>
<For <For
each=move || data_reactive.get() each=move || data_reactive.get()
key=|entry| get_uuid_from_map(&entry.as_map().unwrap().unwrap()) // Entries MUST be given a unique ID. This is absolutely ridiculous. key=|entry| get_uuid_from_map(&entry.as_map().unwrap().unwrap()) // Entries MUST be given a unique ID. This is absolutely ridiculous.
@@ -134,11 +141,12 @@ pub fn MultiEntry(
view! { view! {
<Entry <Entry
data_map = map_signal data_map = map_signal
schema = schema.clone() schema=schema
/> />
} }
} }
/> />
</Show>
</div> </div>
<ActionButton on:click = add_entry>"Add entry"</ActionButton> <ActionButton on:click = add_entry>"Add entry"</ActionButton>
@@ -181,12 +189,12 @@ fn Entry(
data_map: RwSignal<HashMap<String, ValueType>>, data_map: RwSignal<HashMap<String, ValueType>>,
/// The schema of this entry. Should contain all information about what inputs to use and what /// The schema of this entry. Should contain all information about what inputs to use and what
/// data members those inputs modify. /// data members those inputs modify.
#[prop()] #[prop(into)]
schema: Vec<InputType>, schema: Signal<Vec<InputType>>,
) -> impl IntoView { ) -> impl IntoView {
view! { view! {
<div class="flex flex-col flex-1 p-2 rounded-sm transition-shadow shadow-sm hover:shadow-lg/30"> <div class="flex flex-col flex-1 p-2 rounded-sm transition-shadow shadow-sm hover:shadow-lg/30">
{schema.iter() {schema.get().iter()
.map(|input_type| { .map(|input_type| {
input_type.clone().into_view(data_map.clone()) input_type.clone().into_view(data_map.clone())
}).collect_view() }).collect_view()