Skip to content

Commit

Permalink
feat: add note fields setting option
Browse files Browse the repository at this point in the history
  • Loading branch information
BrewingWeasel committed Oct 28, 2023
1 parent fa44891 commit 86019ae
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src-ui/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub fn SettingsChanger(settings: Resource<(), Settings>) -> impl IntoView {
let (model, set_model) = create_signal(old_settings.model);
let (deck, set_deck) = create_signal(old_settings.deck);
let (note, set_note) = create_signal(old_settings.note_type);
let (note_fields, set_note_fields) = create_signal(old_settings.note_fields);

let new_dicts = old_settings
.dicts
Expand All @@ -61,6 +62,8 @@ pub fn SettingsChanger(settings: Resource<(), Settings>) -> impl IntoView {
<SimpleTextSetting readsig=deck writesig=set_deck name="deck" desc="Anki Deck"/>
<br/>
<SimpleTextSetting readsig=note writesig=set_note name="note" desc="Note type"/>
<br/>
<SimpleTextAreaSetting readsig=note_fields writesig=set_note_fields name="notefield" desc="Note Fields"/>

<hr/>
<DictionaryList dicts=dicts set_dicts=set_dicts/>
Expand All @@ -75,6 +78,7 @@ pub fn SettingsChanger(settings: Resource<(), Settings>) -> impl IntoView {
updater.model = model();
updater.deck = deck();
updater.note_type = note();
updater.note_fields = note_fields();
updater.dicts = dicts().iter().map(|(_, (r, _))| r()).collect();
});
save_settings(settings().unwrap());
Expand Down Expand Up @@ -106,6 +110,28 @@ fn SimpleTextSetting(
}
}

#[component]
fn SimpleTextAreaSetting(
readsig: ReadSignal<String>,
writesig: WriteSignal<String>,
name: &'static str,
desc: &'static str,
) -> impl IntoView {
view! {
<div class="labeledinput">
<label for=name>{desc}</label>
<textarea
id=name
type="text"
on:input=move |ev| {
writesig(event_target_value(&ev));
}

prop:value=readsig
/></div>
}
}

#[component]
fn DictionaryList(dicts: ReadSignal<DictList>, set_dicts: WriteSignal<DictList>) -> impl IntoView {
let mut next_dict_id = dicts().len();
Expand Down
7 changes: 6 additions & 1 deletion src-ui/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ hr {
color: #908caa;
}

.settings input {
.settings input, textarea {
outline: none;
border: none;
display: block;
Expand All @@ -31,6 +31,11 @@ hr {
color: #e0def4;
}

.settings textarea {
line-height: 1em;
height: 4em;
}

.dicts_title {
display: inline-block;
margin: 5px;
Expand Down

0 comments on commit 86019ae

Please sign in to comment.