Ability to collapse threads

This commit is contained in:
Mike Dilger 2022-12-30 11:15:51 +13:00
parent 409860ab29
commit aeab1e98b1
2 changed files with 16 additions and 2 deletions

View File

@ -4,7 +4,8 @@ use crate::globals::{Globals, GLOBALS};
use crate::ui::widgets::{CopyButton, ReplyButton}; use crate::ui::widgets::{CopyButton, ReplyButton};
use eframe::egui; use eframe::egui;
use egui::{ use egui::{
Align, Color32, Context, Frame, Layout, RichText, ScrollArea, TextEdit, TextStyle, Ui, Vec2, Align, Color32, Context, Frame, Label, Layout, RichText, ScrollArea, Sense, TextEdit,
TextStyle, Ui, Vec2,
}; };
use nostr_types::{EventKind, Id}; use nostr_types::{EventKind, Id};
@ -201,6 +202,17 @@ fn render_post(
ui.horizontal(|ui| { ui.horizontal(|ui| {
// Indents first (if threaded) // Indents first (if threaded)
if threaded { if threaded {
#[allow(clippy::collapsible_else_if)]
if app.hides.contains(&id) {
if ui.add(Label::new("").sense(Sense::click())).clicked() {
app.hides.retain(|e| *e != id)
}
} else {
if ui.add(Label::new("").sense(Sense::click())).clicked() {
app.hides.push(id);
}
}
let space = 16.0 * (10.0 - (100.0 / (indent as f32 + 10.0))); let space = 16.0 * (10.0 - (100.0 / (indent as f32 + 10.0)));
ui.add_space(space); ui.add_space(space);
if indent > 0 { if indent > 0 {
@ -301,7 +313,7 @@ fn render_post(
ui.separator(); ui.separator();
if threaded && !as_reply_to { if threaded && !as_reply_to && !app.hides.contains(&id) {
for reply_id in replies { for reply_id in replies {
render_post(app, _ctx, _frame, ui, reply_id, indent + 1, as_reply_to); render_post(app, _ctx, _frame, ui, reply_id, indent + 1, as_reply_to);
} }

View File

@ -75,6 +75,7 @@ struct GossipUi {
import_bech32: String, import_bech32: String,
import_hex: String, import_hex: String,
replying_to: Option<Id>, replying_to: Option<Id>,
hides: Vec<Id>,
} }
impl Drop for GossipUi { impl Drop for GossipUi {
@ -141,6 +142,7 @@ impl GossipUi {
import_bech32: "".to_owned(), import_bech32: "".to_owned(),
import_hex: "".to_owned(), import_hex: "".to_owned(),
replying_to: None, replying_to: None,
hides: Vec::new(),
} }
} }
} }