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(
30 State(_state): State<Arc<AppState>>,
31) -> AppResult<Json<ThemeResponse>> {
32 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
48pub async fn set_theme(
50 State(_state): State<Arc<AppState>>,
51 Json(request): Json<SetThemeRequest>,
52) -> AppResult<Json<ThemeResponse>> {
53 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, };
63
64 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}