diff --git a/src/app/mod.rs b/src/app/mod.rs index 658e93c..1264530 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -1,7 +1,6 @@ pub mod form; use crate::event::input::Input; -use clap::ValueEnum; use form::Form; use std::{collections::HashMap, str::FromStr}; diff --git a/src/request.rs b/src/request.rs index c071cac..b9b8d79 100644 --- a/src/request.rs +++ b/src/request.rs @@ -53,8 +53,8 @@ pub async fn send(req: Request) -> Response { match content_type.clone().to_str().unwrap().to_lowercase() { h if h.contains("application/json") => { let data = response.json::().await.unwrap(); - content_type_value = "application/json".to_string(); + content_type_value = "application/json".to_string(); text = format!("{:#}\n", data); } diff --git a/src/ui/request_tab.rs b/src/ui/request_tab.rs index 63ecae7..1b490ec 100644 --- a/src/ui/request_tab.rs +++ b/src/ui/request_tab.rs @@ -79,29 +79,11 @@ pub fn render_request_tab(app: &App, frame: &mut Frame<'_, CrosstermBackend = app - .body_form - .iter() - .map(|(key, value)| { - Row::new(vec![key.clone(), value.clone()]) - .style(Style::default().fg(Color::White)) - }) - .collect(); - - let table = Table::new(rows) - .header( - Row::new(vec!["Key", "Value"]) - .style(Style::default().fg(Color::Yellow)) - .bottom_margin(1), - ) - .widths(&[Constraint::Percentage(50), Constraint::Percentage(50)]) - .highlight_style(Style::default().fg(Color::Green)) - .highlight_symbol(">> ") - .block( - selectable_block(AppBlock::RequestContent, app) - .title("Body") - .padding(ratatui::widgets::Padding::new(1, 1, 1, 1)), - ); + let table = create_kv_table(app.body_form.clone().into_iter().collect()).block( + selectable_block(AppBlock::RequestContent, app) + .title("Body") + .padding(ratatui::widgets::Padding::new(1, 1, 1, 1)), + ); let mut state = TableState::default(); @@ -111,29 +93,11 @@ pub fn render_request_tab(app: &App, frame: &mut Frame<'_, CrosstermBackend { - let rows: Vec = app - .headers - .iter() - .map(|(key, value)| { - Row::new(vec![key.clone(), value.clone()]) - .style(Style::default().fg(Color::White)) - }) - .collect(); - - let table = Table::new(rows) - .header( - Row::new(vec!["Key", "Value"]) - .style(Style::default().fg(Color::Yellow)) - .bottom_margin(1), - ) - .widths(&[Constraint::Percentage(50), Constraint::Percentage(50)]) - .highlight_style(Style::default().fg(Color::Green)) - .highlight_symbol(">> ") - .block( - selectable_block(AppBlock::RequestContent, app) - .title("Headers") - .padding(ratatui::widgets::Padding::new(1, 1, 1, 1)), - ); + let table = create_kv_table(app.headers.clone().into_iter().collect()).block( + selectable_block(AppBlock::RequestContent, app) + .title("Headers") + .padding(ratatui::widgets::Padding::new(1, 1, 1, 1)), + ); let mut state = TableState::default(); @@ -142,29 +106,11 @@ pub fn render_request_tab(app: &App, frame: &mut Frame<'_, CrosstermBackend { - let rows: Vec = app - .query_params - .iter() - .map(|(key, value)| { - Row::new(vec![key.clone(), value.clone()]) - .style(Style::default().fg(Color::White)) - }) - .collect(); - - let table = Table::new(rows) - .header( - Row::new(vec!["Key", "Value"]) - .style(Style::default().fg(Color::Yellow)) - .bottom_margin(1), - ) - .widths(&[Constraint::Percentage(50), Constraint::Percentage(50)]) - .highlight_style(Style::default().fg(Color::Green)) - .highlight_symbol(">> ") - .block( - selectable_block(AppBlock::RequestContent, app) - .title("Query Parameters") - .padding(ratatui::widgets::Padding::new(1, 1, 1, 1)), - ); + let table = create_kv_table(app.query_params.clone()).block( + selectable_block(AppBlock::RequestContent, app) + .title("Query Parameters") + .padding(ratatui::widgets::Padding::new(1, 1, 1, 1)), + ); let mut state = TableState::default(); @@ -175,3 +121,22 @@ pub fn render_request_tab(app: &App, frame: &mut Frame<'_, CrosstermBackend {} } } + +fn create_kv_table(pairs: Vec<(String, String)>) -> Table<'static> { + let rows: Vec = pairs + .iter() + .map(|(key, value)| { + Row::new(vec![key.clone(), value.clone()]).style(Style::default().fg(Color::White)) + }) + .collect(); + + Table::new(rows) + .header( + Row::new(vec!["Key", "Value"]) + .style(Style::default().fg(Color::Yellow)) + .bottom_margin(1), + ) + .widths(&[Constraint::Percentage(50), Constraint::Percentage(50)]) + .highlight_style(Style::default().fg(Color::Green)) + .highlight_symbol(">> ") +}