From 66b19217dc74e5391cc1035a15ca448c4e958984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 26 Nov 2026 02:50:43 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20composer=20plus=20button=20?= =?UTF-8?q?is=20a=20menu=20with=20file=20and=20poll?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/client/src/gui/chat.rs | 18 +----- crates/client/src/gui/composer.rs | 97 ++++++++++++++++++++++++++++--- 2 files changed, 91 insertions(+), 24 deletions(-) diff --git a/crates/client/src/gui/chat.rs b/crates/client/src/gui/chat.rs index 42e5b9c..19a2960 100644 --- a/crates/client/src/gui/chat.rs +++ b/crates/client/src/gui/chat.rs @@ -149,6 +149,7 @@ pub struct Chat { pub(super) poll_options: Vec>, pub(super) poll_multiple: bool, pub(super) poll_public: bool, + pub(super) plus_menu: composer::PlusMenu, pub(super) my_votes: HashMap>, pub(super) poll_expanded: bool, scroll: ScrollHandle, @@ -354,6 +355,7 @@ impl Chat { ], poll_multiple: false, poll_public: false, + plus_menu: composer::PlusMenu::Menu, my_votes: HashMap::new(), poll_expanded: false, history: History::End, @@ -1515,7 +1517,6 @@ impl Yumush { } let input = self.chat.message_input.clone(); - let attach = entity.clone(); let pending = media_view::pending_row(&self.chat.media, entity, palette); let bar = composer::mode_bar(&self.chat, entity, palette); let entity = entity.clone(); @@ -1557,21 +1558,8 @@ impl Yumush { .border_1() .border_color(palette.border) .bg(palette.field) - .child( - clickable("attach_button", palette, move |window, cx| { - attach.update(cx, |yumush, cx| yumush.attach_files(window, cx)) - }) - .tip("Attach") - .size(px(28.)) - .flex() - .items_center() - .justify_center() - .rounded(px(6.)) - .text_color(palette.muted) - .child(Icon::new(IconName::Plus).w(px(16.)).h(px(16.))), - ) + .child(composer::plus_popover(&self.chat, &entity, palette)) .child(composer::format_popover(palette)) - .child(composer::poll_popover(&self.chat, &entity, palette)) .child( Input::new(&self.chat.message_input) .appearance(false) diff --git a/crates/client/src/gui/composer.rs b/crates/client/src/gui/composer.rs index cf3c7ca..f5d0733 100644 --- a/crates/client/src/gui/composer.rs +++ b/crates/client/src/gui/composer.rs @@ -14,7 +14,7 @@ use common::{ }; use gpui_kit::{ Anchor, AnyElement, App, Context, Div, ElementId, Entity, FontWeight, InteractiveElement, - IntoElement, KeyBinding, ParentElement, Styled, Window, actions, + IntoElement, KeyBinding, MouseButton, ParentElement, Styled, Window, actions, assets::IconName, component::{ Icon, WindowExt, checkbox::Checkbox, input::InputState, notification::Notification, @@ -24,7 +24,7 @@ use gpui_kit::{ }; use super::{ - Palette, Trigger, Yumush, + Palette, Trigger, Yumush, clickable, chat::{Chat, TYPING_SEND_INTERVAL}, hoverable, new_input, notify_error, pop_in, primary_button, }; @@ -561,24 +561,102 @@ pub fn format_popover(palette: Palette) -> impl IntoElement { }) } -pub fn poll_popover(chat: &Chat, entity: &Entity, palette: Palette) -> impl IntoElement { +#[derive(Clone, Copy, PartialEq, Eq, Default)] +pub(super) enum PlusMenu { + #[default] + Menu, + Poll, +} + +fn plus_row( + id: &'static str, + icon: IconName, + label: &'static str, + palette: Palette, + on_click: impl Fn(&mut Window, &mut App) + 'static, +) -> impl IntoElement { + clickable(id, palette, on_click) + .h(px(32.)) + .px(px(8.)) + .gap(px(8.)) + .rounded(px(6.)) + .flex() + .items_center() + .child( + div() + .text_color(palette.muted) + .child(Icon::new(icon).w(px(14.)).h(px(14.))), + ) + .child(label) +} + +pub fn plus_popover(chat: &Chat, entity: &Entity, palette: Palette) -> impl IntoElement { let question = chat.poll_question.clone(); let options = chat.poll_options.clone(); let multiple = chat.poll_multiple; let public = chat.poll_public; + let reset = entity.clone(); let entity = entity.clone(); - Popover::new("poll_popover") + Popover::new("plus_popover") .anchor(Anchor::BottomLeft) .appearance(false) - .trigger(trigger_icon( - "poll_trigger", - IconName::ChartBar, - 28., - palette, + .trigger(Trigger::new( + hoverable( + "plus_trigger", + div() + .size(px(28.)) + .flex() + .items_center() + .justify_center() + .rounded(px(6.)) + .text_color(palette.muted) + .child(Icon::new(IconName::Plus).w(px(16.)).h(px(16.))), + palette, + ) + .on_mouse_down(MouseButton::Left, move |_, _, cx| { + reset.update(cx, |yumush, _| yumush.chat.plus_menu = PlusMenu::Menu) + }), )) .content(move |_, _, cx| { let popover = cx.entity(); + if entity.read(cx).chat.plus_menu == PlusMenu::Menu { + let file = entity.clone(); + let poll = entity.clone(); + return pop_in( + "plus_menu", + panel(palette) + .w(px(180.)) + .p(px(4.)) + .flex() + .flex_col() + .gap(px(4.)) + .child(plus_row( + "plus_file", + IconName::File, + "File", + palette, + move |window, cx| { + popover.update(cx, |state, cx| state.dismiss(window, cx)); + file.update(cx, |yumush, cx| yumush.attach_files(window, cx)); + }, + )) + .child(plus_row( + "plus_poll", + IconName::ChartBar, + "Poll", + palette, + move |_, cx| { + poll.update(cx, |yumush, cx| { + yumush.chat.plus_menu = PlusMenu::Poll; + cx.notify(); + }) + }, + )), + Anchor::BottomLeft, + ) + .into_any_element(); + } let toggle = entity.clone(); let toggle_public = entity.clone(); let add = entity.clone(); @@ -681,6 +759,7 @@ pub fn poll_popover(chat: &Chat, entity: &Entity, palette: Palette) -> i ), Anchor::BottomLeft, ) + .into_any_element() }) }