diff options
author | Julian T <julian@jtle.dk> | 2024-05-17 20:22:23 +0200 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2024-05-17 20:22:23 +0200 |
commit | 829cbaf2d0fe95abc9c65b1e34e209fc32952805 (patch) | |
tree | 3a35d6e768b09ea91540eb2f3f7b2df5bb507841 | |
parent | 22c8553af68c6f5b2c62ba790e06b249ac82ed2a (diff) |
Stuff i dont remember, sorry
-rw-r--r-- | src/main.rs | 5 | ||||
-rw-r--r-- | src/model/task.rs | 17 | ||||
-rw-r--r-- | src/render.rs | 11 | ||||
-rw-r--r-- | src/render/tasks.rs | 34 | ||||
-rw-r--r-- | test.db | bin | 20480 -> 20480 bytes |
5 files changed, 54 insertions, 13 deletions
diff --git a/src/main.rs b/src/main.rs index ad4bd25..39e81c9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,11 +12,6 @@ mod model; #[tokio::main] async fn main() -> Result<(), Box<dyn Error>> { let mut conn = SqliteConnection::connect("sqlite::memory:").await?; - let task = sqlx::query_as::<_, model::Task>("SELECT 'hej' as test") - .fetch_one(&mut conn).await?; - - println!("{}", task); - let mut terminal = tui::init()?; let res = App::default().run(&mut terminal); diff --git a/src/model/task.rs b/src/model/task.rs index 4fdfd88..e90dd8e 100644 --- a/src/model/task.rs +++ b/src/model/task.rs @@ -1,15 +1,20 @@ -use std::fmt::{self, Display}; - use sqlx::FromRow; #[derive(Debug, FromRow)] pub struct Task { - pub test: String, + pub id: i64, + pub group_id: i64, + pub name: String, + pub description: String, } -impl Display for Task { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "test: {}", self.test) +impl Task { + pub fn new(id: i64, group_id: i64, name: &str, description: &str) -> Task { + Task { + id, group_id, + name: String::from(name), + description: String::from(description), + } } } diff --git a/src/render.rs b/src/render.rs index 8c9ce38..d1d5f19 100644 --- a/src/render.rs +++ b/src/render.rs @@ -5,11 +5,12 @@ use ratatui::{ buffer::Buffer, layout::{Alignment, Constraint, Direction, Layout, Rect}, style::Stylize, symbols::border, text::Text, widgets::{block::Title, Block, Borders, Paragraph, Widget}, Frame }; -use crate::tui; +use crate::{tui, model::Task}; -use self::footer::Footer; +use self::{footer::Footer, tasks::TaskList}; mod footer; +mod tasks; #[derive(Debug, Default)] pub struct App { @@ -61,6 +62,12 @@ impl Widget for &App { Constraint::Length(1), ]) .split(area); + TaskList::new(&vec![ + Task::new(1, 1, "Hej", "Hej med dig hvordan går det"), + Task::new(2, 1, "Lul", "Hej med dig hvordan går det"), + Task::new(3, 1, "Hvordan lige", ""), + Task::new(4, 1, "Hej med dig", ""), + ]).render(chunks[0], buf); Footer::new().render(chunks[1], buf); } } diff --git a/src/render/tasks.rs b/src/render/tasks.rs new file mode 100644 index 0000000..0f6a79a --- /dev/null +++ b/src/render/tasks.rs @@ -0,0 +1,34 @@ +use ratatui::{layout::Constraint, widgets::{Row, Table, Widget}, prelude::Text}; + +use crate::model::Task; + + + +#[derive(Debug)] +pub struct TaskList<'a> { + tasks: &'a[Task] +} + +impl<'a> TaskList<'a> { + pub fn new(tasks: &'a[Task]) -> TaskList<'a> { + TaskList { + tasks + } + } +} + +impl<'a> Widget for &TaskList<'a> { + fn render(self, area: ratatui::prelude::Rect, buf: &mut ratatui::prelude::Buffer) { + let rows: Vec<Row> = self.tasks.into_iter() + .map(|t: &Task| Row::new(vec![Text::from(t.name.as_str()), Text::from(t.description.as_str())])) + .collect(); + + let widths = [ + Constraint::Percentage(50), + Constraint::Fill(1), + ]; + + Table::new(rows, widths) + .render(area, buf); + } +} Binary files differ |