Skip to content

Commit

Permalink
Restructure frontend source code
Browse files Browse the repository at this point in the history
  • Loading branch information
treiher committed Nov 3, 2024
1 parent b508f6b commit 8f81c13
Show file tree
Hide file tree
Showing 21 changed files with 1,001 additions and 1,002 deletions.
909 changes: 2 additions & 907 deletions frontend/src/main.rs

Large diffs are not rendered by default.

910 changes: 910 additions & 0 deletions frontend/src/ui.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion frontend/src/common.rs → frontend/src/ui/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use chrono::{prelude::*, Duration};
use plotters::prelude::*;
use seed::{prelude::*, *};

use crate::{data, domain};
use crate::{domain, ui::data};

pub const ENTER_KEY: u32 = 13;

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use seed::{prelude::*, *};

use crate::{common, data, domain};
use crate::{
domain,
ui::{common, data},
};

// ------ ------
// Model
Expand Down
13 changes: 8 additions & 5 deletions frontend/src/data.rs → frontend/src/ui/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use gloo_storage::Storage;
use seed::{prelude::*, *};
use serde_json::{json, Map};

use crate::{common, domain};
use crate::{
domain,
ui::{self, common},
};

const STORAGE_KEY_SETTINGS: &str = "settings";
const STORAGE_KEY_ONGOING_TRAINING_SESSION: &str = "ongoing training session";
Expand Down Expand Up @@ -1240,9 +1243,9 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
}
Msg::SessionReceived(Ok(new_session)) => {
model.session = Some(new_session);
orders.send_msg(Msg::Refresh).request_url(
crate::Urls::new(model.base_url.clone().set_hash_path([""; 0])).home(),
);
orders
.send_msg(Msg::Refresh)
.request_url(ui::Urls::new(model.base_url.clone().set_hash_path([""; 0])).home());
}
Msg::SessionReceived(Err(message)) => {
model.session = None;
Expand Down Expand Up @@ -1278,7 +1281,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
}
Msg::SessionDeleted(Ok(())) => {
model.session = None;
orders.request_url(crate::Urls::new(&model.base_url).login());
orders.request_url(ui::Urls::new(&model.base_url).login());
}
Msg::SessionDeleted(Err(message)) => {
model
Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions frontend/src/page/admin.rs → frontend/src/ui/page/admin.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use seed::{prelude::*, *};

use crate::common;
use crate::data;
use crate::ui::{self, common, data};

// ------ ------
// Init
// ------ ------

pub fn init(_: Url, orders: &mut impl Orders<Msg>, navbar: &mut crate::Navbar) -> Model {
pub fn init(_: Url, orders: &mut impl Orders<Msg>, navbar: &mut ui::Navbar) -> Model {
orders
.subscribe(Msg::DataEvent)
.notify(data::Msg::ReadVersion)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use chrono::prelude::*;
use seed::{prelude::*, *};

use crate::common;
use crate::data;
use crate::ui::{self, common, data};

// ------ ------
// Init
Expand All @@ -12,7 +11,7 @@ pub fn init(
mut url: Url,
orders: &mut impl Orders<Msg>,
data_model: &data::Model,
navbar: &mut crate::Navbar,
navbar: &mut ui::Navbar,
) -> Model {
if url.next_hash_path_part() == Some("add") {
orders.send_msg(Msg::ShowAddBodyFatDialog);
Expand Down Expand Up @@ -211,7 +210,7 @@ pub fn update(
}
Msg::CloseBodyFatDialog => {
model.dialog = Dialog::Hidden;
Url::go_and_replace(&crate::Urls::new(&data_model.base_url).body_fat());
Url::go_and_replace(&ui::Urls::new(&data_model.base_url).body_fat());
}

Msg::DateChanged(date) => match model.dialog {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use chrono::prelude::*;
use chrono::Duration;
use seed::{prelude::*, *};

use crate::common;
use crate::data;
use crate::ui::{self, common, data};

// ------ ------
// Init
Expand All @@ -16,7 +15,7 @@ pub fn init(
mut url: Url,
orders: &mut impl Orders<Msg>,
data_model: &data::Model,
navbar: &mut crate::Navbar,
navbar: &mut ui::Navbar,
) -> Model {
if url.next_hash_path_part() == Some("add") {
orders.send_msg(Msg::ShowAddBodyWeightDialog);
Expand Down Expand Up @@ -116,7 +115,7 @@ pub fn update(
}
Msg::CloseBodyWeightDialog => {
model.dialog = Dialog::Hidden;
Url::go_and_replace(&crate::Urls::new(&data_model.base_url).body_weight());
Url::go_and_replace(&ui::Urls::new(&data_model.base_url).body_weight());
}

Msg::DateChanged(date) => match model.dialog {
Expand Down
20 changes: 10 additions & 10 deletions frontend/src/page/exercise.rs → frontend/src/ui/page/exercise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::collections::BTreeMap;
use chrono::prelude::*;
use seed::{prelude::*, *};

use crate::common;
use crate::data;
use crate::domain;
use crate::page::training;
use crate::{
domain,
ui::{self, common, data, page::training},
};

// ------ ------
// Init
Expand All @@ -16,7 +16,7 @@ pub fn init(
mut url: Url,
orders: &mut impl Orders<Msg>,
data_model: &data::Model,
navbar: &mut crate::Navbar,
navbar: &mut ui::Navbar,
) -> Model {
let exercise_id = url
.next_hash_path_part()
Expand Down Expand Up @@ -108,7 +108,7 @@ pub fn update(
Msg::EditExercise => {
model.editing = true;
Url::go_and_push(
&crate::Urls::new(&data_model.base_url)
&ui::Urls::new(&data_model.base_url)
.exercise()
.add_hash_path_part(model.exercise_id.to_string())
.add_hash_path_part("edit"),
Expand Down Expand Up @@ -137,7 +137,7 @@ pub fn update(
model.dialog = Dialog::Hidden;
model.loading = false;
Url::go_and_replace(
&crate::Urls::new(&data_model.base_url)
&ui::Urls::new(&data_model.base_url)
.routine()
.add_hash_path_part(model.exercise_id.to_string()),
);
Expand Down Expand Up @@ -189,7 +189,7 @@ pub fn update(
model.editing = false;
model.mark_as_unchanged();
Url::go_and_push(
&crate::Urls::new(&data_model.base_url)
&ui::Urls::new(&data_model.base_url)
.exercise()
.add_hash_path_part(model.exercise_id.to_string()),
);
Expand Down Expand Up @@ -699,15 +699,15 @@ fn view_sets(
C!["mb-2"],
a![
attrs! {
At::Href => crate::Urls::new(base_url).training_session().add_hash_path_part(t.id.to_string()),
At::Href => ui::Urls::new(base_url).training_session().add_hash_path_part(t.id.to_string()),
},
span![style! {St::WhiteSpace => "nowrap" }, t.date.to_string()]
],
raw!["&emsp;"],
if let Some(routine_id) = t.routine_id {
a![
attrs! {
At::Href => crate::Urls::new(base_url).routine().add_hash_path_part(t.routine_id.unwrap().to_string()),
At::Href => ui::Urls::new(base_url).routine().add_hash_path_part(t.routine_id.unwrap().to_string()),
},
match &routines.get(&routine_id) {
Some(routine) => raw![&routine.name],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ use std::collections::BTreeMap;

use seed::{prelude::*, *};

use crate::common;
use crate::component;
use crate::data;
use crate::ui::{self, common, component, data};

// ------ ------
// Init
// ------ ------

pub fn init(mut url: Url, orders: &mut impl Orders<Msg>, navbar: &mut crate::Navbar) -> Model {
pub fn init(mut url: Url, orders: &mut impl Orders<Msg>, navbar: &mut ui::Navbar) -> Model {
if url.next_hash_path_part() == Some("add") {
orders.send_msg(Msg::ShowAddExerciseDialog);
}
Expand Down Expand Up @@ -97,7 +95,7 @@ pub fn update(
}
Msg::CloseExerciseDialog => {
model.dialog = Dialog::Hidden;
Url::go_and_replace(&crate::Urls::new(&data_model.base_url).exercises());
Url::go_and_replace(&ui::Urls::new(&data_model.base_url).exercises());
}

Msg::ExerciseList(msg) => {
Expand Down Expand Up @@ -150,7 +148,7 @@ pub fn update(
},

Msg::GoToExercise(id) => {
let url = crate::Urls::new(&data_model.base_url)
let url = ui::Urls::new(&data_model.base_url)
.exercise()
.add_hash_path_part(id.to_string());
url.go_and_push();
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/page/home.rs → frontend/src/ui/page/home.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use chrono::prelude::*;
use seed::{prelude::*, *};

use crate::{common, data};
use crate::ui::{self, common, data};

// ------ ------
// Init
Expand All @@ -12,7 +12,7 @@ pub fn init(
_url: Url,
_orders: &mut impl Orders<Msg>,
data_model: &data::Model,
navbar: &mut crate::Navbar,
navbar: &mut ui::Navbar,
) -> Model {
navbar
.title
Expand Down Expand Up @@ -136,27 +136,27 @@ pub fn view(_model: &Model, data_model: &data::Model) -> Node<Msg> {
"Training",
&training_subtitle,
&training_content,
crate::Urls::new(&data_model.base_url).training()
ui::Urls::new(&data_model.base_url).training()
),
view_tile(
"Body weight",
&body_weight_subtitle,
&body_weight_content,
crate::Urls::new(&data_model.base_url).body_weight()
ui::Urls::new(&data_model.base_url).body_weight()
),
view_tile(
"Body fat",
&body_fat_subtitle,
&body_fat_content,
crate::Urls::new(&data_model.base_url).body_fat()
ui::Urls::new(&data_model.base_url).body_fat()
),
IF![
data_model.session.as_ref().unwrap().sex == 0 => {
view_tile(
"Menstrual cycle",
&menstrual_cycle_subtitle,
&menstrual_cycle_content,
crate::Urls::new(&data_model.base_url).menstrual_cycle())
ui::Urls::new(&data_model.base_url).menstrual_cycle())
}
],
]
Expand Down
9 changes: 3 additions & 6 deletions frontend/src/page/login.rs → frontend/src/ui/page/login.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
use seed::{prelude::*, *};

use crate::common;
use crate::data;
use crate::ui::{self, common, data};

// ------ ------
// Init
// ------ ------

pub fn init(url: Url, orders: &mut impl Orders<Msg>, navbar: &mut crate::Navbar) -> Model {
pub fn init(url: Url, orders: &mut impl Orders<Msg>, navbar: &mut ui::Navbar) -> Model {
orders.notify(data::Msg::ReadUsers);

navbar.title = String::from("Valens");
navbar.items = vec![(
ev(Ev::Click, move |_| {
crate::Urls::new(url.to_hash_base_url())
.admin()
.go_and_load();
ui::Urls::new(url.to_hash_base_url()).admin().go_and_load();
}),
String::from("gears"),
)];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use chrono::prelude::*;
use seed::{prelude::*, *};

use crate::common;
use crate::data;
use crate::ui::{self, common, data};

// ------ ------
// Init
Expand All @@ -12,7 +11,7 @@ pub fn init(
mut url: Url,
orders: &mut impl Orders<Msg>,
data_model: &data::Model,
navbar: &mut crate::Navbar,
navbar: &mut ui::Navbar,
) -> Model {
if url.next_hash_path_part() == Some("add") {
orders.send_msg(Msg::ShowAddPeriodDialog);
Expand Down Expand Up @@ -112,7 +111,7 @@ pub fn update(
}
Msg::ClosePeriodDialog => {
model.dialog = Dialog::Hidden;
Url::go_and_replace(&crate::Urls::new(&data_model.base_url).menstrual_cycle());
Url::go_and_replace(&ui::Urls::new(&data_model.base_url).menstrual_cycle());
}

Msg::DateChanged(date) => match model.dialog {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use chrono::prelude::*;
use seed::{prelude::*, *};

use crate::common;
use crate::data;
use crate::domain;
use crate::{
domain,
ui::{self, common, data},
};

// ------ ------
// Init
// ------ ------

pub fn init(data_model: &data::Model, navbar: &mut crate::Navbar) -> Model {
pub fn init(data_model: &data::Model, navbar: &mut ui::Navbar) -> Model {
navbar.title = String::from("Muscles");

Model {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use seed::prelude::*;

use crate::common;
use crate::ui::common;

pub fn view<Ms>() -> Node<Ms> {
common::view_error_not_found("Page")
Expand Down
Loading

0 comments on commit 8f81c13

Please sign in to comment.