Relay Lists: Add "reasons" string to compact view

This commit is contained in:
Bu5hm4nn 2023-08-08 15:15:43 -10:00
parent ff6d0d5e93
commit 008d193994
2 changed files with 30 additions and 7 deletions

View File

@ -146,11 +146,23 @@ pub(super) fn relay_scroll_list(app: &mut GossipUi, ui: &mut Ui, relays: Vec<DbR
db_relay // don't update
};
// is this relay currently connected?
let is_connected = if let Some(_) = GLOBALS.connected_relays.get(&db_url) {
true
// get details on this relay
let (is_connected, reasons) = if let Some(entry) = GLOBALS.connected_relays.get(&db_url) {
(
true,
entry.iter()
.map(|rj| {
if rj.persistent {
format!("[{}]", rj.reason)
} else {
rj.reason.to_string()
}
})
.collect::<Vec<String>>()
.join(", ")
)
} else {
false
(false, "".into())
};
let enabled = edit || !is_editing;
@ -159,6 +171,7 @@ pub(super) fn relay_scroll_list(app: &mut GossipUi, ui: &mut Ui, relays: Vec<DbR
widget.set_detail(false); // TODO obey settings
widget.set_enabled(enabled);
widget.set_connected(is_connected);
widget.set_reasons(reasons);
if let Some(ref assignment) = GLOBALS.relay_picker.get_relay_assignment(&db_url) {
widget.set_user_count(assignment.pubkeys.len());
}

View File

@ -140,6 +140,7 @@ pub struct RelayEntry {
view: RelayEntryView,
enabled: bool,
connected: bool,
reasons: String,
user_count: Option<usize>,
usage: UsageBits,
accent: Color32,
@ -160,6 +161,7 @@ impl RelayEntry {
view: RelayEntryView::List,
enabled: true,
connected: false,
reasons: "".into(),
user_count: None,
usage,
accent,
@ -193,6 +195,10 @@ impl RelayEntry {
self.connected = connected;
}
pub fn set_reasons(&mut self, reasons: String) {
self.reasons = reasons;
}
// pub fn view(&self) -> RelayEntryView {
// self.view.clone()
// }
@ -441,12 +447,15 @@ impl RelayEntry {
}
fn paint_usage(&self, ui: &mut Ui, rect: &Rect) {
const RIGHT: f32 = -17.0;
const SPACE: f32 = 23.0;
let right = match self.view {
RelayEntryView::Detail => {
pos2(rect.max.x, rect.min.y) + vec2(-TEXT_RIGHT, TEXT_TOP + 30.0)
}
_ => {
pos2(rect.max.x, rect.min.y) + vec2(-TEXT_RIGHT -EDIT_BTN_SIZE - 10.0, TEXT_TOP + 4.0)
pos2(rect.max.x, rect.min.y) + vec2(-TEXT_RIGHT -EDIT_BTN_SIZE -SPACE, TEXT_TOP + 4.0)
}
};
@ -468,8 +477,9 @@ impl RelayEntry {
}
}
const RIGHT: f32 = -17.0;
const SPACE: f32 = 23.0;
// ---- usage text ----
let pos = right + vec2(RIGHT - 7.0 * SPACE, 0.0);
draw_text_at(ui, pos, self.reasons.clone().into(), Align::RIGHT, Some(ui.visuals().text_color()), None);
// ---- R ----
let pos = right + vec2(RIGHT - 5.0 * SPACE,0.0);