diff --git a/assets/candle.jpeg b/assets/candle.jpeg index ff33022..5083f1d 100644 Binary files a/assets/candle.jpeg and b/assets/candle.jpeg differ diff --git a/assets/small_candle.jpeg b/assets/small_candle.jpeg deleted file mode 100644 index 5083f1d..0000000 Binary files a/assets/small_candle.jpeg and /dev/null differ diff --git a/src/github/mod.rs b/src/github/mod.rs new file mode 100644 index 0000000..0449b25 --- /dev/null +++ b/src/github/mod.rs @@ -0,0 +1 @@ +pub mod organization; diff --git a/src/github/organization.rs b/src/github/organization.rs new file mode 100644 index 0000000..82ae360 --- /dev/null +++ b/src/github/organization.rs @@ -0,0 +1,16 @@ +#[derive(Debug, Clone)] +pub struct Organization { + name: String, +} + +impl Organization { + pub fn new(name: &str) -> Self { + Self { + name: name.to_string(), + } + } + + pub fn name(&self) -> &str { + &self.name + } +} diff --git a/src/main.rs b/src/main.rs index 093bcca..10436a2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,9 @@ use rocket::{Build, Rocket}; extern crate rocket; mod assets; +mod github; +mod remote; +mod state; mod view; #[launch] @@ -26,5 +29,6 @@ fn mount(rocket: Rocket) -> Rocket { routes![view::index, view::nav::get, view::dashboard::get,], ); - assets::mount_assets(with_index) + let rocket = assets::mount_assets(with_index); + state::mount_state(rocket) } diff --git a/src/remote/mod.rs b/src/remote/mod.rs new file mode 100644 index 0000000..e1fb63b --- /dev/null +++ b/src/remote/mod.rs @@ -0,0 +1,9 @@ +use crate::github::organization::Organization; + +pub async fn get_organizations() -> Vec { + let organizations = vec![ + Organization::new("rust-lang"), + Organization::new("rust-lang-nursery"), + ]; + organizations +} diff --git a/src/state/mod.rs b/src/state/mod.rs new file mode 100644 index 0000000..b96dff0 --- /dev/null +++ b/src/state/mod.rs @@ -0,0 +1,42 @@ +use std::sync::Arc; + +use rocket::tokio::sync::RwLock; +use rocket::{Build, Rocket}; + +use crate::{github::organization::Organization, remote}; + +pub struct GithubState { + organizations: Vec, +} + +impl GithubState { + pub async fn fetch_organizations(&mut self) -> Vec { + let orgs = remote::get_organizations().await; + self.organizations = orgs; + self.organizations.clone() + } +} + +pub struct AppState { + pub github: Arc>, +} + +impl AppState { + pub fn new() -> Self { + Self { + github: Arc::new(RwLock::new(GithubState { + organizations: vec![], + })), + } + } + + pub async fn fetch_organizations(&self) -> Vec { + self.github.write().await.fetch_organizations().await + } +} + +pub fn mount_state(rocket: Rocket) -> Rocket { + let state = AppState::new(); + + rocket.manage(state) +} diff --git a/src/view/dashboard.rs b/src/view/dashboard.rs index 28f089d..6dec74a 100644 --- a/src/view/dashboard.rs +++ b/src/view/dashboard.rs @@ -1,8 +1,12 @@ use maud::html; -use rocket::response::content; +use rocket::{response::content, State}; + +use crate::state::AppState; #[get("/dashboard")] -pub fn get() -> content::RawHtml { +pub async fn get(state: &State) -> content::RawHtml { + let orgs = state.fetch_organizations().await; + let raw = html! { @@ -18,8 +22,15 @@ pub fn get() -> content::RawHtml { body{ div { // GitHub - h3 { "GitHub" } + h3 { "Organizations" } + ul { + @for org in orgs { + li { (org.name()) } + } + } } + + } diff --git a/src/view/mod.rs b/src/view/mod.rs index e0f47be..c3c691a 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -27,6 +27,8 @@ const CSS: &str = r#""#; const PICO_EXT: &str = r#""#; const HTMX: &str = r#""#; const PICO: &str = r#""#; +const ICON: &str = + r#""#; pub fn page(markup: Markup) -> Markup { html! { @@ -35,6 +37,7 @@ pub fn page(markup: Markup) -> Markup { head { ({scripts()}) ({title("Candle")}) + } body class="container" { @@ -50,6 +53,7 @@ fn scripts() -> Markup { (PreEscaped(HTMX)) (PreEscaped(PICO_EXT)) (PreEscaped(PICO)) + (PreEscaped(ICON)) } }