Skip to content

Commit

Permalink
feat(phone): added request payload import
Browse files Browse the repository at this point in the history
  • Loading branch information
zaghaghi committed May 5, 2024
1 parent ff8ece2 commit bd78a06
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,12 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
id: push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
provenance: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
labels: ${{ steps.meta.outputs.labels }}
6 changes: 5 additions & 1 deletion src/pages/phone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,11 @@ impl Page for Phone {
if let Some(pane) = self.panes.get_mut(self.focused_pane_index) {
pane.update(Action::Focus, state)?;
}
actions.push(self.handle_commands(args));
if let Some(action) = self.handle_commands(args) {
for pane in self.panes.iter_mut() {
actions.push(pane.update(action.clone(), state)?);
}
}
},
Action::FooterResult(_cmd, None) => {
if let Some(pane) = self.panes.get_mut(self.focused_pane_index) {
Expand Down
27 changes: 25 additions & 2 deletions src/panes/body_editor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{io::Read, sync::Arc};

use color_eyre::eyre::Result;
use crossterm::event::{KeyCode, KeyEvent};
Expand Down Expand Up @@ -135,6 +135,19 @@ impl Pane for BodyEditor<'_> {
Action::UnFocus => {
self.focused = false;
},
Action::OpenRequestPayload(filepath) => {
if let Err(error) = std::fs::File::open(filepath)
.and_then(|mut file| {
let mut buffer = String::new();
file.read_to_string(&mut buffer).map(|_| buffer)
})
.map(|item| {
self.input = TextArea::from(item.lines());
})
{
return Ok(Some(Action::TimedStatusLine(format!("Can't open or read file content: {error}"), 5)));
}
},
_ => {},
}
Ok(None)
Expand All @@ -151,7 +164,17 @@ impl Pane for BodyEditor<'_> {
}

if !self.content_types.is_empty() {
frame.render_widget(self.input.widget(), inner);
if !self.input.is_empty() || state.input_mode == InputMode::Insert {
frame.render_widget(self.input.widget(), inner);
} else {
frame.render_widget(
Paragraph::new(
" Press enter to start editing,\n or try [request open payload-file-path] command to load from a file.",
)
.style(Style::default().dim()),
inner,
);
}
}

let content_types = if !self.content_types.is_empty() {
Expand Down

0 comments on commit bd78a06

Please sign in to comment.