Add Login Error Text Display and Logout callback
This commit is contained in:
parent
9a1ee2ba63
commit
53e6f72cbb
2 changed files with 28 additions and 17 deletions
src
17
src/main.rs
17
src/main.rs
|
@ -9,8 +9,6 @@ use chrono::{DateTime, Local, Utc};
|
|||
use reqwest::StatusCode;
|
||||
use serde::{Deserialize};
|
||||
|
||||
use crate::Menu::JNovel;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct CalibreWebImporter {
|
||||
jnc: jnovel::State,
|
||||
|
@ -24,8 +22,8 @@ impl Default for CalibreWebImporter {
|
|||
Self {
|
||||
jnc: jnovel::State::default(),
|
||||
settings: AppSettings::default(),
|
||||
current_menu: JNovel,
|
||||
previous_menu: JNovel,
|
||||
current_menu: Menu::JNovel,
|
||||
previous_menu: Menu::JNovel,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,13 +115,13 @@ impl Application for CalibreWebImporter {
|
|||
jnovel::Message::Login => {
|
||||
self.jnc.login_state = jnovel::LoginState::LoggingIn;
|
||||
let _ = open::that("https://j-novel.club/user/otp");
|
||||
Command::perform(self.jnc.login(), |status| Message::JncAction(jnovel::Message::LoginState(status)))
|
||||
Command::perform(jnovel::State::login(), |status| Message::JncAction(jnovel::Message::LoginState(status)))
|
||||
}
|
||||
jnovel::Message::Logout => {
|
||||
println!("Logging out from J-Novel Club");
|
||||
self.jnc.token = None;
|
||||
self.jnc.login_state = jnovel::LoginState::LoggedOut;
|
||||
Command::none()
|
||||
Command::perform(jnovel::State::logout(self.jnc.clone()), || Message::JncAction(jnovel::Message::LoginState(jnovel::LoginState::LoggedOut)))
|
||||
}
|
||||
jnovel::Message::LoginState(status) => {
|
||||
if let jnovel::LoginState::Success(token) = status {
|
||||
|
@ -131,7 +129,7 @@ impl Application for CalibreWebImporter {
|
|||
self.jnc.login_state = status;
|
||||
|
||||
if self.jnc.library_state == jnovel::LibraryState::Unloaded {
|
||||
Command::perform(self.jnc.load_library(), |status| Message::JncAction(jnovel::Message::LibraryState(status)))
|
||||
Command::perform(jnovel::State::load_library(self.jnc.clone()), |status| Message::JncAction(jnovel::Message::LibraryState(status)))
|
||||
}
|
||||
else {
|
||||
Command::none()
|
||||
|
@ -190,7 +188,10 @@ impl Application for CalibreWebImporter {
|
|||
jnovel::LoginState::LoggedOut => Element::from(button("Login").on_press(Message::JncAction(jnovel::Message::Login))),
|
||||
jnovel::LoginState::LoggingIn => Element::from(text("Logging in")),
|
||||
jnovel::LoginState::AwaitingConfirmation(code, start) => Element::from(text(format!("Login Code: {}. Expiring: {}s", code.otp, 600 - (Local::now() - start).num_seconds()))),
|
||||
jnovel::LoginState::Error(_) => Element::from(button("Error").on_press(Message::JncAction(jnovel::Message::LoginState(jnovel::LoginState::LoggedOut)))),
|
||||
jnovel::LoginState::Error(err) => Element::from(row![
|
||||
button("Error").on_press(Message::JncAction(jnovel::Message::LoginState(jnovel::LoginState::LoggedOut))),
|
||||
text(err),
|
||||
]),
|
||||
};
|
||||
|
||||
column(vec![Element::from(
|
||||
|
|
Reference in a new issue