From 235fd9acc54822c07a021676c5da1b5e1586ca71 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 21 Aug 2022 02:38:45 +0200 Subject: [PATCH] Move stability checks back into room --- src/ui/euph/auth.rs | 13 ------------- src/ui/euph/nick.rs | 8 +------- src/ui/euph/room.rs | 16 ++++++++++++++-- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/ui/euph/auth.rs b/src/ui/euph/auth.rs index 6ddef88..9af8d59 100644 --- a/src/ui/euph/auth.rs +++ b/src/ui/euph/auth.rs @@ -2,7 +2,6 @@ use std::sync::Arc; use crossterm::event::KeyCode; use crossterm::style::{ContentStyle, Stylize}; -use euphoxide::conn::{Joining, Status}; use parking_lot::FairMutex; use toss::terminal::Terminal; @@ -16,22 +15,10 @@ use crate::ui::widgets::popup::Popup; use crate::ui::widgets::text::Text; use crate::ui::widgets::BoxedWidget; -use super::room::RoomStatus; - pub fn new() -> EditorState { EditorState::new() } -pub fn stable(status: &RoomStatus) -> bool { - matches!( - status, - RoomStatus::Connected(Status::Joining(Joining { - bounce: Some(_), - .. - })) - ) -} - pub fn widget() -> BoxedWidget { Popup::new( Padding::new(Cursor::new(Text::new(( diff --git a/src/ui/euph/nick.rs b/src/ui/euph/nick.rs index ca027f8..513e0e4 100644 --- a/src/ui/euph/nick.rs +++ b/src/ui/euph/nick.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use crossterm::event::KeyCode; -use euphoxide::conn::{Joined, Status}; +use euphoxide::conn::Joined; use parking_lot::FairMutex; use toss::styled::Styled; use toss::terminal::Terminal; @@ -14,16 +14,10 @@ use crate::ui::widgets::padding::Padding; use crate::ui::widgets::popup::Popup; use crate::ui::widgets::BoxedWidget; -use super::room::RoomStatus; - pub fn new(joined: Joined) -> EditorState { EditorState::with_initial_text(joined.session.name) } -pub fn stable(status: &RoomStatus) -> bool { - matches!(status, RoomStatus::Connected(Status::Joined(_))) -} - pub fn widget(editor: &EditorState) -> BoxedWidget { let editor = editor .widget() diff --git a/src/ui/euph/room.rs b/src/ui/euph/room.rs index 0478fb7..d21e52f 100644 --- a/src/ui/euph/room.rs +++ b/src/ui/euph/room.rs @@ -153,8 +153,20 @@ impl EuphRoom { fn stabilize_state(&mut self, status: &RoomStatus) { match &self.state { - State::Auth(_) if !auth::stable(status) => self.state = State::Normal, - State::Nick(_) if !nick::stable(status) => self.state = State::Normal, + State::Auth(_) + if !matches!( + status, + RoomStatus::Connected(Status::Joining(Joining { + bounce: Some(_), + .. + })) + ) => + { + self.state = State::Normal + } + State::Nick(_) if !matches!(status, RoomStatus::Connected(Status::Joined(_))) => { + self.state = State::Normal + } _ => {} } }