Use is_valid for Id
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use crate::lang::{DeckSettings, OrderMode, INVALID_ID};
|
use crate::lang::{DeckSettings, INVALID_ID, OrderMode};
|
||||||
|
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ pub fn add_set(set: &mut DeckSettings, connection: &Connection) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_deck(set: &mut DeckSettings, connection: &Connection) {
|
pub fn update_deck(set: &mut DeckSettings, connection: &Connection) {
|
||||||
if set.id == INVALID_ID {
|
if !set.id.is_valid() {
|
||||||
add_set(set, connection);
|
add_set(set, connection);
|
||||||
} else {
|
} else {
|
||||||
connection
|
connection
|
||||||
@@ -66,7 +66,7 @@ pub fn update_deck(set: &mut DeckSettings, connection: &Connection) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_set(set: &DeckSettings, connection: &Connection) {
|
pub fn delete_set(set: &DeckSettings, connection: &Connection) {
|
||||||
if set.id == INVALID_ID {
|
if !set.id.is_valid() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
connection
|
connection
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::lang::{DeckSettings, CardStatistics, INVALID_ID};
|
use crate::lang::{CardStatistics, DeckSettings, INVALID_ID};
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ pub fn update_stat_score(stat: &CardStatistics, connection: &Connection) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_stat(stat: &CardStatistics, connection: &Connection) {
|
pub fn delete_stat(stat: &CardStatistics, connection: &Connection) {
|
||||||
if stat.id == INVALID_ID {
|
if !stat.id.is_valid() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
connection
|
connection
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
use hashbrown::HashMap;
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use hashbrown::HashMap;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ImportData(pub(crate) Vec<ImportGroup>);
|
pub struct ImportData(pub(crate) Vec<ImportGroup>);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::lang::{WordData, WordGroup, INVALID_ID};
|
use crate::lang::{INVALID_ID, WordData, WordGroup};
|
||||||
use rusqlite::{Connection, params};
|
use rusqlite::{Connection, params};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ pub fn add_words(words: &mut [WordData], connection: &mut Connection) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_word(word: &mut WordData, connection: &Connection) {
|
pub fn update_word(word: &mut WordData, connection: &Connection) {
|
||||||
if word.id == INVALID_ID {
|
if !word.id.is_valid() {
|
||||||
add_word(word, connection);
|
add_word(word, connection);
|
||||||
} else {
|
} else {
|
||||||
connection
|
connection
|
||||||
@@ -86,7 +86,7 @@ pub fn update_word(word: &mut WordData, connection: &Connection) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_word(word: &WordData, connection: &Connection) {
|
pub fn delete_word(word: &WordData, connection: &Connection) {
|
||||||
if word.id == INVALID_ID {
|
if !word.id.is_valid() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
connection
|
connection
|
||||||
@@ -160,7 +160,7 @@ pub fn add_group(group: &mut WordGroup, connection: &Connection) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_group(group: &mut WordGroup, connection: &Connection) {
|
pub fn update_group(group: &mut WordGroup, connection: &Connection) {
|
||||||
if group.id == INVALID_ID {
|
if !group.id.is_valid() {
|
||||||
add_group(group, connection);
|
add_group(group, connection);
|
||||||
} else {
|
} else {
|
||||||
connection
|
connection
|
||||||
@@ -176,7 +176,7 @@ pub fn update_group(group: &mut WordGroup, connection: &Connection) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_group(group: &WordGroup, connection: &Connection) {
|
pub fn delete_group(group: &WordGroup, connection: &Connection) {
|
||||||
if group.id == INVALID_ID {
|
if !group.id.is_valid() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
connection
|
connection
|
||||||
|
|||||||
+4
-4
@@ -2,13 +2,14 @@ use crate::data_provider::words::{delete_group, delete_word, update_group, updat
|
|||||||
use crate::dictionary::DictionaryMessage::*;
|
use crate::dictionary::DictionaryMessage::*;
|
||||||
use crate::dictionary_test::DictionaryQuizState;
|
use crate::dictionary_test::DictionaryQuizState;
|
||||||
use crate::import::ImportState;
|
use crate::import::ImportState;
|
||||||
use crate::lang::{WordData, WordGroup, INVALID_ID};
|
use crate::lang::{INVALID_ID, WordData, WordGroup};
|
||||||
use crate::navigation::Page::{Import, Word};
|
use crate::navigation::Page::{Import, Word};
|
||||||
use crate::navigation::{NavigatedPage, Page};
|
use crate::navigation::{NavigatedPage, Page};
|
||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
use crate::word::WordState;
|
use crate::word::WordState;
|
||||||
use crate::{AppState, RootMessage};
|
use crate::{AppState, RootMessage};
|
||||||
use chrono::{DateTime, TimeDelta, Utc};
|
use chrono::{DateTime, TimeDelta, Utc};
|
||||||
|
use hashbrown::{HashMap, HashSet};
|
||||||
use iced::alignment::Vertical::Center;
|
use iced::alignment::Vertical::Center;
|
||||||
use iced::widget::button::Style;
|
use iced::widget::button::Style;
|
||||||
use iced::widget::button::{danger, text};
|
use iced::widget::button::{danger, text};
|
||||||
@@ -18,7 +19,6 @@ use iced::widget::*;
|
|||||||
use iced::{Border, Color, Shadow, Task};
|
use iced::{Border, Color, Shadow, Task};
|
||||||
use iced_core::Length::Fill;
|
use iced_core::Length::Fill;
|
||||||
use rand::random_range;
|
use rand::random_range;
|
||||||
use hashbrown::{HashMap, HashSet};
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::ops::Add;
|
use std::ops::Add;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@@ -96,7 +96,7 @@ impl NavigatedPage<DictionaryMessage> for DictionaryState {
|
|||||||
let dict = &state.dictionary;
|
let dict = &state.dictionary;
|
||||||
word = dict[*index].clone();
|
word = dict[*index].clone();
|
||||||
}
|
}
|
||||||
if word.id != INVALID_ID {
|
if word.id.is_valid() {
|
||||||
return Some(Word(WordState::new(word, *index, self.state.clone())));
|
return Some(Word(WordState::new(word, *index, self.state.clone())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -423,7 +423,7 @@ impl DictionaryState {
|
|||||||
let line_button = || {
|
let line_button = || {
|
||||||
let action = WordAction(index);
|
let action = WordAction(index);
|
||||||
|
|
||||||
if data.id == INVALID_ID {
|
if !data.id.is_valid() {
|
||||||
return button("-").on_press(action).style(|_x, _status| Style {
|
return button("-").on_press(action).style(|_x, _status| Style {
|
||||||
background: None,
|
background: None,
|
||||||
text_color: Color::BLACK,
|
text_color: Color::BLACK,
|
||||||
|
|||||||
+6
-1
@@ -28,7 +28,6 @@ const FADE_PER_DAY: f32 = 0.95;
|
|||||||
#[derive(Clone, PartialEq, Eq, Debug, Hash, Copy)]
|
#[derive(Clone, PartialEq, Eq, Debug, Hash, Copy)]
|
||||||
pub(crate) struct Id(u32);
|
pub(crate) struct Id(u32);
|
||||||
pub const INVALID_ID: Id = Id(0);
|
pub const INVALID_ID: Id = Id(0);
|
||||||
|
|
||||||
impl FromStr for Id {
|
impl FromStr for Id {
|
||||||
type Err = ParseIntError;
|
type Err = ParseIntError;
|
||||||
|
|
||||||
@@ -69,6 +68,12 @@ impl ToSql for Id {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Id {
|
||||||
|
pub(crate) fn is_valid(self) -> bool {
|
||||||
|
self.0 != 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct KanaSet {
|
pub struct KanaSet {
|
||||||
name: String,
|
name: String,
|
||||||
|
|||||||
+1
-1
@@ -27,6 +27,7 @@ use crate::lang::{DeckSettings, Id, WordData, WordGroup};
|
|||||||
use crate::navigation::{AppSettings, RootMessage, ScreenState};
|
use crate::navigation::{AppSettings, RootMessage, ScreenState};
|
||||||
use crate::quiz::*;
|
use crate::quiz::*;
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
|
use hashbrown::HashMap;
|
||||||
use iced::{Font, window};
|
use iced::{Font, window};
|
||||||
use iced::{Subscription, Theme, keyboard};
|
use iced::{Subscription, Theme, keyboard};
|
||||||
use iced_core::Size;
|
use iced_core::Size;
|
||||||
@@ -34,7 +35,6 @@ use iced_core::window::Position;
|
|||||||
use iced_core::window::settings::PlatformSpecific;
|
use iced_core::window::settings::PlatformSpecific;
|
||||||
use mimalloc::MiMalloc;
|
use mimalloc::MiMalloc;
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use hashbrown::HashMap;
|
|
||||||
|
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static GLOBAL: MiMalloc = MiMalloc;
|
static GLOBAL: MiMalloc = MiMalloc;
|
||||||
|
|||||||
+3
-3
@@ -7,6 +7,7 @@ use crate::dictionary::{DictionaryMessage, DictionaryState, app_data_dir};
|
|||||||
use crate::dictionary_test::{DictionaryQuizMessage, DictionaryQuizState};
|
use crate::dictionary_test::{DictionaryQuizMessage, DictionaryQuizState};
|
||||||
use crate::history::{HistoryMessage, HistoryState};
|
use crate::history::{HistoryMessage, HistoryState};
|
||||||
use crate::import::{ImportMessage, ImportState};
|
use crate::import::{ImportMessage, ImportState};
|
||||||
|
use crate::lang::Id;
|
||||||
use crate::message_navigation;
|
use crate::message_navigation;
|
||||||
use crate::navigation::Page::*;
|
use crate::navigation::Page::*;
|
||||||
use crate::navigation::RootMessage::{DataLoaded, Keyboard, UpdateData};
|
use crate::navigation::RootMessage::{DataLoaded, Keyboard, UpdateData};
|
||||||
@@ -24,14 +25,13 @@ use crate::word::{WordMessage, WordState};
|
|||||||
use crate::writing::{WritingMessage, WritingState};
|
use crate::writing::{WritingMessage, WritingState};
|
||||||
use crate::{AppState, fill_state};
|
use crate::{AppState, fill_state};
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
|
use hashbrown::HashMap;
|
||||||
use iced::keyboard::Event;
|
use iced::keyboard::Event;
|
||||||
use iced::{Element, Task};
|
use iced::{Element, Task};
|
||||||
use reqwest::Error;
|
use reqwest::Error;
|
||||||
use hashbrown::HashMap;
|
use rusqlite::Connection;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use rusqlite::Connection;
|
|
||||||
use crate::lang::Id;
|
|
||||||
|
|
||||||
impl Default for ScreenState {
|
impl Default for ScreenState {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,6 @@
|
|||||||
use crate::data_provider::voice::get_voice;
|
use crate::data_provider::voice::get_voice;
|
||||||
use crate::lang::{DeckData, DeckSettings, CardStatistics, WordData, WordOpenMode};
|
use crate::lang::Id;
|
||||||
|
use crate::lang::{CardStatistics, DeckData, DeckSettings, WordData, WordOpenMode};
|
||||||
use crate::navigation::Page::PreviousPage;
|
use crate::navigation::Page::PreviousPage;
|
||||||
use crate::navigation::{KeyPressedPage, NavigatedPage, Page};
|
use crate::navigation::{KeyPressedPage, NavigatedPage, Page};
|
||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
@@ -13,7 +14,6 @@ use iced::{Element, Fill, Task, Theme, alignment, keyboard};
|
|||||||
use rodio::MixerDeviceSink;
|
use rodio::MixerDeviceSink;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use crate::lang::Id;
|
|
||||||
use tokio::task::spawn_blocking;
|
use tokio::task::spawn_blocking;
|
||||||
|
|
||||||
pub struct RepetitionState {
|
pub struct RepetitionState {
|
||||||
|
|||||||
+5
-6
@@ -1,7 +1,7 @@
|
|||||||
use crate::data_provider::card_sets::update_deck;
|
use crate::data_provider::card_sets::update_deck;
|
||||||
use crate::data_provider::card_stats::{add_stat_list, load_stats_of_deck};
|
use crate::data_provider::card_stats::{add_stat_list, load_stats_of_deck};
|
||||||
use crate::history::HistoryState;
|
use crate::history::HistoryState;
|
||||||
use crate::lang::{AppendMode, CardStatistics, DeckSettings, INVALID_ID, Id, OrderMode};
|
use crate::lang::{AppendMode, CardStatistics, DeckSettings, Id, OrderMode};
|
||||||
use crate::navigation::Page::{History, PreviousPage, Repetition, RepetitionSettings};
|
use crate::navigation::Page::{History, PreviousPage, Repetition, RepetitionSettings};
|
||||||
use crate::navigation::{NavigatedPage, Page};
|
use crate::navigation::{NavigatedPage, Page};
|
||||||
use crate::repetition::RepetitionState;
|
use crate::repetition::RepetitionState;
|
||||||
@@ -115,7 +115,7 @@ impl NavigatedPage<RepetitionsMessage> for RepetitionsState {
|
|||||||
let index = self.selected_deck_index.unwrap();
|
let index = self.selected_deck_index.unwrap();
|
||||||
self.clear_selection();
|
self.clear_selection();
|
||||||
let deck = self.decks.remove(index);
|
let deck = self.decks.remove(index);
|
||||||
if deck.id != INVALID_ID {
|
if deck.id.is_valid() {
|
||||||
let mut state = self.state.lock().unwrap();
|
let mut state = self.state.lock().unwrap();
|
||||||
state.decks.remove(index);
|
state.decks.remove(index);
|
||||||
self.decks = self
|
self.decks = self
|
||||||
@@ -292,7 +292,7 @@ impl RepetitionsState {
|
|||||||
|
|
||||||
impl RepetitionsState {
|
impl RepetitionsState {
|
||||||
fn launch_delete_button(&self, deck: &DeckViewData) -> Element<'_, RepetitionsMessage> {
|
fn launch_delete_button(&self, deck: &DeckViewData) -> Element<'_, RepetitionsMessage> {
|
||||||
if deck.id != INVALID_ID {
|
if deck.id.is_valid() {
|
||||||
if deck.append_mode == AppendMode::Manual
|
if deck.append_mode == AppendMode::Manual
|
||||||
&& deck.existing_words_indices.as_ref().unwrap().is_empty()
|
&& deck.existing_words_indices.as_ref().unwrap().is_empty()
|
||||||
{
|
{
|
||||||
@@ -325,7 +325,7 @@ impl RepetitionsState {
|
|||||||
]
|
]
|
||||||
.spacing(QUARTER_SPACING),
|
.spacing(QUARTER_SPACING),
|
||||||
{
|
{
|
||||||
if deck.id == INVALID_ID {
|
if !deck.id.is_valid() {
|
||||||
column![
|
column![
|
||||||
column![
|
column![
|
||||||
text!("Передняя сторона"),
|
text!("Передняя сторона"),
|
||||||
@@ -548,8 +548,7 @@ impl RepetitionsState {
|
|||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
text_color:
|
text_color: _x.palette().primary,
|
||||||
_x.palette().primary,
|
|
||||||
border: Border {
|
border: Border {
|
||||||
color: Default::default(),
|
color: Default::default(),
|
||||||
width: 0.0,
|
width: 0.0,
|
||||||
|
|||||||
Reference in New Issue
Block a user