feat: showing results (just JSON currently) after submitting query
This commit is contained in:
parent
4915f20fbe
commit
f00f32bc78
|
@ -11,6 +11,8 @@ pub struct App {
|
|||
pub input: Input,
|
||||
/// Is the app running?
|
||||
pub running: bool,
|
||||
/// Results from the search query
|
||||
pub results: String,
|
||||
}
|
||||
|
||||
impl Default for App {
|
||||
|
@ -18,6 +20,7 @@ impl Default for App {
|
|||
App {
|
||||
input: Input::default(),
|
||||
running: true,
|
||||
results: "".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,25 +6,24 @@ use tui_input::backend::crossterm::EventHandler;
|
|||
|
||||
/// Handles the key events and updates the state of [`App`].
|
||||
pub async fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
|
||||
match key_event.code {
|
||||
// Exit application on `ESC`
|
||||
KeyCode::Esc => {
|
||||
match key_event {
|
||||
KeyEvent {
|
||||
code: KeyCode::Char('c'),
|
||||
modifiers: KeyModifiers::CONTROL,
|
||||
..
|
||||
} => {
|
||||
app.quit();
|
||||
}
|
||||
// Exit application on `Ctrl-C`
|
||||
KeyCode::Char('c') | KeyCode::Char('C') => {
|
||||
if key_event.modifiers == KeyModifiers::CONTROL {
|
||||
app.quit();
|
||||
}
|
||||
KeyEvent { code: KeyCode::Esc, .. } => {
|
||||
app.quit();
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
query_anime(app.input.to_string()).await.unwrap();
|
||||
KeyEvent { code: KeyCode::Enter, .. } => {
|
||||
app.results = format!("{:#?}", query_anime(app.input.to_string()).await.unwrap().results);
|
||||
app.input.reset();
|
||||
}
|
||||
_ => {
|
||||
app.input.handle_event(&Event::Key(key_event));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ pub fn render(app: &mut App, frame: &mut Frame) {
|
|||
chunks[1].y + 1,
|
||||
);
|
||||
|
||||
let messages = Paragraph::new("Another placeholder")
|
||||
let messages = Paragraph::new(&*app.results)
|
||||
.block(Block::default().borders(Borders::ALL).title("Results"));
|
||||
frame.render_widget(messages, chunks[2]);
|
||||
}
|
||||
|
|
Reference in a new issue