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