More fixes for dictionary
This commit is contained in:
1 parent
92b019b072
commit
7f9aa11d6e
1 file changed
+29
-8
+29
-8
@@ -116,6 +116,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||
let mut word = WordData::new();
|
||||
word.group_id = self.selected_group.id;
|
||||
dictionary.create(word);
|
||||
self.displayed_words_query.load(&dictionary);
|
||||
}
|
||||
|
||||
SetKey(handle, v) => {
|
||||
@@ -158,6 +159,8 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||
if let Err(err) = dictionary.delete(i) {
|
||||
return push_error_task!(err);
|
||||
}
|
||||
|
||||
self.displayed_words_query.load(&dictionary);
|
||||
}
|
||||
Include(i, b) => {
|
||||
if b {
|
||||
@@ -188,6 +191,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||
id: 0.into(),
|
||||
name: format!("Группа слов {}", random_range(100..1000)),
|
||||
});
|
||||
self.groups_query.load(&groups);
|
||||
}
|
||||
EditGroup(new) => {
|
||||
let mut groups = self.state.word_groups.write();
|
||||
@@ -198,15 +202,21 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||
}
|
||||
}
|
||||
SaveGroup => {
|
||||
let mut groups = self.state.word_groups.write();
|
||||
{
|
||||
let mut groups = self.state.word_groups.write();
|
||||
|
||||
if let Err(err) = groups.save(&mut self.selected_group) {
|
||||
return push_error_task!(err);
|
||||
if let Err(err) = groups.save(&mut self.selected_group) {
|
||||
return push_error_task!(err);
|
||||
}
|
||||
|
||||
self.groups_query.load(&groups);
|
||||
}
|
||||
|
||||
self.setup_words_query();
|
||||
}
|
||||
SelectGroup(i) => {
|
||||
self.selected_group = i;
|
||||
self.setup_words_query(i.id);
|
||||
self.setup_words_query();
|
||||
self.update_words_include(i.id)
|
||||
}
|
||||
DeleteGroup => {
|
||||
@@ -214,9 +224,10 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||
return Task::none();
|
||||
}
|
||||
{
|
||||
let mut groups = self.state.word_groups.write();
|
||||
let delete_group = self.selected_group;
|
||||
self.selected_group = groups.handle_by_id(Id(1));
|
||||
self.selected_group = EntityHandle::from_id(1.into());
|
||||
self.setup_words_query();
|
||||
let mut groups = self.state.word_groups.write();
|
||||
|
||||
if let Err(err) = groups.delete(delete_group) {
|
||||
return push_error_task!(err);
|
||||
@@ -225,6 +236,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||
if let Err(err) = self.state.dictionary.write().reload() {
|
||||
return push_error_task!(err);
|
||||
}
|
||||
self.groups_query.load(&groups);
|
||||
}
|
||||
|
||||
self.update_tags()
|
||||
@@ -242,7 +254,11 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
||||
|
||||
let mut dictionary = self.state.dictionary.write();
|
||||
|
||||
let reload_query = handle.real() == false;
|
||||
let _ = dictionary.save(&mut handle);
|
||||
if reload_query {
|
||||
self.displayed_words_query.load(&dictionary);
|
||||
}
|
||||
return Task::none();
|
||||
}
|
||||
}
|
||||
@@ -307,8 +323,13 @@ impl DictionaryState {
|
||||
.query_par(Arc::new(|word| word.group_id == Id(1)));
|
||||
}
|
||||
|
||||
fn setup_words_query(&mut self, id: Id) {
|
||||
self.displayed_words_query = self.state.dictionary.read().query_par(Arc::new(move |word| word.group_id == id));
|
||||
fn setup_words_query(&mut self) {
|
||||
let id = self.selected_group.id;
|
||||
self.displayed_words_query = self
|
||||
.state
|
||||
.dictionary
|
||||
.read()
|
||||
.query_par(Arc::new(move |word| word.group_id == id));
|
||||
}
|
||||
|
||||
fn launch_auto_save_offset(&mut self, handle: EntityHandle<WordData>) -> Task<RootMessage> {
|
||||
|
||||
Reference in new issue
Block a user