| 1 | use crate::gui::composer::{self, PlusMenu}; |
| 2 | use crate::gui::{Yumush, new_input}; |
| 3 | use crate::lang::w; |
| 4 | use common::constant::MINIMUM_POLL_OPTIONS; |
| 5 | use gpui_kit::{Context, Entity, Window, component::input::InputState}; |
| 6 | |
| 7 | pub struct PollDraft { |
| 8 | pub question: Entity<InputState>, |
| 9 | pub options: Vec<Entity<InputState>>, |
| 10 | pub multiple: bool, |
| 11 | pub public: bool, |
| 12 | pub duration: Option<u32>, |
| 13 | pub plus_menu: PlusMenu, |
| 14 | pub expanded: bool, |
| 15 | pub page: usize, |
| 16 | } |
| 17 | |
| 18 | impl PollDraft { |
| 19 | pub fn new(window: &mut Window, cx: &mut Context<Yumush>) -> Self { |
| 20 | Self { |
| 21 | question: new_input(w().chat.question, window, cx), |
| 22 | options: (0..MINIMUM_POLL_OPTIONS) |
| 23 | .map(|_| composer::new_poll_option(window, cx)) |
| 24 | .collect(), |
| 25 | multiple: false, |
| 26 | public: true, |
| 27 | duration: None, |
| 28 | plus_menu: PlusMenu::Menu, |
| 29 | expanded: false, |
| 30 | page: 0, |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | pub fn clear(&mut self, window: &mut Window, cx: &mut Context<Yumush>) { |
| 35 | self.question |
| 36 | .update(cx, |state, cx| state.set_value("", window, cx)); |
| 37 | self.options.truncate(MINIMUM_POLL_OPTIONS); |
| 38 | for input in &self.options { |
| 39 | input.update(cx, |state, cx| state.set_value("", window, cx)); |
| 40 | } |
| 41 | self.multiple = false; |
| 42 | self.public = true; |
| 43 | self.duration = None; |
| 44 | } |
| 45 | } |