use super::{Phase, Start};
use crate::reply::start::Prepared;
use crate::ui::Model;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Spread {
pub ball: String,
pub project: String,
pub n: u64,
}
impl Model {
pub fn stage_spread(&mut self, address: &str, spread: Spread, goal: &str) {
if goal.trim().is_empty() || self.start.as_ref().is_some_and(Start::outstanding) {
return;
}
self.outbox
.push(super::super::Posted::act(crate::verbs::prepare(
address.to_owned(),
None,
)));
self.start = Some(Start {
address: address.to_owned(),
goal: goal.to_owned(),
phase: Phase::Staging,
spread: Some(spread),
});
}
pub(in crate::ui::model) fn staged(&mut self, prepared: &Prepared) {
let held = self
.start
.clone()
.filter(|start| matches!(start.phase, Phase::Staging));
let Some((start, spread)) = held.and_then(|start| {
let spread = start.spread.clone()?;
Some((start, spread))
}) else {
self.fire(prepared);
return;
};
self.outbox
.push(super::super::Posted::act(crate::verbs::fan(
prepared,
start.address.clone(),
spread.ball.clone(),
spread.project.clone(),
spread.n,
)));
self.start = Some(Start {
phase: Phase::Firing,
..start
});
}
pub(in crate::ui::model) fn fanned(&mut self, rows: Vec<Prepared>) {
let held = self.start.clone().filter(|start| start.spread.is_some());
let (address, goal) = held.map_or_else(
|| (String::new(), String::new()),
|start| (start.address, start.goal),
);
for row in &rows {
let to = if address.is_empty() {
row.workspace.clone()
} else {
address.clone()
};
let said = if goal.trim().is_empty() {
row.goal.clone()
} else {
goal.clone()
};
if said.trim().is_empty() {
continue;
}
self.outbox
.push(super::super::Posted::act(crate::verbs::prompt(
row, to, said,
)));
}
}
}
#[cfg(test)]
mod tests;