Skip to content

Commit

Permalink
wip: working on auth editor
Browse files Browse the repository at this point in the history
  • Loading branch information
wllfaria committed Jul 3, 2024
1 parent 658f7e5 commit 09cbf4d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion hac-client/src/pages/collection_viewer/request_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl<'re> RequestEditor<'re> {
ReqEditorTabs::Body => self.body_editor.draw(frame, size)?,
ReqEditorTabs::Headers => self.headers_editor.draw(frame, size)?,
ReqEditorTabs::Query => UnderConstruction::new(self.colors).draw(frame, size)?,
ReqEditorTabs::Auth => UnderConstruction::new(self.colors).draw(frame, size)?,
ReqEditorTabs::Auth => self.auth_editor.draw(frame, size)?,
}

Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ use crate::pages::collection_viewer::collection_store::CollectionStore;
use crate::pages::{Eventful, Renderable};

use std::cell::RefCell;
use std::ops::Sub;
use std::rc::Rc;

use crossterm::event::KeyEvent;
use ratatui::{layout::Rect, widgets::Paragraph, Frame};
use ratatui::layout::Rect;
use ratatui::style::Stylize;
use ratatui::widgets::{Block, Borders, Paragraph};
use ratatui::Frame;

#[derive(Debug)]
pub struct AuthEditor<'ae> {
_colors: &'ae hac_colors::colors::Colors,
colors: &'ae hac_colors::colors::Colors,
collection_store: Rc<RefCell<CollectionStore>>,
}

Expand All @@ -19,23 +23,55 @@ impl<'ae> AuthEditor<'ae> {
collection_store: Rc<RefCell<CollectionStore>>,
) -> Self {
AuthEditor {
_colors: colors,
colors,
collection_store,
}
}

fn get_hint_size(&self, frame: &mut Frame) -> Rect {
let size = frame.size();
Rect::new(0, size.height.sub(1), size.width, 1)
}

fn draw_hint(&self, frame: &mut Frame, has_auth: bool) {
let hint_size = self.get_hint_size(frame);
let hint = if has_auth {
match hint_size.width {
w if w.le(&100) => "[e: Change method] [Tab: Change focus] [?: Help]",
_ => "[e: Change method] [Tab: Change focus] [?: Help]",
}
} else {
"[e: Select method]"
};
frame.render_widget(
Paragraph::new(hint).fg(self.colors.bright.black).centered(),
hint_size,
);
}
}

impl Renderable for AuthEditor<'_> {
fn draw(&mut self, frame: &mut Frame, size: Rect) -> anyhow::Result<()> {
frame.render_widget(Paragraph::new("hello from auth editor").centered(), size);
let store = self.collection_store.borrow();

let Some(request) = store.get_selected_request() else {
return Ok(());
};

let request = request.read().unwrap();
if request.auth_method.is_none() {
let has_auth = request.auth_method.is_none();
self.draw_hint(frame, has_auth);

if has_auth {
let no_request = "No authentication method".fg(self.colors.bright.black);
let no_request = Paragraph::new(no_request).centered().block(
Block::default()
.fg(self.colors.normal.white)
.borders(Borders::ALL),
);

let size = Rect::new(size.x, size.y, size.width.sub(10), 3);
frame.render_widget(no_request, size);
return Ok(());
}

Expand Down

0 comments on commit 09cbf4d

Please sign in to comment.