Repetitions remake #1
No files matched your search
@@ -86,8 +86,15 @@ pub fn delete_stats(stat: &[CardStatistics], connection: &Connection) {
|
|||||||
if stat.is_empty() {
|
if stat.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let ids = stat.iter().map(|s| s.id.into()).collect::<Vec<String>>().join(", ");
|
let ids = stat
|
||||||
|
.iter()
|
||||||
|
.map(|s| s.id.into())
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join(", ");
|
||||||
connection
|
connection
|
||||||
.execute(format!("DELETE FROM card_stats WHERE id in {ids}").as_str(), ())
|
.execute(
|
||||||
|
format!("DELETE FROM card_stats WHERE id in {ids}").as_str(),
|
||||||
|
(),
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,7 @@ pub async fn get_voice(text: &str) -> Result<BufReader<File>, ()> {
|
|||||||
let mut path = app_data_dir();
|
let mut path = app_data_dir();
|
||||||
path.push("voice");
|
path.push("voice");
|
||||||
if !path.exists() {
|
if !path.exists() {
|
||||||
std::fs::create_dir(path.clone()).map_err(|_|())?;
|
std::fs::create_dir(path.clone()).map_err(|_| ())?;
|
||||||
}
|
}
|
||||||
let hash = format!("{}.wav", hex::encode(Sha256::digest(text.as_bytes())));
|
let hash = format!("{}.wav", hex::encode(Sha256::digest(text.as_bytes())));
|
||||||
path.push(hash);
|
path.push(hash);
|
||||||
@@ -20,19 +20,21 @@ pub async fn get_voice(text: &str) -> Result<BufReader<File>, ()> {
|
|||||||
.send()
|
.send()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let query = query.map_err(|_|())?.text().await.map_err(|_|())?;
|
let query = query.map_err(|_| ())?.text().await.map_err(|_| ())?;
|
||||||
// Synthesis
|
// Synthesis
|
||||||
let audio = client
|
let audio = client
|
||||||
.post(format!("{engine_url}/synthesis?speaker=11"))
|
.post(format!("{engine_url}/synthesis?speaker=11"))
|
||||||
.header("Content-Type", "application/json")
|
.header("Content-Type", "application/json")
|
||||||
.body(query)
|
.body(query)
|
||||||
.send()
|
.send()
|
||||||
.await.map_err(|_|())?
|
.await
|
||||||
|
.map_err(|_| ())?
|
||||||
.bytes()
|
.bytes()
|
||||||
.await.map_err(|_|())?;
|
.await
|
||||||
|
.map_err(|_| ())?;
|
||||||
|
|
||||||
tokio::fs::write(&path, &audio).await.map_err(|_|())?;
|
tokio::fs::write(&path, &audio).await.map_err(|_| ())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(BufReader::new(File::open(path).map_err(|_|())?))
|
Ok(BufReader::new(File::open(path).map_err(|_| ())?))
|
||||||
}
|
}
|
||||||
+12
-1
@@ -364,7 +364,17 @@ impl DeckData {
|
|||||||
let state_locked = state.lock();
|
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()).map(|index| &state_locked.dictionary[index]).cloned().collect();
|
let words = stats
|
||||||
|
.iter()
|
||||||
|
.map(|stat| {
|
||||||
|
state_locked
|
||||||
|
.dictionary
|
||||||
|
.binary_search_by_key(&stat.word_id, |w| w.id)
|
||||||
|
.unwrap()
|
||||||
|
})
|
||||||
|
.map(|index| &state_locked.dictionary[index])
|
||||||
|
.cloned()
|
||||||
|
.collect();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
set: stats,
|
set: stats,
|
||||||
@@ -381,6 +391,7 @@ impl DeckData {
|
|||||||
settings: settings.clone(),
|
settings: settings.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next(&mut self) -> (WordData, CardStatistics) {
|
pub fn next(&mut self) -> (WordData, CardStatistics) {
|
||||||
let index = match self.order_module.clone() {
|
let index = match self.order_module.clone() {
|
||||||
OrderModule::SemiRandomSRS(mut module) => {
|
OrderModule::SemiRandomSRS(mut module) => {
|
||||||
|
|||||||
+2
-2
@@ -9,8 +9,8 @@ use chrono::Local;
|
|||||||
use iced::alignment::Horizontal::Center;
|
use iced::alignment::Horizontal::Center;
|
||||||
use iced::keyboard::key::Physical::Code;
|
use iced::keyboard::key::Physical::Code;
|
||||||
use iced::widget::text::Style;
|
use iced::widget::text::Style;
|
||||||
use iced::widget::{button, column, container, row, rule, space, text, tooltip, Column};
|
use iced::widget::{Column, button, column, container, row, rule, space, text, tooltip};
|
||||||
use iced::{alignment, keyboard, Element, Fill, Task, Theme};
|
use iced::{Element, Fill, Task, Theme, alignment, keyboard};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use rodio::MixerDeviceSink;
|
use rodio::MixerDeviceSink;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::AppState;
|
||||||
use crate::data_provider::card_sets::{delete_set, update_deck};
|
use crate::data_provider::card_sets::{delete_set, update_deck};
|
||||||
use crate::data_provider::card_stats::{delete_stats, load_stats_of_deck};
|
use crate::data_provider::card_stats::{delete_stats, load_stats_of_deck};
|
||||||
use crate::lang::DeckSettings;
|
use crate::lang::DeckSettings;
|
||||||
@@ -5,13 +6,12 @@ use crate::navigation::Page::PreviousPage;
|
|||||||
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
use crate::navigation::{NavigatedPage, Page, RootMessage};
|
||||||
use crate::repetition_settings::RepetitionSettingsMessage::*;
|
use crate::repetition_settings::RepetitionSettingsMessage::*;
|
||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
use crate::AppState;
|
|
||||||
use iced::widget::button::danger;
|
use iced::widget::button::danger;
|
||||||
use iced::widget::text_input::Catalog;
|
use iced::widget::text_input::Catalog;
|
||||||
use iced::widget::{button, column, row, scrollable, space, text, text_input};
|
use iced::widget::{button, column, row, scrollable, space, text, text_input};
|
||||||
use iced::{Element, Task};
|
use iced::{Element, Task};
|
||||||
use iced_core::Length::Fill;
|
use iced_core::Length::Fill;
|
||||||
use iced_core::{color, Padding, Theme};
|
use iced_core::{Padding, Theme, color};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|||||||
+2
-2
@@ -88,7 +88,8 @@ impl NavigatedPage<RepetitionsMessage> for RepetitionsState {
|
|||||||
self.decks.remove(index);
|
self.decks.remove(index);
|
||||||
self.clear_selection();
|
self.clear_selection();
|
||||||
} else {
|
} else {
|
||||||
self.decks[self.selected_deck_index.unwrap()].general_settings = state.decks[index].clone();
|
self.decks[self.selected_deck_index.unwrap()].general_settings =
|
||||||
|
state.decks[index].clone();
|
||||||
drop(state);
|
drop(state);
|
||||||
self.fill_deck_word_indices();
|
self.fill_deck_word_indices();
|
||||||
}
|
}
|
||||||
@@ -625,7 +626,6 @@ impl RepetitionsState {
|
|||||||
deck.existing_words_indices = Some(added);
|
deck.existing_words_indices = Some(added);
|
||||||
deck.available_words_indices = Some(total);
|
deck.available_words_indices = Some(total);
|
||||||
self.decks[self.selected_deck_index.unwrap()] = deck;
|
self.decks[self.selected_deck_index.unwrap()] = deck;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|||||||
Reference in new issue
Block a user