notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit a5e1fbf3280e85b235e893e3d8eb06373c69447f
parent 349e3baa995199afe9211d28cbebae27bc4e911a
Author: kernelkind <kernelkind@gmail.com>
Date:   Wed, 17 Apr 2024 13:36:26 -0400

Add preview for RelayView

Signed-off-by: kernelkind <kernelkind@gmail.com>
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Msrc/ui_preview/main.rs | 12+++++++++++-
Asrc/ui_preview/relay_view_preview.rs | 35+++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/src/ui_preview/main.rs b/src/ui_preview/main.rs @@ -1,11 +1,15 @@ mod account_login_preview; mod egui_preview_setup; +mod relay_view_preview; use account_login_preview::{DesktopAccountLoginPreview, MobileAccountLoginPreview}; use egui_preview_setup::{EguiPreviewCase, EguiPreviewSetup}; use notedeck::app_creation::{generate_mobile_emulator_native_options, generate_native_options}; +use relay_view_preview::RelayViewPreview; use std::env; -fn run_test_app<F, T, O>(create_supr: F, create_child: O, is_mobile: bool) +#[cfg(not(target_arch = "wasm32"))] +#[tokio::main] +async fn run_test_app<F, T, O>(create_supr: F, create_child: O, is_mobile: bool) where F: 'static + FnOnce(&eframe::CreationContext<'_>) -> EguiPreviewSetup, T: 'static + EguiPreviewCase, @@ -39,6 +43,12 @@ fn main() { "MobileAccountLoginPreview" => { run_test_app(EguiPreviewSetup::new, MobileAccountLoginPreview::new, true) } + "DesktopRelayViewPreview" => { + run_test_app(EguiPreviewSetup::new, RelayViewPreview::new, false) + } + "MobileRelayViewPreview" => { + run_test_app(EguiPreviewSetup::new, RelayViewPreview::new, true) + } _ => println!("Component not found."), } } else { diff --git a/src/ui_preview/relay_view_preview.rs b/src/ui_preview/relay_view_preview.rs @@ -0,0 +1,35 @@ +use enostr::RelayPool; +use notedeck::{relay_pool_manager::RelayPoolManager, relay_view::RelayView}; + +use crate::egui_preview_setup::{EguiPreviewCase, EguiPreviewSetup}; + +pub struct RelayViewPreview { + pool: RelayPool, +} + +#[allow(unused_must_use)] +impl EguiPreviewCase for RelayViewPreview { + fn new(_supr: EguiPreviewSetup) -> Self { + let mut pool = RelayPool::new(); + let wakeup = move || {}; + + pool.add_url("wss://relay.damus.io".to_string(), wakeup); + pool.add_url("wss://eden.nostr.land".to_string(), wakeup); + pool.add_url("wss://nostr.wine".to_string(), wakeup); + pool.add_url("wss://nos.lol".to_string(), wakeup); + pool.add_url("wss://test_relay_url_long_00000000000000000000000000000000000000000000000000000000000000000000000000000000000".to_string(), wakeup); + + for _ in 0..20 { + pool.add_url("tmp".to_string(), wakeup); + } + + RelayViewPreview { pool } + } +} + +impl eframe::App for RelayViewPreview { + fn update(&mut self, ctx: &egui::Context, _: &mut eframe::Frame) { + self.pool.try_recv(); + RelayView::new(ctx, RelayPoolManager::new(&mut self.pool)).panel(); + } +}