Rewrite fully second db table into result
This commit is contained in:
1 parent
06bf9138c0
commit
8841a51897
11 files changed
+127
-74
No files matched your search
+10
-9
@@ -6,7 +6,7 @@ use crate::data_provider::history::push_note;
|
||||
use chrono::Utc;
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::notification::NotificationData;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DeckData {
|
||||
@@ -18,24 +18,24 @@ pub struct DeckData {
|
||||
settings: DeckSettings,
|
||||
}
|
||||
impl DeckData {
|
||||
pub fn new(settings: &DeckSettings, state: Arc<Mutex<AppState>>) -> Self {
|
||||
pub fn new(settings: &DeckSettings, state: Arc<Mutex<AppState>>) -> Result<Self, NotificationData> {
|
||||
let state_for = state.clone();
|
||||
let state_locked = state.lock();
|
||||
|
||||
let stats = load_stats_of_deck(settings, &state_locked.connection);
|
||||
let stats = load_stats_of_deck(settings, &state_locked.connection)?;
|
||||
let words = stats
|
||||
.iter()
|
||||
.map(|stat| {
|
||||
state_locked
|
||||
.dictionary
|
||||
.binary_search_by_key(&stat.word_id, |w| w.id)
|
||||
.unwrap()
|
||||
.expect("No word found in dictionary")
|
||||
})
|
||||
.map(|index| &state_locked.dictionary[index])
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
Self {
|
||||
Ok(Self {
|
||||
set: stats,
|
||||
words,
|
||||
current_word_index: None,
|
||||
@@ -48,7 +48,7 @@ impl DeckData {
|
||||
OrderMode::FullRandom => OrderModule::RandomSRS(RandomSRSModule::new()),
|
||||
},
|
||||
settings: settings.clone(),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn next(&mut self) -> (WordData, CardStatistics) {
|
||||
@@ -82,9 +82,9 @@ impl DeckData {
|
||||
self.current_word_index = Some(index);
|
||||
(self.words[index].clone(), self.set[index].clone())
|
||||
}
|
||||
pub fn open(&mut self, status: WordOpenMode) {
|
||||
pub fn open(&mut self, status: WordOpenMode) -> Result<(), NotificationData> {
|
||||
if self.current_word_index.is_none() {
|
||||
return;
|
||||
return Ok(());
|
||||
}
|
||||
let index = self.current_word_index.unwrap();
|
||||
|
||||
@@ -104,7 +104,7 @@ impl DeckData {
|
||||
module.open(status, index, word);
|
||||
}
|
||||
}
|
||||
update_stat_score(word, &self.state.lock().connection);
|
||||
update_stat_score(word, &self.state.lock().connection)?;
|
||||
let _ = push_note(
|
||||
self.settings.id,
|
||||
HistoryItem {
|
||||
@@ -115,6 +115,7 @@ impl DeckData {
|
||||
after: new_score,
|
||||
},
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
pub fn len(&self) -> usize {
|
||||
self.set.len()
|
||||
|
||||
Reference in new issue
Block a user