| 1 | use topcoat::{ |
| 2 | Result, |
| 3 | context::Cx, |
| 4 | router::layout, |
| 5 | tailwind, |
| 6 | view::{View, component, view}, |
| 7 | }; |
| 8 | |
| 9 | use crate::application::Identity; |
| 10 | |
| 11 | use super::context::identity; |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | #[layout("/")] |
| 27 | async fn root_layout(cx: &Cx, slot: Result) -> Result { |
| 28 | let content = slot?; |
| 29 | let viewer = identity(cx).await?; |
| 30 | |
| 31 | view! { |
| 32 | <!DOCTYPE html> |
| 33 | <html lang="en" class="dark"> |
| 34 | <head> |
| 35 | <meta charset="utf-8" /> |
| 36 | <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 37 | <title>"steid"</title> |
| 38 | <link rel="stylesheet" href=(tailwind::stylesheet!()) /> |
| 39 | topcoat::dev::script() |
| 40 | </head> |
| 41 | <body> |
| 42 | top_bar(viewer: &viewer) |
| 43 | <main class="px-6 py-10">(content)</main> |
| 44 | </body> |
| 45 | </html> |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | #[component] |
| 58 | async fn top_bar(viewer: &Option<Identity>) -> Result { |
| 59 | view! { |
| 60 | <header class="border-b border-border"> |
| 61 | <div class="flex h-11 items-center px-6 text-[13px]"> |
| 62 | <a href="/" class="font-mono font-semibold tracking-tight">"steid"</a> |
| 63 | <div class="ml-auto flex items-center gap-5"> |
| 64 | match viewer { |
| 65 | Some(me) => { |
| 66 | <a |
| 67 | href=(format!("/{}", me.handle)) |
| 68 | class="font-mono text-muted-foreground hover:text-foreground" |
| 69 | >"@" (me.handle.as_str())</a> |
| 70 | <a |
| 71 | href=(format!("/{}/settings", me.handle)) |
| 72 | class="text-muted-foreground hover:text-foreground" |
| 73 | >"Settings"</a> |
| 74 | <form method="post" action="/auth/logout"> |
| 75 | <button |
| 76 | type="submit" |
| 77 | class="cursor-pointer text-muted-foreground hover:text-foreground" |
| 78 | >"Sign out"</button> |
| 79 | </form> |
| 80 | } |
| 81 | None => { |
| 82 | <a |
| 83 | href="/auth/login" |
| 84 | class="text-muted-foreground hover:text-foreground" |
| 85 | >"Sign in"</a> |
| 86 | } |
| 87 | } |
| 88 | </div> |
| 89 | </div> |
| 90 | </header> |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | |
| 95 | #[component] |
| 96 | pub(super) async fn narrow(#[default] child: View) -> Result { |
| 97 | view! { <div class="mx-auto w-full max-w-3xl">(child)</div> } |
| 98 | } |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | #[component] |
| 105 | pub(super) async fn wide(#[default] child: View) -> Result { |
| 106 | view! { <div class="mx-auto w-full max-w-screen-xl">(child)</div> } |
| 107 | } |