Skip to content

Commit

Permalink
feat: show orgs
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenLoc committed Dec 11, 2024
1 parent 98716ae commit e58e2c6
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 4 deletions.
Binary file modified assets/candle.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/small_candle.jpeg
Binary file not shown.
1 change: 1 addition & 0 deletions src/github/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod organization;
16 changes: 16 additions & 0 deletions src/github/organization.rs
Original file line number Diff line number Diff line change
@@ -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
}
}
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use rocket::{Build, Rocket};
extern crate rocket;

mod assets;
mod github;
mod remote;
mod state;
mod view;

#[launch]
Expand All @@ -26,5 +29,6 @@ fn mount(rocket: Rocket<Build>) -> Rocket<Build> {
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)
}
9 changes: 9 additions & 0 deletions src/remote/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use crate::github::organization::Organization;

pub async fn get_organizations() -> Vec<Organization> {
let organizations = vec![
Organization::new("rust-lang"),
Organization::new("rust-lang-nursery"),
];
organizations
}
42 changes: 42 additions & 0 deletions src/state/mod.rs
Original file line number Diff line number Diff line change
@@ -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<Organization>,
}

impl GithubState {
pub async fn fetch_organizations(&mut self) -> Vec<Organization> {
let orgs = remote::get_organizations().await;
self.organizations = orgs;
self.organizations.clone()
}
}

pub struct AppState {
pub github: Arc<RwLock<GithubState>>,
}

impl AppState {
pub fn new() -> Self {
Self {
github: Arc::new(RwLock::new(GithubState {
organizations: vec![],
})),
}
}

pub async fn fetch_organizations(&self) -> Vec<Organization> {
self.github.write().await.fetch_organizations().await
}
}

pub fn mount_state(rocket: Rocket<Build>) -> Rocket<Build> {
let state = AppState::new();

rocket.manage(state)
}
17 changes: 14 additions & 3 deletions src/view/dashboard.rs
Original file line number Diff line number Diff line change
@@ -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<String> {
pub async fn get(state: &State<AppState>) -> content::RawHtml<String> {
let orgs = state.fetch_organizations().await;

let raw = html! {


Expand All @@ -18,8 +22,15 @@ pub fn get() -> content::RawHtml<String> {
body{
div {
// GitHub
h3 { "GitHub" }
h3 { "Organizations" }
ul {
@for org in orgs {
li { (org.name()) }
}
}
}


}


Expand Down
4 changes: 4 additions & 0 deletions src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const CSS: &str = r#"<link rel="stylesheet" href="_assets/app.css">"#;
const PICO_EXT: &str = r#"<link rel="stylesheet" href="_assets/pico_ext.css">"#;
const HTMX: &str = r#"<script src="/_assets/htmx.min.js"></script>"#;
const PICO: &str = r#"<link rel="stylesheet" href="_assets/pico.violet.min.css">"#;
const ICON: &str =
r#"<link rel="icon" type="image/x-icon" href="https://i.ibb.co/RDThxRB/favicon-32x32.png">"#;

pub fn page(markup: Markup) -> Markup {
html! {
Expand All @@ -35,6 +37,7 @@ pub fn page(markup: Markup) -> Markup {
head {
({scripts()})
({title("Candle")})

}

body class="container" {
Expand All @@ -50,6 +53,7 @@ fn scripts() -> Markup {
(PreEscaped(HTMX))
(PreEscaped(PICO_EXT))
(PreEscaped(PICO))
(PreEscaped(ICON))
}
}

Expand Down

0 comments on commit e58e2c6

Please sign in to comment.