reverted the idea of getting a lobby list from the server

This commit is contained in:
clizia 2025-05-13 19:21:53 +02:00
parent b37ab4a37d
commit 789e3912d3
4 changed files with 101 additions and 111 deletions

View file

@ -1,13 +1,12 @@
use anyhow::Result; use anyhow::Result;
use ratatui::DefaultTerminal; use ratatui::{widgets::ListState, DefaultTerminal};
use crate::{message::{Message, MessageKind}, player::Player, ui::{ui, CurrentScreen}}; use crate::{lobby::Lobby, message::{Message, MessageKind}, player::Player, ui::{ui, CurrentScreen}};
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct Client { pub struct Client {
pub addr: String, pub addr: String,
pub client: reqwest::Client, pub client: reqwest::Client,
pub current_screen: CurrentScreen,
pub user: Option<String>, pub user: Option<String>,
pub user_name: String, pub user_name: String,
pub exit: bool, pub exit: bool,

View file

@ -19,6 +19,7 @@ pub enum MessageKind {
DeleteLobby, DeleteLobby,
JoinLobby, JoinLobby,
QuitLobby, QuitLobby,
GetLobbies,
} }
impl Message { impl Message {

View file

@ -133,4 +133,5 @@ impl App {
) -> Result<axum::response::Json<Message>, StatusCode> { ) -> Result<axum::response::Json<Message>, StatusCode> {
todo!() todo!()
} }
} }

View file

@ -8,7 +8,7 @@ use ratatui::{
}, },
style::{Color, Style, Stylize}, style::{Color, Style, Stylize},
text::{Line, Span, Text}, text::{Line, Span, Text},
widgets::{Block, Borders, Clear, List, ListItem, Paragraph, Widget, Wrap}, widgets::{Block, Borders, Clear, List, ListItem, ListState, Paragraph, Widget, Wrap},
Frame, Frame,
}; };
use ratatui::crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind}; use ratatui::crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind};
@ -57,14 +57,12 @@ impl Widget for Popup<'_> {
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub enum CurrentScreen { pub enum CurrentScreen {
#[default] Menu, #[default] Menu,
LobbyList, Lobbies,
} }
async fn handle_key_event(mut client: &mut Client, key_event: KeyEvent) { async fn handle_key_event(mut client: &mut Client, key_event: KeyEvent) {
match &client.popup { match &client.popup {
false => { false => {
match client.current_screen {
CurrentScreen::Menu => {
match key_event.code { match key_event.code {
KeyCode::Char('q') => Client::exit(client), KeyCode::Char('q') => Client::exit(client),
KeyCode::Char('h') => { KeyCode::Char('h') => {
@ -111,9 +109,6 @@ async fn handle_key_event(mut client: &mut Client, key_event: KeyEvent) {
_ => (), _ => (),
} }
} }
CurrentScreen::LobbyList => todo!(),
}
}
true => { true => {
match key_event.code { match key_event.code {
_ => client.popup = false, _ => client.popup = false,
@ -134,9 +129,6 @@ pub async fn handle_events(client: &mut Client) -> anyhow::Result<()> {
} }
pub fn ui(frame: &mut Frame, app: &Client) { pub fn ui(frame: &mut Frame, app: &Client) {
match app.current_screen {
CurrentScreen::Menu => {
let chunks = Layout::default() let chunks = Layout::default()
.direction(Direction::Vertical) .direction(Direction::Vertical)
.constraints([ .constraints([
@ -195,9 +187,6 @@ pub fn ui(frame: &mut Frame, app: &Client) {
.block(btm_block), .block(btm_block),
chunks[1], chunks[1],
); );
}
CurrentScreen::LobbyList => todo!(),
}
let popup_area = Rect { let popup_area = Rect {
x: frame.area().width / 4, x: frame.area().width / 4,