PR with too many features #58
@@ -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,42 +102,51 @@ 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">
|
||||||
<span class="font-bold">{label}</span>
|
<div class="flex flex-col gap-2 p-2">
|
||||||
<Show when=move || !description.get().is_empty()>
|
<span class="font-bold">{label}</span>
|
||||||
<span>{description}</span>
|
<Show when=move || !description.get().is_empty()>
|
||||||
</Show>
|
<span>{description}</span>
|
||||||
|
</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
|
||||||
<For
|
<Show
|
||||||
each=move || data_reactive.get()
|
when=move || !data_reactive.get().is_empty()
|
||||||
key=|entry| get_uuid_from_map(&entry.as_map().unwrap().unwrap()) // Entries MUST be given a unique ID. This is absolutely ridiculous.
|
fallback=|| view! {
|
||||||
children=move |mut entry_map| {
|
<div class="mx-auto">"You haven't added any entries yet."</div>
|
||||||
// The map_signal is the map used for the internal element. This signal will
|
|
||||||
// keep track of the individual entry's data, and whenever it is changed,
|
|
||||||
// the parent data_map will also be updated to reflect these changes.
|
|
||||||
let map_signal = RwSignal::new(entry_map
|
|
||||||
.as_map()
|
|
||||||
.unwrap_or_default()
|
|
||||||
.unwrap_or_default());
|
|
||||||
|
|
||||||
// This effect updates the data_reactive list with the map_signal values, every
|
|
||||||
// time the map_signal is changed.
|
|
||||||
Effect::new(move |_| {
|
|
||||||
let child_map = map_signal.get(); // HashMap
|
|
||||||
data_reactive.update(|mut list| {
|
|
||||||
update_entry_list(&mut list, &child_map);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
view! {
|
|
||||||
<Entry
|
|
||||||
data_map = map_signal
|
|
||||||
schema = schema.clone()
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/>
|
>
|
||||||
|
<For
|
||||||
|
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.
|
||||||
|
children=move |mut entry_map| {
|
||||||
|
// The map_signal is the map used for the internal element. This signal will
|
||||||
|
// keep track of the individual entry's data, and whenever it is changed,
|
||||||
|
// the parent data_map will also be updated to reflect these changes.
|
||||||
|
let map_signal = RwSignal::new(entry_map
|
||||||
|
.as_map()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.unwrap_or_default());
|
||||||
|
|
||||||
|
// This effect updates the data_reactive list with the map_signal values, every
|
||||||
|
// time the map_signal is changed.
|
||||||
|
Effect::new(move |_| {
|
||||||
|
let child_map = map_signal.get(); // HashMap
|
||||||
|
data_reactive.update(|mut list| {
|
||||||
|
update_entry_list(&mut list, &child_map);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
view! {
|
||||||
|
<Entry
|
||||||
|
data_map = map_signal
|
||||||
|
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()
|
||||||
|
|||||||
Reference in new issue
Block a user