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