feat: better session creation handling
This commit is contained in:
@@ -81,16 +81,6 @@ impl App {
|
||||
}
|
||||
|
||||
fn sidebar(&self) -> Element<'_, Message> {
|
||||
let new_session_content = row![icon(ICON_NEW_SESSION, 17), text("New session").size(14),]
|
||||
.spacing(9)
|
||||
.align_y(Alignment::Center);
|
||||
let new_session = if self.selected_project.is_some() {
|
||||
button(new_session_content)
|
||||
.width(Length::Fill)
|
||||
.on_press(Message::CreateSession)
|
||||
} else {
|
||||
button(new_session_content).width(Length::Fill)
|
||||
};
|
||||
let preference_content = row![
|
||||
icon(ICON_SETTINGS, 17),
|
||||
text("Preferences").size(14),
|
||||
@@ -116,16 +106,12 @@ impl App {
|
||||
.width(Length::Fill)
|
||||
.on_press(Message::ChooseProjectFolder)
|
||||
};
|
||||
let header = column![
|
||||
row![
|
||||
text("DS4Server").size(20),
|
||||
Space::with_width(Length::Fill),
|
||||
text("Local").size(12),
|
||||
]
|
||||
.align_y(Alignment::Center),
|
||||
new_session.style(button::text),
|
||||
let header = row![
|
||||
text("DS4Server").size(20),
|
||||
Space::with_width(Length::Fill),
|
||||
text("Local").size(12),
|
||||
]
|
||||
.spacing(10);
|
||||
.align_y(Alignment::Center);
|
||||
let mut projects = column![
|
||||
row![
|
||||
text("PROJECTS").size(11),
|
||||
@@ -149,6 +135,9 @@ impl App {
|
||||
.width(Length::Fill)
|
||||
.on_press(Message::SelectProject(project.id))
|
||||
.style(button::text),
|
||||
button(icon(ICON_NEW_SESSION, 15))
|
||||
.on_press(Message::CreateSession(project.id))
|
||||
.style(button::text),
|
||||
button(icon(ICON_TRASH, 15))
|
||||
.on_press(Message::DeleteProject(project.id))
|
||||
.style(button::text),
|
||||
@@ -182,6 +171,35 @@ impl App {
|
||||
.align_y(Alignment::Center),
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(title) = self.drafts.get(&project.id) {
|
||||
let draft_selected = self.draft_selected(project.id);
|
||||
projects = projects.push(
|
||||
row![
|
||||
Space::with_width(26),
|
||||
button(
|
||||
row![
|
||||
icon(ICON_CHAT, 15),
|
||||
text(title).size(13).color(muted_text())
|
||||
]
|
||||
.spacing(8)
|
||||
.align_y(Alignment::Center),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.on_press(Message::CreateSession(project.id))
|
||||
.style(if draft_selected {
|
||||
button::secondary
|
||||
} else {
|
||||
button::text
|
||||
}),
|
||||
button(icon(ICON_TRASH, 14))
|
||||
.on_press(Message::DiscardSession(project.id))
|
||||
.style(button::text),
|
||||
]
|
||||
.spacing(3)
|
||||
.align_y(Alignment::Center),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
container(
|
||||
@@ -281,6 +299,18 @@ impl App {
|
||||
.iter()
|
||||
.find(|session| Some(session.id) == self.selected_session)
|
||||
}
|
||||
|
||||
/// Title of the active chat surface: a stored session, or this project's
|
||||
/// unsaved draft. `None` means no chat is open for the project.
|
||||
fn active_session_title<'a>(&'a self, project: &'a ProjectWithSessions) -> Option<&'a str> {
|
||||
match self.selected_session(project) {
|
||||
Some(session) => Some(session.title.as_str()),
|
||||
None if self.draft_selected(project.project.id) => {
|
||||
self.drafts.get(&project.project.id).map(String::as_str)
|
||||
}
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn preference_input_row<'a>(
|
||||
|
||||
Reference in New Issue
Block a user