Rewrite for dictionary indexer
This commit is contained in:
+6
-9
@@ -150,8 +150,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
|||||||
v = v[..v.len() - 2].to_string()
|
v = v[..v.len() - 2].to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
while v.contains(",,") {
|
while let Some(index) = v.find(",,") {
|
||||||
let index = v.find(",,").unwrap();
|
|
||||||
v.remove(index);
|
v.remove(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,14 +210,12 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
|||||||
SaveGroup => {
|
SaveGroup => {
|
||||||
let state = &mut self.state.lock().unwrap();
|
let state = &mut self.state.lock().unwrap();
|
||||||
let connection = &state.connection;
|
let connection = &state.connection;
|
||||||
let group = &mut state
|
let mut group = state
|
||||||
.word_groups
|
.word_groups[self.selected_group_index]
|
||||||
.get(self.selected_group_index)
|
|
||||||
.unwrap()
|
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
update_group(group, connection);
|
update_group(&mut group, connection);
|
||||||
state.word_groups[self.selected_group_index] = group.clone();
|
state.word_groups[self.selected_group_index] = group;
|
||||||
}
|
}
|
||||||
SelectGroup(i) => {
|
SelectGroup(i) => {
|
||||||
self.selected_group_index = i;
|
self.selected_group_index = i;
|
||||||
@@ -316,7 +313,7 @@ impl DictionaryState {
|
|||||||
fn save_word(&mut self, i: usize) {
|
fn save_word(&mut self, i: usize) {
|
||||||
let state = &mut self.state.lock().unwrap();
|
let state = &mut self.state.lock().unwrap();
|
||||||
let connection = &state.connection;
|
let connection = &state.connection;
|
||||||
let word = &mut state.dictionary.get(i).unwrap().clone();
|
let word = &mut state.dictionary[i].clone();
|
||||||
|
|
||||||
update_word(word, connection);
|
update_word(word, connection);
|
||||||
state.dictionary[i] = word.clone();
|
state.dictionary[i] = word.clone();
|
||||||
|
|||||||
+2
-3
@@ -517,8 +517,7 @@ impl ImportState {
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|name| (name.clone(), Vec::<usize>::with_capacity(1)))
|
.map(|name| (name.clone(), Vec::<usize>::with_capacity(1)))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
for key in group.mapping.keys() {
|
for (key, endpoint) in &group.mapping {
|
||||||
let endpoint = group.mapping.get(key).unwrap();
|
|
||||||
let property_index = group.fields.iter().position(|f| f == key).unwrap();
|
let property_index = group.fields.iter().position(|f| f == key).unwrap();
|
||||||
let group_index = result
|
let group_index = result
|
||||||
.iter()
|
.iter()
|
||||||
@@ -538,7 +537,7 @@ impl ImportState {
|
|||||||
) -> String {
|
) -> String {
|
||||||
let mut working_words = Vec::with_capacity(indices.len());
|
let mut working_words = Vec::with_capacity(indices.len());
|
||||||
for index in indices {
|
for index in indices {
|
||||||
let str = properties.get(*index).unwrap();
|
let str = &properties[*index];
|
||||||
if skip_empty && str.is_empty() {
|
if skip_empty && str.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -360,7 +360,7 @@ impl DeckData {
|
|||||||
let last_list: Vec<_> = settings
|
let last_list: Vec<_> = settings
|
||||||
.get_word_list(&state_locked)
|
.get_word_list(&state_locked)
|
||||||
.iter()
|
.iter()
|
||||||
.map(|w| state_locked.dictionary.get(*w).unwrap())
|
.map(|w| &state_locked.dictionary[*w])
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
let word_ids = last_list.iter().map(|l| l.id).collect::<Vec<Id>>();
|
let word_ids = last_list.iter().map(|l| l.id).collect::<Vec<Id>>();
|
||||||
|
|||||||
+1
-1
@@ -581,7 +581,7 @@ impl RepetitionsState {
|
|||||||
let words = &state.dictionary;
|
let words = &state.dictionary;
|
||||||
let stats = &mut indices
|
let stats = &mut indices
|
||||||
.map(|i| {
|
.map(|i| {
|
||||||
let word = words.get(i).unwrap();
|
let word = &words[i];
|
||||||
CardStatistics {
|
CardStatistics {
|
||||||
id: 0.into(),
|
id: 0.into(),
|
||||||
word_id: word.id,
|
word_id: word.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user