Skip to main content

logicaffeine_web/ui/
app.rs

1//! Root application component and global styles.
2//!
3//! This module defines the top-level Dioxus component that bootstraps the
4//! application, sets up global context providers, and injects CSS styles.
5//!
6//! # Context Providers
7//!
8//! The [`App`] component provides these global contexts:
9//! - [`RegistryAuthState`] - GitHub authentication for package registry
10//!
11//! # Global Styles
12//!
13//! CSS custom properties (design tokens) are injected at the root level,
14//! making them available throughout the component tree via `var(--name)`.
15//!
16//! # Routing
17//!
18//! The app uses Dioxus Router with routes defined in [`crate::ui::router::Route`].
19
20use crate::ui::router::Route;
21use crate::ui::state::RegistryAuthState;
22use dioxus::prelude::*;
23
24/// Global CSS including design tokens, reset styles, and common component styles.
25const GLOBAL_STYLE: &str = r#"
26:root {
27    /* Primary colors */
28    --color-primary-blue: #667eea;
29    --color-primary-purple: #764ba2;
30    --color-accent-blue: #60a5fa;
31    --color-accent-purple: #a78bfa;
32
33    /* Semantic colors */
34    --color-success: #4ade80;
35    --color-warning: #f59e0b;
36    --color-error: #e06c75;
37    --color-info: #60a5fa;
38
39    /* Palette: the page background and the two accents */
40    --bg-gradient-start: #09090b;
41    --bg-gradient-mid: #0c0c10;
42    --bg-gradient-end: #09090b;
43    --accent-primary: #00d4ff;
44    --accent-secondary: #818cf8;
45    --accent-tertiary: #f0f0f0;
46    --accent-primary-rgb: 0, 212, 255;
47    --accent-secondary-rgb: 129, 140, 248;
48    --accent-border: rgba(0, 212, 255, 0.3);
49    --accent-glow: rgba(0, 212, 255, 0.2);
50
51    /* Text colors - MUCH lighter for readability */
52    --text-primary: #f5f5f5;
53    --text-secondary: #d0d0d0;
54    --text-tertiary: #b8b8b8;
55    --text-muted: #c0c0c0;
56    --text-placeholder: #a0a0a0;
57
58    /* Font sizes - minimum 14px for readability */
59    --font-display-xl: 66px;
60    --font-display-lg: 50px;
61    --font-display-md: 34px;
62    --font-heading-lg: 26px;
63    --font-heading-md: 22px;
64    --font-heading-sm: 20px;
65    --font-body-lg: 18px;
66    --font-body-md: 16px;
67    --font-body-sm: 15px;
68    --font-caption-lg: 15px;
69    --font-caption-md: 14px;
70    --font-caption-sm: 14px;
71
72    /* Font families */
73    --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
74    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
75
76    /* Spacing */
77    --spacing-xs: 4px;
78    --spacing-sm: 8px;
79    --spacing-md: 12px;
80    --spacing-lg: 16px;
81    --spacing-xl: 24px;
82    --spacing-xxl: 32px;
83
84    /* Border radius */
85    --radius-sm: 4px;
86    --radius-md: 8px;
87    --radius-lg: 12px;
88    --radius-xl: 16px;
89    --radius-full: 9999px;
90}
91
92* {
93    margin: 0;
94    padding: 0;
95    box-sizing: border-box;
96}
97
98html, body {
99    height: 100%;
100    background: linear-gradient(
101        135deg,
102        var(--bg-gradient-start) 0%,
103        var(--bg-gradient-mid) 50%,
104        var(--bg-gradient-end) 100%
105    );
106    color: var(--text-primary);
107    font-family: var(--font-sans);
108    font-size: var(--font-body-lg);
109    overflow-x: hidden;
110}
111
112#main {
113    min-height: 100vh;
114}
115
116a {
117    color: inherit;
118    text-decoration: none;
119}
120
121.chat-area {
122    flex: 1;
123    overflow-y: auto;
124    padding: 30px;
125    display: flex;
126    flex-direction: column;
127    gap: var(--spacing-lg);
128}
129
130.message {
131    max-width: 75%;
132    padding: 14px 20px;
133    border-radius: var(--radius-xl);
134    line-height: 1.6;
135    animation: fadeIn 0.3s ease;
136}
137
138@keyframes fadeIn {
139    from { opacity: 0; transform: translateY(10px); }
140    to { opacity: 1; transform: translateY(0); }
141}
142
143.message.user {
144    align-self: flex-end;
145    background: linear-gradient(135deg, var(--color-primary-blue) 0%, var(--color-primary-purple) 100%);
146    color: white;
147    border-bottom-right-radius: var(--radius-sm);
148    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
149}
150
151.message.system {
152    align-self: flex-start;
153    background: rgba(255, 255, 255, 0.08);
154    border: 1px solid rgba(255, 255, 255, 0.15);
155    border-bottom-left-radius: var(--radius-sm);
156    font-family: var(--font-mono);
157    font-size: var(--font-heading-sm);
158    color: var(--accent-primary);
159    text-shadow: 0 0 20px var(--accent-glow);
160}
161
162.message.error {
163    align-self: flex-start;
164    background: linear-gradient(135deg, #ff6b6b 0%, #c92a2a 100%);
165    color: white;
166    border-bottom-left-radius: var(--radius-sm);
167    font-style: italic;
168    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
169}
170
171.input-area {
172    background: rgba(0, 0, 0, 0.4);
173    backdrop-filter: blur(10px);
174    padding: 20px 30px;
175    border-top: 1px solid rgba(255, 255, 255, 0.1);
176}
177
178.input-row {
179    display: flex;
180    gap: var(--spacing-md);
181    align-items: center;
182}
183
184.input-row input {
185    flex: 1;
186    background: rgba(255, 255, 255, 0.08);
187    border: 1px solid rgba(255, 255, 255, 0.2);
188    border-radius: var(--radius-lg);
189    padding: 14px 20px;
190    font-size: var(--font-body-lg);
191    color: white;
192    outline: none;
193    transition: all 0.2s ease;
194}
195
196.input-row input::placeholder {
197    color: var(--text-placeholder);
198}
199
200.input-row input:focus {
201    border-color: var(--color-primary-blue);
202    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
203}
204
205.input-row button {
206    background: linear-gradient(135deg, var(--color-primary-blue) 0%, var(--color-primary-purple) 100%);
207    border: none;
208    border-radius: var(--radius-lg);
209    padding: 14px 28px;
210    font-size: var(--font-body-lg);
211    font-weight: 600;
212    color: white;
213    cursor: pointer;
214    transition: all 0.2s ease;
215    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
216}
217
218.input-row button:hover {
219    transform: translateY(-2px);
220    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
221}
222
223.input-row button:active {
224    transform: translateY(0);
225}
226
227/* Accents. These components still hardcode colours of their own; the rules below paint
228   them from the palette, which is why they carry !important. */
229.main-nav-link.active::after {
230    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary)) !important;
231}
232
233.btn-primary,
234.main-nav-btn.primary {
235    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary)) !important;
236    box-shadow: 0 12px 30px rgba(var(--accent-primary-rgb), 0.18) !important;
237}
238
239.btn-primary:hover,
240.main-nav-btn.primary:hover {
241    box-shadow: 0 16px 40px rgba(var(--accent-primary-rgb), 0.25) !important;
242}
243
244.mobile-nav-item.active,
245.mobile-nav-link.active {
246    background: rgba(var(--accent-primary-rgb), 0.12) !important;
247    color: var(--accent-primary) !important;
248}
249
250input:focus,
251textarea:focus {
252    box-shadow: 0 0 0 3px rgba(var(--accent-primary-rgb), 0.3);
253    border-color: var(--accent-primary);
254}
255
256.badge .dot {
257    background: var(--accent-primary) !important;
258    box-shadow: 0 0 0 6px rgba(var(--accent-primary-rgb), 0.12) !important;
259}
260
261.card:hover {
262    border-color: rgba(var(--accent-secondary-rgb), 0.28) !important;
263}
264
265.card:hover::before {
266    background: linear-gradient(135deg, rgba(var(--accent-primary-rgb), 0.12), rgba(var(--accent-secondary-rgb), 0.12)) !important;
267}
268
269.icon-box {
270    background: rgba(var(--accent-primary-rgb), 0.15) !important;
271}
272
273.code.logic {
274    color: var(--accent-secondary) !important;
275}
276"#;
277
278/// Root application component.
279///
280/// Sets up the registry authentication context and renders the router.
281///
282/// # Context Providers
283///
284/// - [`RegistryAuthState`] - Manages GitHub OAuth for package registry
285pub fn App() -> Element {
286    let _registry_auth = use_context_provider(RegistryAuthState::new);
287
288    rsx! {
289        style { "{GLOBAL_STYLE}" }
290        div {
291            id: "app-root",
292            // No explicit SuspenseBoundary: lazy route chunks suspend against
293            // the implicit root boundary (the wasm-split harness shape). The
294            // CSR takeover that swaps out the prerendered copy watches this
295            // element's content from outside — see the poll in index.html.
296            Router::<Route> {}
297        }
298    }
299}