steid

@jamesgill /

1use topcoat::{
2 Result,
3 context::Cx,
4 router::{layout, uri},
5 tailwind,
6 view::{View, component, view},
7};
8
9use crate::application::Identity;
10
11use super::{atom, context::identity};
12
13/// The HTML shell every page renders inside.
14///
15/// A layout rather than a helper function: `view!` needs the request context in scope,
16/// so a plain `fn shell(..)` cannot build one. Layouts wrap by path prefix, and this
17/// one is at `/`, so it wraps everything.
18///
19/// `class="dark"` opts the whole document into the dark palette. Steid is dark-first —
20/// developers live there — and light mode is a later toggle rather than the default.
21///
22/// The shell imposes no width: prose-shaped pages wrap themselves in [`narrow`] and
23/// code-shaped ones in [`wide`], because a repository tree and a settings form do not
24/// want the same column. A page that forgets a container renders full-bleed, which is
25/// immediately visible — the same reasoning as request helpers being functions.
26#[layout("/")]
27async fn root_layout(cx: &Cx, slot: Result) -> Result {
28 let content = slot?;
29 let viewer = identity(cx).await?;
30 // Feed autodiscovery is derived from the request's path rather than contributed by
31 // the page. Only a *layer* may put a value on the request context, so a page has
32 // nowhere to leave one for the layout to pick up — see `atom::discovered`, which
33 // holds the knowledge of which URLs have feeds, with tests.
34 let feed = atom::discovered(uri(cx).path());
35
36 view! {
37 <!DOCTYPE html>
38 <html lang="en" class="dark">
39 <head>
40 <meta charset="utf-8" />
41 <meta name="viewport" content="width=device-width, initial-scale=1" />
42 <title>"steid"</title>
43 <link rel="stylesheet" href=(tailwind::stylesheet!()) />
44 match &feed {
45 Some((href, title)) => <link
46 rel="alternate"
47 type="application/atom+xml"
48 title=(title.as_str())
49 href=(href.as_str())
50 />,
51 None => "",
52 }
53 topcoat::dev::script()
54 </head>
55 <body>
56 top_bar(viewer: &viewer)
57 <main class="px-6 py-10">(content)</main>
58 </body>
59 </html>
60 }
61}
62
63/// The one-line global bar: where you are signed in, or the way in.
64///
65/// Deliberately not an app shell. Steid's visitors are anonymous readers of someone's
66/// site, so the chrome stays a slim bar and real navigation lives with the thing being
67/// navigated — the profile's tab bar, the repository's — rather than in a global rail.
68///
69/// Everything on the signed-in side is owner furniture; a visitor sees only "Sign in",
70/// and the wordmark, which goes to `/` — the owner's profile, by the front-door rule.
71#[component]
72async fn top_bar(viewer: &Option<Identity>) -> Result {
73 view! {
74 <header class="border-b border-border">
75 <div class="flex h-11 items-center px-6 text-[13px]">
76 <a href="/" class="font-mono font-semibold tracking-tight">"steid"</a>
77 <div class="ml-auto flex items-center gap-5">
78 match viewer {
79 Some(me) => {
80 <a
81 href=(format!("/{}", me.handle))
82 class="font-mono text-muted-foreground hover:text-foreground"
83 >"@" (me.handle.as_str())</a>
84 <a
85 href=(format!("/{}/settings", me.handle))
86 class="text-muted-foreground hover:text-foreground"
87 >"Settings"</a>
88 <form method="post" action="/auth/logout">
89 <button
90 type="submit"
91 class="cursor-pointer text-muted-foreground hover:text-foreground"
92 >"Sign out"</button>
93 </form>
94 }
95 None => {
96 <a
97 href="/auth/login"
98 class="text-muted-foreground hover:text-foreground"
99 >"Sign in"</a>
100 }
101 }
102 </div>
103 </div>
104 </header>
105 }
106}
107
108/// The centered column for prose-shaped pages: profiles, forms, settings, writing.
109#[component]
110pub(super) async fn narrow(#[default] child: View) -> Result {
111 view! { <div class="mx-auto w-full max-w-3xl">(child)</div> }
112}
113
114/// The full working width for code-shaped pages: trees, blobs, logs.
115///
116/// Info density is the point — a file view in a 48rem column wastes the screen the
117/// reader sized their window to.
118#[component]
119pub(super) async fn wide(#[default] child: View) -> Result {
120 view! { <div class="mx-auto w-full max-w-screen-xl">(child)</div> }
121}