Partial AppState rewrite
This commit is contained in:
1 parent
29a90d48d9
commit
0c4aec3dc0
13 files changed
+75
-49
No files matched your search
+6
-9
@@ -9,15 +9,13 @@ use crate::data_provider::card_states::{load_stats_of_deck, update_stat_score};
|
||||
use crate::data_provider::history::push_note;
|
||||
use crate::notification::{MaybeError, NotificationData};
|
||||
use chrono::Utc;
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DeckData {
|
||||
pub(crate) words: Vec<WordData>,
|
||||
pub(crate) set: Vec<CardState>,
|
||||
current_word_index: Option<usize>,
|
||||
state: Arc<Mutex<AppState>>,
|
||||
state: AppState,
|
||||
order_module: OrderModule,
|
||||
open_mode: OrderMode,
|
||||
settings: DeckSettings,
|
||||
@@ -25,21 +23,20 @@ pub struct DeckData {
|
||||
impl DeckData {
|
||||
pub fn new(
|
||||
settings: &DeckSettings,
|
||||
state: Arc<Mutex<AppState>>,
|
||||
state: 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.connection.read())?;
|
||||
let words = stats
|
||||
.iter()
|
||||
.map(|stat| {
|
||||
state_locked
|
||||
state
|
||||
.dictionary
|
||||
.binary_search_by_key(&stat.word_id, |w| w.id)
|
||||
.expect("No word found in dictionary")
|
||||
})
|
||||
.map(|index| &state_locked.dictionary[index])
|
||||
.map(|index| &state.dictionary[index])
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
@@ -117,7 +114,7 @@ impl DeckData {
|
||||
OrderMode::FullRandom => RandomSRS(RandomSRSModule::new()),
|
||||
}
|
||||
}
|
||||
update_stat_score(word, &self.state.lock().connection)?;
|
||||
update_stat_score(word, &self.state.connection.read())?;
|
||||
let _ = push_note(
|
||||
self.settings.id,
|
||||
HistoryItem {
|
||||
|
||||
Reference in new issue
Block a user