forge
Explore
Log in

Don't you dare go Hollow

Composer plus button is a menu with file and poll

Browse files at this commit

66b19217dc74e5391cc1035a15ca448c4e958984Ahmet Kaan GümüşParent: c3c7ee2
  • feat
    • composer plus button is a menu with file and poll
Show full message
✨ feat: composer plus button is a menu with file and poll
crates/client/src/gui/chat.rsmodified+3 -15
@@ -149,6 +149,7 @@ pub struct Chat {
149 pub(super) poll_options: Vec<Entity<InputState>>,149 pub(super) poll_options: Vec<Entity<InputState>>,
150 pub(super) poll_multiple: bool,150 pub(super) poll_multiple: bool,
151 pub(super) poll_public: bool,151 pub(super) poll_public: bool,
152+ pub(super) plus_menu: composer::PlusMenu,
152 pub(super) my_votes: HashMap<Id, Vec<u32>>,153 pub(super) my_votes: HashMap<Id, Vec<u32>>,
153 pub(super) poll_expanded: bool,154 pub(super) poll_expanded: bool,
154 scroll: ScrollHandle,155 scroll: ScrollHandle,
@@ -354,6 +355,7 @@ impl Chat {
354 ],355 ],
355 poll_multiple: false,356 poll_multiple: false,
356 poll_public: false,357 poll_public: false,
358+ plus_menu: composer::PlusMenu::Menu,
357 my_votes: HashMap::new(),359 my_votes: HashMap::new(),
358 poll_expanded: false,360 poll_expanded: false,
359 history: History::End,361 history: History::End,
@@ -1515,7 +1517,6 @@ impl Yumush {
1515 }1517 }
1516 1518
1517 let input = self.chat.message_input.clone();1519 let input = self.chat.message_input.clone();
1518- let attach = entity.clone();
1519 let pending = media_view::pending_row(&self.chat.media, entity, palette);1520 let pending = media_view::pending_row(&self.chat.media, entity, palette);
1520 let bar = composer::mode_bar(&self.chat, entity, palette);1521 let bar = composer::mode_bar(&self.chat, entity, palette);
1521 let entity = entity.clone();1522 let entity = entity.clone();
@@ -1557,21 +1558,8 @@ impl Yumush {
1557 .border_1()1558 .border_1()
1558 .border_color(palette.border)1559 .border_color(palette.border)
1559 .bg(palette.field)1560 .bg(palette.field)
1560- .child(1561+ .child(composer::plus_popover(&self.chat, &entity, palette))
1561- clickable("attach_button", palette, move |window, cx| {
1562- attach.update(cx, |yumush, cx| yumush.attach_files(window, cx))
1563- })
1564- .tip("Attach")
1565- .size(px(28.))
1566- .flex()
1567- .items_center()
1568- .justify_center()
1569- .rounded(px(6.))
1570- .text_color(palette.muted)
1571- .child(Icon::new(IconName::Plus).w(px(16.)).h(px(16.))),
1572- )
1573 .child(composer::format_popover(palette))1562 .child(composer::format_popover(palette))
1574- .child(composer::poll_popover(&self.chat, &entity, palette))
1575 .child(1563 .child(
1576 Input::new(&self.chat.message_input)1564 Input::new(&self.chat.message_input)
1577 .appearance(false)1565 .appearance(false)
crates/client/src/gui/composer.rsmodified+88 -9
@@ -14,7 +14,7 @@ use common::{
14 };14 };
15 use gpui_kit::{15 use gpui_kit::{
16 Anchor, AnyElement, App, Context, Div, ElementId, Entity, FontWeight, InteractiveElement,16 Anchor, AnyElement, App, Context, Div, ElementId, Entity, FontWeight, InteractiveElement,
17- IntoElement, KeyBinding, ParentElement, Styled, Window, actions,17+ IntoElement, KeyBinding, MouseButton, ParentElement, Styled, Window, actions,
18 assets::IconName,18 assets::IconName,
19 component::{19 component::{
20 Icon, WindowExt, checkbox::Checkbox, input::InputState, notification::Notification,20 Icon, WindowExt, checkbox::Checkbox, input::InputState, notification::Notification,
@@ -24,7 +24,7 @@ use gpui_kit::{
24 };24 };
25 25
26 use super::{26 use super::{
27- Palette, Trigger, Yumush,27+ Palette, Trigger, Yumush, clickable,
28 chat::{Chat, TYPING_SEND_INTERVAL},28 chat::{Chat, TYPING_SEND_INTERVAL},
29 hoverable, new_input, notify_error, pop_in, primary_button,29 hoverable, new_input, notify_error, pop_in, primary_button,
30 };30 };
@@ -561,24 +561,102 @@ pub fn format_popover(palette: Palette) -> impl IntoElement {
561 })561 })
562 }562 }
563 563
564-pub fn poll_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> impl IntoElement {564+#[derive(Clone, Copy, PartialEq, Eq, Default)]
565+pub(super) enum PlusMenu {
566+ #[default]
567+ Menu,
568+ Poll,
569+}
570+
571+fn plus_row(
572+ id: &'static str,
573+ icon: IconName,
574+ label: &'static str,
575+ palette: Palette,
576+ on_click: impl Fn(&mut Window, &mut App) + 'static,
577+) -> impl IntoElement {
578+ clickable(id, palette, on_click)
579+ .h(px(32.))
580+ .px(px(8.))
581+ .gap(px(8.))
582+ .rounded(px(6.))
583+ .flex()
584+ .items_center()
585+ .child(
586+ div()
587+ .text_color(palette.muted)
588+ .child(Icon::new(icon).w(px(14.)).h(px(14.))),
589+ )
590+ .child(label)
591+}
592+
593+pub fn plus_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> impl IntoElement {
565 let question = chat.poll_question.clone();594 let question = chat.poll_question.clone();
566 let options = chat.poll_options.clone();595 let options = chat.poll_options.clone();
567 let multiple = chat.poll_multiple;596 let multiple = chat.poll_multiple;
568 let public = chat.poll_public;597 let public = chat.poll_public;
598+ let reset = entity.clone();
569 let entity = entity.clone();599 let entity = entity.clone();
570 600
571- Popover::new("poll_popover")601+ Popover::new("plus_popover")
572 .anchor(Anchor::BottomLeft)602 .anchor(Anchor::BottomLeft)
573 .appearance(false)603 .appearance(false)
574- .trigger(trigger_icon(604+ .trigger(Trigger::new(
575- "poll_trigger",605+ hoverable(
576- IconName::ChartBar,606+ "plus_trigger",
577- 28.,607+ div()
578- palette,608+ .size(px(28.))
609+ .flex()
610+ .items_center()
611+ .justify_center()
612+ .rounded(px(6.))
613+ .text_color(palette.muted)
614+ .child(Icon::new(IconName::Plus).w(px(16.)).h(px(16.))),
615+ palette,
616+ )
617+ .on_mouse_down(MouseButton::Left, move |_, _, cx| {
618+ reset.update(cx, |yumush, _| yumush.chat.plus_menu = PlusMenu::Menu)
619+ }),
579 ))620 ))
580 .content(move |_, _, cx| {621 .content(move |_, _, cx| {
581 let popover = cx.entity();622 let popover = cx.entity();
623+ if entity.read(cx).chat.plus_menu == PlusMenu::Menu {
624+ let file = entity.clone();
625+ let poll = entity.clone();
626+ return pop_in(
627+ "plus_menu",
628+ panel(palette)
629+ .w(px(180.))
630+ .p(px(4.))
631+ .flex()
632+ .flex_col()
633+ .gap(px(4.))
634+ .child(plus_row(
635+ "plus_file",
636+ IconName::File,
637+ "File",
638+ palette,
639+ move |window, cx| {
640+ popover.update(cx, |state, cx| state.dismiss(window, cx));
641+ file.update(cx, |yumush, cx| yumush.attach_files(window, cx));
642+ },
643+ ))
644+ .child(plus_row(
645+ "plus_poll",
646+ IconName::ChartBar,
647+ "Poll",
648+ palette,
649+ move |_, cx| {
650+ poll.update(cx, |yumush, cx| {
651+ yumush.chat.plus_menu = PlusMenu::Poll;
652+ cx.notify();
653+ })
654+ },
655+ )),
656+ Anchor::BottomLeft,
657+ )
658+ .into_any_element();
659+ }
582 let toggle = entity.clone();660 let toggle = entity.clone();
583 let toggle_public = entity.clone();661 let toggle_public = entity.clone();
584 let add = entity.clone();662 let add = entity.clone();
@@ -681,6 +759,7 @@ pub fn poll_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> i
681 ),759 ),
682 Anchor::BottomLeft,760 Anchor::BottomLeft,
683 )761 )
762+ .into_any_element()
684 })763 })
685 }764 }
686 765