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(State(_state): State<Arc<AppState>>) -> AppResult<Json<ThemeResponse>> {
30    // Default to aurora theme for now
31    // In the future, this could read from a config file or database
32    let theme = Theme::Aurora;
33    let theme_colors = theme.colors();
34
35    Ok(Json(ThemeResponse {
36        theme: "aurora".to_string(),
37        colors: ThemeColorsWeb {
38            primary: theme_colors.css_primary.to_string(),
39            secondary: theme_colors.css_secondary.to_string(),
40            background: theme_colors.css_background.to_string(),
41            foreground: theme_colors.css_foreground.to_string(),
42        },
43    }))
44}
45
46/// POST /api/theme — Set theme (accepts {"theme": "aurora"})
47pub async fn set_theme(
48    State(_state): State<Arc<AppState>>,
49    Json(request): Json<SetThemeRequest>,
50) -> AppResult<Json<ThemeResponse>> {
51    // Parse the theme name
52    let theme = match request.theme.as_str() {
53        "default" => Theme::Default,
54        "claude" => Theme::Claude,
55        "twitter" => Theme::Twitter,
56        "neo-brutalism" => Theme::NeoBrutalism,
57        "retro-arcade" => Theme::RetroArcade,
58        "business" => Theme::Business,
59        _ => Theme::Aurora, // Default fallback (including "aurora")
60    };
61
62    // In the future, persist the theme choice to config/database
63    let theme_colors = theme.colors();
64
65    Ok(Json(ThemeResponse {
66        theme: request.theme,
67        colors: ThemeColorsWeb {
68            primary: theme_colors.css_primary.to_string(),
69            secondary: theme_colors.css_secondary.to_string(),
70            background: theme_colors.css_background.to_string(),
71            foreground: theme_colors.css_foreground.to_string(),
72        },
73    }))
74}