note: add copy note json

very handy
This commit is contained in:
William Casarin
2024-12-11 16:12:25 -08:00
parent a429ff689c
commit aa14fb092d

View File

@@ -2,6 +2,7 @@ use crate::colors;
use egui::{Rect, Vec2}; use egui::{Rect, Vec2};
use enostr::{NoteId, Pubkey}; use enostr::{NoteId, Pubkey};
use nostrdb::{Note, NoteKey}; use nostrdb::{Note, NoteKey};
use tracing::error;
#[derive(Clone)] #[derive(Clone)]
#[allow(clippy::enum_variant_names)] #[allow(clippy::enum_variant_names)]
@@ -9,6 +10,7 @@ pub enum NoteContextSelection {
CopyText, CopyText,
CopyPubkey, CopyPubkey,
CopyNoteId, CopyNoteId,
CopyNoteJSON,
} }
impl NoteContextSelection { impl NoteContextSelection {
@@ -33,6 +35,12 @@ impl NoteContextSelection {
} }
}); });
} }
NoteContextSelection::CopyNoteJSON => {
ui.output_mut(|w| match note.json() {
Ok(json) => w.copied_text = json,
Err(err) => error!("error copying note json: {err}"),
});
}
} }
} }
} }
@@ -162,6 +170,10 @@ impl NoteContextButton {
context_selection = Some(NoteContextSelection::CopyNoteId); context_selection = Some(NoteContextSelection::CopyNoteId);
ui.close_menu(); ui.close_menu();
} }
if ui.button("Copy note json").clicked() {
context_selection = Some(NoteContextSelection::CopyNoteJSON);
ui.close_menu();
}
}); });
context_selection context_selection