Skip to content

Commit

Permalink
refactor(settings): generic type signature for simpletextsetting
Browse files Browse the repository at this point in the history
  • Loading branch information
BrewingWeasel committed Nov 14, 2023
1 parent 51467fa commit b41deab
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
12 changes: 8 additions & 4 deletions src-ui/src/settings/shared_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
use leptos::*;

#[component]
pub fn SimpleTextSetting(
readsig: ReadSignal<String>,
writesig: WriteSignal<String>,
pub fn SimpleTextSetting<Read, Write>(
readsig: Read,
mut writesig: Write,
name: &'static str,
desc: &'static str,
) -> impl IntoView {
) -> impl IntoView
where
Read: Fn() -> String + 'static + Copy,
Write: FnMut(String) + 'static + Copy,
{
view! {
<div class="labeledinput">
<label for=name>{desc}</label>
Expand Down
43 changes: 19 additions & 24 deletions src-ui/src/settings/wordknowledge_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ pub fn WordKnowledgeList(
.update(move |templs| templs.push((next_templ_id, create_signal(new_template))));
next_templ_id += 1;
};
let each_template = move |(id, (rtempl, wtempl))| {
view! {
<div class="deck_templates">
<button
class="remove"
on:click=move |_| {
set_templates
.update(|templ| { templ.retain(|(templ_id, _)| templ_id != &id) });
}
>

"x"
</button>
<IndividualDeckRepresentation rtempl=rtempl wtempl=wtempl info=info/>
<hr/>
</div>
}
};
view! {
<div class="dicts">
<h2 class="dicts_title">Word Knowledge</h2>
Expand All @@ -39,30 +57,7 @@ pub fn WordKnowledgeList(
</button>
</div>
<div class="all_templates">
<For
each=templates
key=|templ| templ.0
children=move |(id, (rtempl, wtempl))| {
view! {
<div class="deck_templates">
<button
class="remove"
on:click=move |_| {
set_templates
.update(|templ| {
templ.retain(|(templ_id, _)| templ_id != &id)
});
}
>

"x"
</button>
<IndividualDeckRepresentation rtempl=rtempl wtempl=wtempl info=info/>
<hr/>
</div>
}
}
/>
<For each=templates key=|templ| templ.0 children=each_template/>

</div>
}
Expand Down

0 comments on commit b41deab

Please sign in to comment.