flow_server/routes/
theme.rs1use 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
28pub async fn get_theme(State(_state): State<Arc<AppState>>) -> AppResult<Json<ThemeResponse>> {
30 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
46pub async fn set_theme(
48 State(_state): State<Arc<AppState>>,
49 Json(request): Json<SetThemeRequest>,
50) -> AppResult<Json<ThemeResponse>> {
51 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, };
61
62 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}