Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
Eiafuawn committed Feb 15, 2024
1 parent b6fb0ff commit 67edf64
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
23 changes: 16 additions & 7 deletions src/components/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ use color_eyre::eyre::Result;
use ratatui::{prelude::*, widgets::*};

use super::Component;
use crate::{action::Action, tui::Frame};
use crate::{action::Action, mode::Mode, tui::Frame};

#[derive(Default)]
pub struct Download {
mode: Mode,
download_output: String,
}

impl Download {
pub fn new() -> Self {
Self {
mode: Mode::Idle,
download_output: String::new(),
}
}
Expand All @@ -23,9 +25,11 @@ impl Component for Download {
fn update(&mut self, action: Action) -> Result<Option<Action>> {
#[allow(clippy::single_match)]
match action {
Action::EnterEditing => self.mode = Mode::SelectingDir,
Action::SelectPlaylist(_, _) => self.mode = Mode::Downloading,
Action::Downloading(output) => {
self.download_output.push_str(&output);
self.download_output.push('\n');
self.download_output.push_str(&output);
self.download_output.push('\n');
}
_ => {}
}
Expand All @@ -38,11 +42,16 @@ impl Component for Download {
[Constraint::Percentage(50), Constraint::Percentage(50)],
)
.split(rect);
let output = Paragraph::new(self.download_output.clone())
.style(Style::default().fg(Color::Black).bg(Color::White))
.block(Block::default().borders(Borders::ALL).title("Output"));
match self.mode {
Mode::Downloading => {
let output = Paragraph::new(self.download_output.clone())
.style(Style::default().fg(Color::White).bg(Color::Black))
.block(Block::default().borders(Borders::ALL).title("Output"));

f.render_widget(output, chunks[1]);
f.render_widget(output, chunks[1]);
}
_ => f.render_widget(Clear, chunks[1]),
}

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl Component for Home {
f.render_widget(menu, chunks[0]);

if self.mode == Mode::SelectingDir {
f.render_widget(Clear, chunks[0]);
f.render_widget(Clear, area);
let popup_block = Block::default()
.title("Choose your folder")
.borders(Borders::ALL)
Expand Down
5 changes: 4 additions & 1 deletion src/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use serde::{Deserialize, Serialize};
pub enum Mode {
#[default]
Home,
Downloading,
SelectingDir,

// Outputs
Idle,
Downloading,
}

0 comments on commit 67edf64

Please sign in to comment.