| 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, list_repos, view_profile}, |
| 19 | components::button::{ButtonSize, ButtonVariant, button_variants}, |
| 20 | domain::OrgName, |
| 21 | }; |
| 22 | |
| 23 | use super::{ |
| 24 | context::{current_actor, memberships, orgs, repos, server_error}, |
| 25 | repo::repo_list, |
| 26 | }; |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | #[path_param] |
| 34 | struct Handle(str); |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | pub(super) fn handle_param(cx: &Cx) -> Result<OrgName> { |
| 44 | Ok(OrgName::new(path_param::<Handle>(cx)).map_err(|_| not_found())?) |
| 45 | } |
| 46 | |
| 47 | |
| 48 | pub(super) async fn profile_for(cx: &Cx) -> Result<PublicProfile> { |
| 49 | let handle = handle_param(cx)?; |
| 50 | let actor = current_actor(cx).await?; |
| 51 | |
| 52 | Ok(view_profile(&handle, &actor, &orgs(cx), &memberships(cx)) |
| 53 | .await |
| 54 | .map_err(server_error)? |
| 55 | .ok_or_not_found()?) |
| 56 | } |
| 57 | |
| 58 | #[page("/{handle}")] |
| 59 | async fn profile(cx: &Cx) -> Result { |
| 60 | let profile = profile_for(cx).await?; |
| 61 | |
| 62 | |
| 63 | |
| 64 | let listed = list_repos( |
| 65 | &profile.handle, |
| 66 | ¤t_actor(cx).await?, |
| 67 | &orgs(cx), |
| 68 | &memberships(cx), |
| 69 | &repos(cx), |
| 70 | ) |
| 71 | .await |
| 72 | .map_err(server_error)? |
| 73 | .unwrap_or_default(); |
| 74 | |
| 75 | view! { |
| 76 | <header class="mb-10"> |
| 77 | <h1 class="text-2xl font-semibold tracking-tight">(&profile.label)</h1> |
| 78 | <p class="mt-1 font-mono text-sm text-muted-foreground"> |
| 79 | "@" (profile.handle.as_str()) |
| 80 | </p> |
| 81 | ({ |
| 82 | match &profile.bio { |
| 83 | Some(bio) => view! { <p class="mt-3 text-sm leading-relaxed">(bio)</p> }, |
| 84 | None => view! {}, |
| 85 | } |
| 86 | }?) |
| 87 | ({ |
| 88 | if profile.viewer_is_owner { |
| 89 | view! { |
| 90 | <p class="mt-4"> |
| 91 | <a |
| 92 | href=(format!("/{}/settings", profile.handle)) |
| 93 | class=(button_variants(ButtonVariant::Outline, ButtonSize::Sm)) |
| 94 | >"Edit profile"</a> |
| 95 | </p> |
| 96 | } |
| 97 | } else { |
| 98 | view! {} |
| 99 | } |
| 100 | }?) |
| 101 | </header> |
| 102 | |
| 103 | <section class="mt-8"> |
| 104 | <div class="flex items-center justify-between"> |
| 105 | <h2 class="text-xs font-medium uppercase tracking-wider text-muted-foreground"> |
| 106 | "Repositories" |
| 107 | </h2> |
| 108 | if profile.viewer_is_owner { |
| 109 | <a |
| 110 | href=(format!("/{}/repos/new", profile.handle)) |
| 111 | class=(button_variants(ButtonVariant::Outline, ButtonSize::Sm)) |
| 112 | >"New repository"</a> |
| 113 | } |
| 114 | </div> |
| 115 | repo_list(handle: profile.handle.as_str(), repos: &listed) |
| 116 | </section> |
| 117 | |
| 118 | <section class="mt-8"> |
| 119 | <h2 class="text-xs font-medium uppercase tracking-wider text-muted-foreground"> |
| 120 | "Writing" |
| 121 | </h2> |
| 122 | <p class="mt-2 rounded-lg border border-border px-4 py-6 text-center text-sm text-muted-foreground"> |
| 123 | "Nothing here yet." |
| 124 | </p> |
| 125 | </section> |
| 126 | |
| 127 | <section class="mt-8"> |
| 128 | <h2 class="text-xs font-medium uppercase tracking-wider text-muted-foreground"> |
| 129 | "Projects" |
| 130 | </h2> |
| 131 | <p class="mt-2 rounded-lg border border-border px-4 py-6 text-center text-sm text-muted-foreground"> |
| 132 | "Nothing here yet." |
| 133 | </p> |
| 134 | </section> |
| 135 | } |
| 136 | } |