From e531d32a77bdebcb0736efcf72f4b326af599470 Mon Sep 17 00:00:00 2001 From: Chili Palmer Date: Mon, 20 Jul 2026 18:18:53 +0200 Subject: [PATCH] Hide post gallery action in preview mode. --- crates/bds-ui/src/views/post_editor.rs | 37 ++++++++++++++++++-------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/crates/bds-ui/src/views/post_editor.rs b/crates/bds-ui/src/views/post_editor.rs index 7421692..4b2adb9 100644 --- a/crates/bds-ui/src/views/post_editor.rs +++ b/crates/bds-ui/src/views/post_editor.rs @@ -870,6 +870,7 @@ pub fn view<'a>( ] .spacing(6) .align_y(iced::Alignment::Center); + let show_content_actions = content_actions_visible(&state.editor_mode); let body_toolbar = inputs::toolbar( vec![ row![ @@ -881,7 +882,7 @@ pub fn view<'a>( .into(), ], vec![ - if state.editor_mode == "markdown" { + if show_content_actions { button( text(t(locale, "editor.insertLink")) .size(13) @@ -894,7 +895,7 @@ pub fn view<'a>( } else { Space::new(0, 0).into() }, - if state.editor_mode == "markdown" { + if show_content_actions { button( text(t(locale, "editor.insertMedia")) .size(13) @@ -907,15 +908,19 @@ pub fn view<'a>( } else { Space::new(0, 0).into() }, - button( - text(t(locale, "editor.gallery")) - .size(13) - .shaping(Shaping::Advanced), - ) - .on_press(Message::PostEditor(PostEditorMsg::Gallery)) - .padding([6, 16]) - .style(inputs::secondary_button) - .into(), + if show_content_actions { + button( + text(t(locale, "editor.gallery")) + .size(13) + .shaping(Shaping::Advanced), + ) + .on_press(Message::PostEditor(PostEditorMsg::Gallery)) + .padding([6, 16]) + .style(inputs::secondary_button) + .into() + } else { + Space::new(0, 0).into() + }, ], ); let editor_widget: Element<'a, Message> = if state.editor_mode == "preview" { @@ -1106,6 +1111,10 @@ fn normalize_editor_mode(mode: &str) -> String { } } +fn content_actions_visible(mode: &str) -> bool { + mode == "markdown" +} + fn status_badge<'a>(status: &PostStatus) -> Element<'a, Message> { let (label, color) = match status { PostStatus::Draft => ("Draft", Color::from_rgb(0.8, 0.7, 0.2)), @@ -1245,4 +1254,10 @@ mod tests { state.set_editor_mode("preview"); assert_eq!(state.editor_mode, "preview"); } + + #[test] + fn content_actions_are_only_visible_in_markdown_mode() { + assert!(content_actions_visible("markdown")); + assert!(!content_actions_visible("preview")); + } }