Skip to content

Commit

Permalink
feature: add basic console app using dioxus
Browse files Browse the repository at this point in the history
  • Loading branch information
shenek committed Jan 19, 2024
1 parent 4ebe553 commit 7cfba9f
Show file tree
Hide file tree
Showing 18 changed files with 2,456 additions and 406 deletions.
2,019 changes: 1,628 additions & 391 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
members = [
"ucelofka",
"ucelofka-data",
#"ucelofka-webapp",
]

default-members = [
"ucelofka",
]

exclude = [
"ucelofka-webapp",
]
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
# Ucelofka (project root)

* [CLI application](ucelofka/README.md)
* [webapp](ucelofka/README.md)
* [common data](ucelofka-data/README.md)

## Installation

To install ucelofka from sources you need to install two binary crates first:
```bash
cargo install wasm-bindgen-cli trunk
You should be able to install ucelofka using:
```

Afterwards you should be able to install ucelofka:
```
cargo install --path .
cargo install --path ucelofka/
```
6 changes: 6 additions & 0 deletions ucelofka-data/src/identification/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ pub struct Identification {
pub name: String,
pub value: String,
}

impl ToString for Identification {
fn to_string(&self) -> String {
return format!("{}:{}", self.name, self.value)
}
}
2 changes: 2 additions & 0 deletions ucelofka/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ tera = "~1.6.1"
tokio = { version = "1", features = ["rt", "rt-multi-thread"]}
unic-langid = { version = "~0.9.0", features = ["macros"]}
ucelofka-data = { path="../ucelofka-data/" }
dioxus = "0.4"
dioxus-tui = "0.4"

[dev-dependencies]
assert_cmd = "~1.0.1"
Expand Down
Empty file removed ucelofka/default/invoices/.gitkeep
Empty file.
52 changes: 52 additions & 0 deletions ucelofka/default/invoices/202400001.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
_version: 2
id: 202400001
issue_date: 2024-01-19
due_date: 2024-02-03
issuer:
name: Your Name
address:
- YouStreet 123/4
- 56789 YouCity
- YouCountry
phone:
- +420 111 222 333
email:
- [email protected]
www:
- www.your-site.com
identifications:
- name: tax
value: CZ1234567890
- name: registration
value: "987654321"
customer:
name: First Customer
address:
- CoStreet 1234/5
- 12345 CoCity
- CoCountry
identifications:
- name: registration
value: "123456"
- name: tax
value: CZ123456
email:
- [email protected]
entries:
- name: IT system management
price: 999.989990234375
currency: USD
details:
- System maintenance
- DB Optimizations
- Performing security updates
billing:
account_name: Your Name
account_number: 12-1234632/2700
BIC: AABBCCDDEE
IBAN: MY11 2222 3333 4444 5555 6666
total: 999.989990234375
currency: USD
variable_symbol: "202400001"

21 changes: 21 additions & 0 deletions ucelofka/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod actions;
pub mod storage;
pub mod translations;
pub mod tui;
pub mod web;

use anyhow::{anyhow, Result};
Expand Down Expand Up @@ -338,6 +339,12 @@ fn prepare_ids_subcommand() -> Command {
.about("Print ids of all entities")
}

fn prepare_tui_subcommand() -> Command {
Command::new("tui")
.arg(prepare_data_dir())
.about("Start ucelofka's tui")
}

fn prepare_cmd() -> Command {
Command::new(crate_name!())
.author(crate_authors!())
Expand All @@ -353,6 +360,7 @@ fn prepare_cmd() -> Command {
.subcommand(prepare_web())
.subcommand(prepare_completions())
.subcommand(prepare_ids_subcommand())
.subcommand(prepare_tui_subcommand())
}

fn get_data_dir(matches: &ArgMatches) -> Result<PathBuf> {
Expand Down Expand Up @@ -600,6 +608,18 @@ fn process_ids(_cmd: Command, matches: &ArgMatches) -> Result<()> {
Ok(())
}

fn process_tui(_cmd: Command, matches: &ArgMatches) -> Result<()> {
let path = get_data_dir(matches)?;
dioxus_tui::launch_cfg_with_props(
tui::App,
tui::AppProps {
path
},
dioxus_tui::Config::new(),
);
Ok(())
}

fn main() -> Result<()> {
let cmd = prepare_cmd();

Expand All @@ -618,6 +638,7 @@ fn main() -> Result<()> {
process_completions(cmd.clone(), completions_matches)?
}
Some(("ids", ids_matches)) => process_ids(cmd.clone(), ids_matches)?,
Some(("tui", tui_matches)) => process_tui(cmd.clone(), tui_matches)?,
_ => exit_on_parse_error(cmd),
}
Ok(())
Expand Down
12 changes: 12 additions & 0 deletions ucelofka/src/tui.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![allow(non_snake_case, deprecated)]

pub mod account;
pub mod app;
pub mod customer;
pub mod entry;
pub mod identity;
pub mod list;
pub mod table;
pub mod invoice;

pub use app::{App, AppProps};
82 changes: 82 additions & 0 deletions ucelofka/src/tui/account.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#![allow(non_snake_case, deprecated)]

use dioxus::prelude::*;
use std::rc::Rc;
use ucelofka_data::account::Account;

use crate::actions::account::list;

use super::{app::UcelofkaTuiCfg, list::List, table::Table};

struct CurrentAccountPage(usize);

#[derive(Clone)]
enum SubPage {
Create,
Account(Account),
}

impl AsRef<str> for SubPage {
fn as_ref(&self) -> &str {
match self {
Self::Create => "<Create>",
Self::Account(account) => account.name.as_str(),
}
}
}

#[inline_props]
pub fn Accounts(cx: Scope) -> Element {
use_shared_state_provider(cx, || CurrentAccountPage(0));

let account_page = use_shared_state::<CurrentAccountPage>(cx).unwrap();

let cfg = use_shared_state::<UcelofkaTuiCfg>(cx).unwrap();
let accounts = list(cfg.read().path.as_path()).unwrap().accounts;
let items: Vec<SubPage> = vec![SubPage::Create]
.into_iter()
.chain(accounts.iter().map(|e| SubPage::Account(e.clone())))
.collect();

let items_str: Vec<String> = items.iter().map(|e| e.as_ref().to_string()).collect();
let selected_idx = account_page.read().0;
let selected_account = if selected_idx == 0 {
None
} else {
Some(accounts[selected_idx - 1].clone())
};

cx.render(rsx! {
List {
tabindex: 0,
width: "20%",
items: Rc::new(items_str),
dot: "❱",
idx: account_page.read().0.into(),
onindexupdate: move |i: usize| {
account_page.write().0 = i.into();
}
}
div { width: "60%", border_width: "1px", height: "100%", justify_content: "center",
if let Some(account) = selected_account {
rsx! {
Table {
width: "100%",
items: vec![
("Name:", account.name),
("Bank Name:", account.bank_name),
("Account Name:", account.account_name),
("Account number:", account.account_number),
("IBAN:", account.IBAN),
("BIC:", account.BIC),
("Currency:", account.currency),

]
}
}
} else {
rsx! {span { "TODO CREATE FORM"}}
}
}
})
}
Loading

0 comments on commit 7cfba9f

Please sign in to comment.