Skip to content

Commit

Permalink
Show disconnected server icon
Browse files Browse the repository at this point in the history
  • Loading branch information
tarkah committed Jun 23, 2023
1 parent 9db2238 commit 941d774
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 25 deletions.
6 changes: 5 additions & 1 deletion data/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Connection {
}
}

fn channels(&self) -> Vec<String> {
pub fn channels(&self) -> Vec<String> {
self.client.list_channels().unwrap_or_default()
}

Expand Down Expand Up @@ -141,4 +141,8 @@ impl Map {
})
.collect()
}

pub fn iter(&self) -> std::collections::btree_map::Iter<Server, State> {
self.0.iter()
}
}
4 changes: 4 additions & 0 deletions src/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ pub fn globe<'a>() -> Text<'a> {
to_text('\u{f3ef}')
}

pub fn wifi_off<'a>() -> Text<'a> {
to_text('\u{f61b}')
}

pub fn chat<'a>() -> Text<'a> {
to_text('\u{f267}')
}
Expand Down
75 changes: 51 additions & 24 deletions src/screen/dashboard/side_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,46 @@ impl SideMenu {
) -> Element<'a, Message> {
let mut column = column![].spacing(1);

for (server, channels) in clients.get_channels().iter() {
column = column.push(buffer_button(panes, focus, Buffer::Server(server.clone())));

for channel in channels {
column = column.push(buffer_button(
panes,
focus,
Buffer::Channel(server.clone(), channel.clone()),
));
for (server, state) in clients.iter() {
match state {
data::client::State::Disconnected => {
column = column.push(buffer_button(
panes,
focus,
Buffer::Server(server.clone()),
false,
));
}
data::client::State::Ready(connection) => {
column = column.push(buffer_button(
panes,
focus,
Buffer::Server(server.clone()),
true,
));

for channel in connection.channels() {
column = column.push(buffer_button(
panes,
focus,
Buffer::Channel(server.clone(), channel.clone()),
true,
));
}

let queries = history.get_unique_queries(server);
for user in queries {
column = column.push(buffer_button(
panes,
focus,
Buffer::Query(server.clone(), user.clone()),
true,
));
}

column = column.push(vertical_space(12));
}
}

let queries = history.get_unique_queries(server);
for user in queries {
column = column.push(buffer_button(
panes,
focus,
Buffer::Query(server.clone(), user.clone()),
));
}

column = column.push(vertical_space(12));
}

container(
Expand Down Expand Up @@ -121,15 +140,23 @@ fn buffer_button<'a>(
panes: &pane_grid::State<Pane>,
focus: Option<pane_grid::Pane>,
buffer: Buffer,
connected: bool,
) -> Element<'a, Message> {
let open = panes
.iter()
.find_map(|(pane, state)| (state.buffer.kind().as_ref() == Some(&buffer)).then_some(*pane));

let row = match &buffer {
Buffer::Server(server) => row![icon::globe(), text(server.to_string())]
.spacing(8)
.align_items(iced::Alignment::Center),
Buffer::Server(server) => row![
if connected {
icon::globe()
} else {
icon::wifi_off()
},
text(server.to_string())
]
.spacing(8)
.align_items(iced::Alignment::Center),
Buffer::Channel(_, channel) => row![horizontal_space(4), icon::chat(), text(channel)]
.spacing(8)
.align_items(iced::Alignment::Center),
Expand All @@ -147,7 +174,7 @@ fn buffer_button<'a>(

let entries = Entry::list(panes.len(), open, focus);

if entries.is_empty() {
if entries.is_empty() || !connected {
base.into()
} else {
context_menu(base, entries, move |entry| {
Expand Down

0 comments on commit 941d774

Please sign in to comment.