Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,18 @@ impl Flowsurface {
event: msg,
});
}
Some(dashboard::sidebar::Action::SyncToAllPanes(ticker_info)) => {
let main_window_id = self.main_window.id;

let task = self
.active_dashboard_mut()
.switch_all_panes_to_ticker(main_window_id, ticker_info);

return task.map(move |msg| Message::Dashboard {
layout_id: None,
event: msg,
});
}
Some(dashboard::sidebar::Action::ErrorOccurred(err)) => {
self.notifications.push(Toast::error(err.to_string()));
}
Expand Down
32 changes: 32 additions & 0 deletions src/screen/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,38 @@ impl Dashboard {
}
}

pub fn switch_all_panes_to_ticker(
&mut self,
main_window: window::Id,
ticker_info: TickerInfo,
) -> Task<Message> {
let pane_infos: Vec<(window::Id, pane_grid::Pane, ContentKind)> = self
.iter_all_panes_mut(main_window)
.filter_map(|(window, pane, state)| {
// Skip Starter panes (empty panes)
match state.content.kind() {
ContentKind::Starter => None,
kind => Some((window, pane, kind)),
}
})
.collect();

if pane_infos.is_empty() {
return Task::done(Message::Notification(Toast::warn(
"No active panels to sync".to_string(),
)));
}

let tasks: Vec<Task<Message>> = pane_infos
.iter()
.map(|(window, pane, content_kind)| {
self.init_pane(main_window, *window, *pane, ticker_info, *content_kind)
})
.collect();

Task::batch(tasks)
}

pub fn toggle_trade_fetch(&mut self, is_enabled: bool, main_window: &Window) {
exchange::fetcher::toggle_trade_fetch(is_enabled);

Expand Down
4 changes: 4 additions & 0 deletions src/screen/dashboard/sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub enum Action {
exchange::TickerInfo,
Option<data::layout::pane::ContentKind>,
),
SyncToAllPanes(exchange::TickerInfo),
ErrorOccurred(data::InternalError),
}

Expand Down Expand Up @@ -70,6 +71,9 @@ impl Sidebar {
Some(Action::TickerSelected(ticker_info, content)),
);
}
Some(tickers_table::Action::SyncToAllPanes(ticker_info)) => {
return (Task::none(), Some(Action::SyncToAllPanes(ticker_info)));
}
Some(tickers_table::Action::Fetch(task)) => {
return (task.map(Message::TickersTable), None);
}
Expand Down
28 changes: 27 additions & 1 deletion src/screen/dashboard/tickers_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub fn fetch_tickers_info() -> Task<Message> {

pub enum Action {
TickerSelected(TickerInfo, Option<ContentKind>),
SyncToAllPanes(TickerInfo),
ErrorOccurred(data::InternalError),
Fetch(Task<Message>),
FocusWidget(iced::widget::Id),
Expand All @@ -84,6 +85,7 @@ pub enum Message {
ChangeSortOption(SortOptions),
ShowSortingOptions,
TickerSelected(Ticker, Option<ContentKind>),
SyncToAllPanes(Ticker),
ExpandTickerCard(Option<Ticker>),
FavoriteTicker(Ticker),
Scrolled(scrollable::Viewport),
Expand Down Expand Up @@ -202,6 +204,18 @@ impl TickersTable {
);
}
}
Message::SyncToAllPanes(ticker) => {
let ticker_info = self.tickers_info.get(&ticker).cloned().flatten();

if let Some(ticker_info) = ticker_info {
return Some(Action::SyncToAllPanes(ticker_info));
} else {
log::warn!(
"Ticker info not found for {ticker:?} on {:?}",
ticker.exchange
);
}
}
Message::ToggleTable => {
self.is_shown = !self.is_shown;

Expand Down Expand Up @@ -1284,8 +1298,20 @@ fn expanded_ticker_card<'a>(
})
.on_press(Message::FavoriteTicker(*ticker))
.style(move |theme, status| { style::button::transparent(theme, status, false) }),
Space::new().width(Length::Fill).height(Length::Shrink),
button(
row![
icon_text(Icon::Link, 12),
text("Sync All").size(11)
]
.spacing(4)
.align_y(Alignment::Center)
)
.on_press(Message::SyncToAllPanes(*ticker))
.style(|theme, status| style::button::confirm(theme, status, false)),
]
.spacing(2),
.spacing(2)
.align_y(Alignment::Center),
row![
icon_text(exchange_icon, 12),
text(
Expand Down