Skip to content

Commit

Permalink
feat: show current org
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenLoc committed Dec 15, 2024
1 parent d6bcf58 commit 135c9b2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/github/organization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ impl Organization {
}
}

pub fn name(&self) -> &str {
&self.name
pub fn name(&self) -> String {
self.name.clone()
}
}

Expand Down
16 changes: 13 additions & 3 deletions src/view/nav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ use crate::{
#[get("/nav")]
pub async fn get(state: &State<AppState>) -> content::RawHtml<String> {
let orgs = state.fetch_organizations().await;
let current_name = match state.current_org().await {
Some(o) => o.name(),
None => {
let co = orgs.clone();
co.first()
.map(|f| f.name())
.unwrap_or("No organization found".to_string())
}
};

let raw = html! {
nav {
ul {
Expand All @@ -31,7 +41,7 @@ pub async fn get(state: &State<AppState>) -> content::RawHtml<String> {
li { (nav_button_with_class("Dashboard", "/dashboard", "outline")) }
li{

(org_selection(orgs))
(org_selection(orgs, current_name))

}
}
Expand All @@ -49,10 +59,10 @@ fn org_option(org: String) -> Markup {
}
}

pub fn org_selection(orgs: Vec<Organization>) -> Markup {
pub fn org_selection(orgs: Vec<Organization>, first: String) -> Markup {
html! {
select name="org" aria-label="Select" hx-post="/org_changed" hx-swap="outerHTML" {
option selected disabled value="" { ("Org") }
option selected disabled value="" { (first) }
@for org in orgs {
(org_option(org.name().to_string()))
}
Expand Down
2 changes: 1 addition & 1 deletion src/view/org_changed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub async fn changed(

let clone_orgs = orgs.clone();

let o = org_selection(clone_orgs);
let o = org_selection(clone_orgs, org.clone());

HXResponder {
inner: content::RawHtml(o.into_string()),
Expand Down

0 comments on commit 135c9b2

Please sign in to comment.