Skip to content

Commit

Permalink
refactor: proper naming of the api explorer layout
Browse files Browse the repository at this point in the history
  • Loading branch information
wllfaria committed Apr 18, 2024
1 parent a6e2e2f commit b4f0818
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions tui/src/components/api_explorer/api_explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::components::{
},
Component,
};
use anyhow::Context;
use crossterm::event::{KeyCode, KeyEvent};
use httpretty::{
command::Command,
Expand All @@ -19,7 +20,7 @@ use ratatui::{
};
use std::collections::HashMap;

pub struct EditorLayout {
pub struct ExplorerLayout {
pub sidebar: Rect,
pub req_builder: Rect,
pub req_editor: Rect,
Expand All @@ -38,7 +39,7 @@ enum PaneFocus {
}

pub struct ApiExplorer<'a> {
layout: EditorLayout,
layout: ExplorerLayout,
schema: Schema,

focus: PaneFocus,
Expand Down Expand Up @@ -75,15 +76,16 @@ impl<'a> ApiExplorer<'a> {
}
}

#[tracing::instrument(skip_all, err)]
fn handle_sidebar_key_event(&mut self, key_event: KeyEvent) -> anyhow::Result<Option<Command>> {
match key_event.code {
KeyCode::Enter => if let Some(ref _id) = self.selected_request {},
KeyCode::Char('j') => {
if let Some(ref id) = self.selected_request {
self.selected_request = find_next_entry(
self.schema.requests.as_ref().expect(
self.schema.requests.as_ref().context(
"should never have a selected request without any requests on schema",
),
)?,
VisitNode::Next,
&self.dirs_expanded,
id,
Expand All @@ -93,9 +95,9 @@ impl<'a> ApiExplorer<'a> {
KeyCode::Char('k') => {
if let Some(ref id) = self.selected_request {
self.selected_request = find_next_entry(
self.schema.requests.as_ref().expect(
self.schema.requests.as_ref().context(
"should never have a selected request without any requests on schema",
),
)?,
VisitNode::Prev,
&self.dirs_expanded,
id,
Expand Down Expand Up @@ -140,7 +142,7 @@ impl Component for ApiExplorer<'_> {
}
}

pub fn build_layout(size: Rect) -> EditorLayout {
pub fn build_layout(size: Rect) -> ExplorerLayout {
let [sidebar, right_pane] = Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Length(30), Constraint::Fill(1)])
Expand All @@ -163,7 +165,7 @@ pub fn build_layout(size: Rect) -> EditorLayout {
.areas(request_builder)
};

EditorLayout {
ExplorerLayout {
sidebar,
req_builder: url,
req_editor: request_builder,
Expand Down

0 comments on commit b4f0818

Please sign in to comment.