From 312f3d2ab9332d2ae48e02bd35f4a7c979706cc5 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Mon, 9 Oct 2023 16:53:28 -0400 Subject: [PATCH] Change how the default theme gets determined --- crates/storybook2/src/storybook2.rs | 3 ++- crates/storybook2/src/themes.rs | 19 +++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/crates/storybook2/src/storybook2.rs b/crates/storybook2/src/storybook2.rs index 3f2e80ff34..8b840b75ab 100644 --- a/crates/storybook2/src/storybook2.rs +++ b/crates/storybook2/src/storybook2.rs @@ -50,7 +50,8 @@ fn main() { let story_selector = args.story.clone(); - let theme = themes::load_theme(args.theme); + let theme_name = args.theme.unwrap_or("One Dark".to_string()); + let theme = themes::load_theme(theme_name); let asset_source = Arc::new(Assets); gpui3::App::production(asset_source).run(move |cx| { diff --git a/crates/storybook2/src/themes.rs b/crates/storybook2/src/themes.rs index 6e06f5b6b4..b348019e53 100644 --- a/crates/storybook2/src/themes.rs +++ b/crates/storybook2/src/themes.rs @@ -13,20 +13,15 @@ struct LegacyTheme { pub base_theme: serde_json::Value, } -pub fn load_theme(override_theme_name: Option) -> Theme { - let theme = if let Some(theme) = override_theme_name { - let theme_contents = Assets::get(&format!("themes/{theme}.json")) - .unwrap_or_else(|| panic!("failed to load theme: {theme}.json")); +/// Loads the [`Theme`] with the given name. +pub fn load_theme(name: String) -> Theme { + let theme_contents = Assets::get(&format!("themes/{name}.json")) + .unwrap_or_else(|| panic!("failed to load theme: {name}.json")); - let legacy_theme: LegacyTheme = - serde_json::from_str(std::str::from_utf8(&theme_contents.data).unwrap()).unwrap(); + let legacy_theme: LegacyTheme = + serde_json::from_str(std::str::from_utf8(&theme_contents.data).unwrap()).unwrap(); - let new_theme: Theme = serde_json::from_value(legacy_theme.base_theme.clone()).unwrap(); - - new_theme - } else { - rose_pine_dawn() - }; + let theme: Theme = serde_json::from_value(legacy_theme.base_theme.clone()).unwrap(); theme }