use ratatui::{
Frame,
layout::{Constraint, Direction, Layout, Rect},
widgets::Block,
};
use crate::app::{App, InputMode};
use crate::ui::diff_view::render_diff_view;
use crate::ui::file_list::render_file_list;
use crate::ui::inline_commit_selector::render_inline_commit_selector;
use crate::ui::selector::render_commit_select;
use crate::ui::{comment_panel, help_popup, status_bar, styles, submit_modals};
pub fn render(frame: &mut Frame, app: &mut App) {
frame.render_widget(
Block::default().style(styles::panel_style(&app.theme)),
frame.area(),
);
if app.input_mode == InputMode::CommitSelect {
render_commit_select(frame, app);
return;
}
app.comment_cursor_screen_pos = None;
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints(vec![
Constraint::Length(1), Constraint::Min(0), Constraint::Length(1), ])
.split(frame.area());
status_bar::render_header(frame, app, chunks[0]);
render_main_content(frame, app, chunks[1]);
status_bar::render_status_bar(frame, app, chunks[2]);
if app.input_mode == InputMode::Help {
help_popup::render_help(frame, app);
}
if app.input_mode == InputMode::Confirm {
comment_panel::render_confirm_dialog(frame, app, "Copy review to clipboard?");
}
if app.input_mode == InputMode::SubmitResolver {
submit_modals::render_submit_resolver(frame, app);
}
if app.input_mode == InputMode::SubmitConfirm {
submit_modals::render_submit_confirm(frame, app);
}
if app.input_mode == InputMode::SubmitActionPicker {
submit_modals::render_submit_action_picker(frame, app);
}
if app.input_mode == InputMode::Comment {
let (col, row) = app.comment_cursor_screen_pos.unwrap_or_else(|| {
if let Some(diff_area) = app.diff_area {
(diff_area.x + 1, diff_area.y + 1)
} else {
(chunks[1].x + 1, chunks[1].y + 1)
}
});
frame.set_cursor_position(ratatui::layout::Position { x: col, y: row });
}
}
fn render_main_content(frame: &mut Frame, app: &mut App, area: Rect) {
let content_area = if app.has_inline_commit_selector() {
let selector_height = (app.review_commits.len() as u16 + 2).min(8); let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Length(selector_height), Constraint::Min(0)])
.split(area);
render_inline_commit_selector(frame, app, chunks[0]);
chunks[1]
} else {
app.commit_list_inner_area = None;
area
};
if app.show_file_list {
let chunks = Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Percentage(20), Constraint::Percentage(80), ])
.split(content_area);
app.file_list_area = Some(chunks[0]);
app.diff_area = Some(chunks[1]);
render_file_list(frame, app, chunks[0]);
render_diff_view(frame, app, chunks[1]);
} else {
app.file_list_area = None;
app.diff_area = Some(content_area);
render_diff_view(frame, app, content_area);
}
}