| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | use topcoat::{ |
| 8 | Result, |
| 9 | context::Cx, |
| 10 | router::{ |
| 11 | error::{RouterErrorExt, not_found}, |
| 12 | page, path_param, |
| 13 | }, |
| 14 | view::view, |
| 15 | }; |
| 16 | |
| 17 | use crate::{ |
| 18 | application::{PublicProfile, view_profile}, |
| 19 | domain::OrgName, |
| 20 | }; |
| 21 | |
| 22 | use super::context::{current_actor, memberships, orgs, server_error}; |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | #[path_param] |
| 30 | struct Handle(str); |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | pub(super) async fn profile_for(cx: &Cx) -> Result<PublicProfile> { |
| 37 | let raw = path_param::<Handle>(cx); |
| 38 | let handle = OrgName::new(raw).map_err(|_| not_found())?; |
| 39 | let actor = current_actor(cx).await?; |
| 40 | |
| 41 | Ok(view_profile(&handle, &actor, &orgs(cx), &memberships(cx)) |
| 42 | .await |
| 43 | .map_err(server_error)? |
| 44 | .ok_or_not_found()?) |
| 45 | } |
| 46 | |
| 47 | #[page("/{handle}")] |
| 48 | async fn profile(cx: &Cx) -> Result { |
| 49 | let profile = profile_for(cx).await?; |
| 50 | |
| 51 | view! { |
| 52 | <header> |
| 53 | <h1>(&profile.label)</h1> |
| 54 | <p><code>"@" (profile.handle.as_str())</code></p> |
| 55 | ({ |
| 56 | match &profile.bio { |
| 57 | Some(bio) => view! { <p>(bio)</p> }, |
| 58 | None => view! {}, |
| 59 | } |
| 60 | }?) |
| 61 | ({ |
| 62 | if profile.viewer_is_owner { |
| 63 | view! { |
| 64 | <p><a href=(format!("/{}/settings", profile.handle))>"Edit profile"</a></p> |
| 65 | } |
| 66 | } else { |
| 67 | view! {} |
| 68 | } |
| 69 | }?) |
| 70 | </header> |
| 71 | |
| 72 | <section> |
| 73 | <h2>"Repositories"</h2> |
| 74 | <p>"Nothing here yet."</p> |
| 75 | </section> |
| 76 | |
| 77 | <section> |
| 78 | <h2>"Writing"</h2> |
| 79 | <p>"Nothing here yet."</p> |
| 80 | </section> |
| 81 | |
| 82 | <section> |
| 83 | <h2>"Projects"</h2> |
| 84 | <p>"Nothing here yet."</p> |
| 85 | </section> |
| 86 | } |
| 87 | } |