Skip to main content

flow_server/routes/
theme.rs

1use crate::{error::AppResult, state::AppState};
2use axum::{extract::State, response::Json};
3use flow_core::Theme;
4use serde::{Deserialize, Serialize};
5use std::sync::Arc;
6
7#[derive(Debug, Serialize)]
8#[serde(rename_all = "camelCase")]
9pub struct ThemeColorsWeb {
10    primary: String,
11    secondary: String,
12    background: String,
13    foreground: String,
14}
15
16#[derive(Debug, Serialize)]
17#[serde(rename_all = "camelCase")]
18pub struct ThemeResponse {
19    theme: String,
20    colors: ThemeColorsWeb,
21}
22
23#[derive(Debug, Deserialize)]
24pub struct SetThemeRequest {
25    theme: String,
26}
27
28/// GET /api/theme — Return current theme name and CSS variables
29pub async fn get_theme(
30    State(_state): State<Arc<AppState>>,
31) -> AppResult<Json<ThemeResponse>> {
32    // Default to aurora theme for now
33    // In the future, this could read from a config file or database
34    let theme = Theme::Aurora;
35    let theme_colors = theme.colors();
36
37    Ok(Json(ThemeResponse {
38        theme: "aurora".to_string(),
39        colors: ThemeColorsWeb {
40            primary: theme_colors.css_primary.to_string(),
41            secondary: theme_colors.css_secondary.to_string(),
42            background: theme_colors.css_background.to_string(),
43            foreground: theme_colors.css_foreground.to_string(),
44        },
45    }))
46}
47
48/// POST /api/theme — Set theme (accepts {"theme": "aurora"})
49pub async fn set_theme(
50    State(_state): State<Arc<AppState>>,
51    Json(request): Json<SetThemeRequest>,
52) -> AppResult<Json<ThemeResponse>> {
53    // Parse the theme name
54    let theme = match request.theme.as_str() {
55        "default" => Theme::Default,
56        "claude" => Theme::Claude,
57        "twitter" => Theme::Twitter,
58        "neo-brutalism" => Theme::NeoBrutalism,
59        "retro-arcade" => Theme::RetroArcade,
60        "business" => Theme::Business,
61        _ => Theme::Aurora, // Default fallback (including "aurora")
62    };
63
64    // In the future, persist the theme choice to config/database
65    let theme_colors = theme.colors();
66
67    Ok(Json(ThemeResponse {
68        theme: request.theme,
69        colors: ThemeColorsWeb {
70            primary: theme_colors.css_primary.to_string(),
71            secondary: theme_colors.css_secondary.to_string(),
72            background: theme_colors.css_background.to_string(),
73            foreground: theme_colors.css_foreground.to_string(),
74        },
75    }))
76}