Skip to main content

metis_docs_tui/app/actions/
ui_actions.rs

1use crate::app::state::ConfirmationType;
2use crate::app::App;
3use crate::models::{AppState, BoardType};
4
5impl App {
6    // Message handling methods
7    pub fn add_success_message(&mut self, message: String) {
8        self.ui_state.message_state.add_success(message);
9    }
10
11    pub fn add_error_message(&mut self, message: String) {
12        self.ui_state.message_state.add_error(message);
13    }
14
15    pub fn add_warning_message(&mut self, message: String) {
16        self.ui_state.message_state.add_warning(message);
17    }
18
19    pub fn add_info_message(&mut self, message: String) {
20        self.ui_state.message_state.add_info(message);
21    }
22
23    pub fn clear_messages(&mut self) {
24        self.ui_state.message_state.clear_message();
25    }
26
27    pub fn clear_expired_messages(&mut self) {
28        self.ui_state.message_state.clear_expired_messages();
29    }
30
31    // Document creation state management methods
32    pub fn start_document_creation(&mut self) {
33        self.ui_state.set_app_state(AppState::CreatingDocument);
34        self.ui_state.reset_input();
35    }
36
37    pub fn start_smart_document_creation(&mut self) {
38        match self.ui_state.current_board {
39            // Strategy board: Create strategies (full config) or initiatives (other configs)
40            BoardType::Strategy => {
41                if self.core_state.flight_config.strategies_enabled {
42                    // Full config: Create root strategy
43                    self.ui_state.set_app_state(AppState::CreatingDocument);
44                } else {
45                    // Streamlined/Direct config: Create initiative under selected strategy (if any exist)
46                    self.ui_state.set_app_state(AppState::CreatingChildDocument);
47                }
48                self.ui_state.reset_input();
49            }
50            // Initiative board: Create initiatives (streamlined config) or tasks (other configs)
51            BoardType::Initiative => {
52                if !self.core_state.flight_config.strategies_enabled
53                    && self.core_state.flight_config.initiatives_enabled
54                {
55                    // Streamlined config: Create root initiative (no parent strategies)
56                    self.ui_state.set_app_state(AppState::CreatingDocument);
57                } else {
58                    // Full config: Create task under selected initiative
59                    self.ui_state.set_app_state(AppState::CreatingChildDocument);
60                }
61                self.ui_state.reset_input();
62            }
63            // Task board: Create tasks (direct config) or show error (other configs)
64            BoardType::Task => {
65                if !self.core_state.flight_config.strategies_enabled
66                    && !self.core_state.flight_config.initiatives_enabled
67                {
68                    // Direct config: Create root task (no parent strategies/initiatives)
69                    self.ui_state.set_app_state(AppState::CreatingDocument);
70                    self.ui_state.reset_input();
71                } else {
72                    // Full/Streamlined config: Tasks must have parents
73                    self.add_error_message("Tasks are created from the Initiative board (with parent) or Backlog board (standalone)".to_string());
74                }
75            }
76            // ADR board: Create new ADR (standalone)
77            BoardType::Adr => {
78                self.ui_state.set_app_state(AppState::CreatingAdr);
79                self.ui_state.reset_input();
80            }
81            // Backlog board: Create backlog item (standalone)
82            BoardType::Backlog => {
83                self.ui_state
84                    .set_app_state(AppState::SelectingBacklogCategory);
85                self.ui_state.reset_input();
86            }
87        }
88    }
89
90    pub fn start_child_document_creation(&mut self) {
91        self.ui_state.set_app_state(AppState::CreatingChildDocument);
92        self.ui_state.reset_input();
93    }
94
95    pub fn start_adr_creation(&mut self) {
96        self.ui_state.set_app_state(AppState::CreatingAdr);
97        self.ui_state.reset_input();
98    }
99
100    pub fn cancel_document_creation(&mut self) {
101        self.ui_state.set_app_state(AppState::Normal);
102        self.ui_state.reset_input();
103    }
104
105    // Confirmation dialog state management methods
106    pub fn start_delete_confirmation(&mut self) {
107        self.ui_state.confirmation_type = Some(ConfirmationType::Delete);
108        self.ui_state.set_app_state(AppState::Confirming);
109    }
110
111    pub fn start_transition_confirmation(&mut self) {
112        self.ui_state.confirmation_type = Some(ConfirmationType::Transition);
113        self.ui_state.set_app_state(AppState::Confirming);
114    }
115
116    pub fn cancel_confirmation(&mut self) {
117        self.ui_state.confirmation_type = None;
118        self.ui_state.set_app_state(AppState::Normal);
119    }
120}