notedeck

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

commit 7ec31d0eaee2aa816d4a40f5ec8a6ad4646b6570
parent e8168b0004fb994b27b9f8a9cab368229f9132ec
Author: William Casarin <jb55@jb55.com>
Date:   Tue, 23 Apr 2024 20:43:30 -0700

fun large profile grid preview

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

Diffstat:
Mpreview | 2+-
Msrc/ui/profile/picture.rs | 62+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Msrc/ui/relay.rs | 2+-
Msrc/ui_preview/main.rs | 4++--
4 files changed, 65 insertions(+), 5 deletions(-)

diff --git a/preview b/preview @@ -1,2 +1,2 @@ #!/usr/bin/env bash -cargo run --bin ui_preview -- "$@" +cargo run --bin ui_preview --release -- "$@" diff --git a/src/ui/profile/picture.rs b/src/ui/profile/picture.rs @@ -1,5 +1,5 @@ use crate::imgcache::ImageCache; - +use crate::ui::{Preview, View}; use egui::{vec2, Sense, TextureHandle}; pub struct ProfilePic<'cache, 'url> { @@ -97,3 +97,63 @@ fn paint_circle(ui: &mut egui::Ui, size: f32) -> egui::Response { response } + +mod preview { + use super::*; + use nostrdb::*; + use std::collections::HashSet; + + pub struct ProfilePicPreview { + cache: ImageCache, + urls: Vec<String>, + } + + impl ProfilePicPreview { + fn new() -> Self { + let config = Config::new(); + let ndb = Ndb::new(".", &config).expect("ndb"); + let txn = Transaction::new(&ndb).unwrap(); + let filters = vec![Filter::new().kinds(vec![0]).build()]; + let cache = ImageCache::new("cache/img".into()); + let mut pks = HashSet::new(); + let mut urls = HashSet::new(); + + for query_result in ndb.query(&txn, filters, 1000).unwrap() { + pks.insert(query_result.note.pubkey()); + } + + for pk in pks { + let profile = if let Ok(profile) = ndb.get_profile_by_pubkey(&txn, pk) { + profile + } else { + continue; + }; + if let Some(url) = profile.record().profile().and_then(|p| p.picture()) { + urls.insert(url.to_string()); + } + } + + let urls = urls.into_iter().collect(); + + ProfilePicPreview { cache, urls } + } + } + + impl View for ProfilePicPreview { + fn ui(&mut self, ui: &mut egui::Ui) { + ui.horizontal_wrapped(|ui| { + for url in &self.urls { + ui.add(ProfilePic::new(&mut self.cache, &url)); + } + }); + } + } + + impl<'cache, 'url> Preview for ProfilePic<'cache, 'url> { + type Prev = ProfilePicPreview; + + fn preview() -> Self::Prev { + ProfilePicPreview::new() + } + } +} diff --git a/src/ui/relay.rs b/src/ui/relay.rs @@ -193,7 +193,7 @@ mod preview { impl View for RelayViewPreview { fn ui(&mut self, ui: &mut egui::Ui) { self.pool.try_recv(); - RelayView::new(RelayPoolManager::new(&mut self.pool)).ui(ui) + RelayView::new(RelayPoolManager::new(&mut self.pool)).ui(ui); } } diff --git a/src/ui_preview/main.rs b/src/ui_preview/main.rs @@ -2,7 +2,7 @@ use notedeck::account_login_view::AccountLoginView; use notedeck::app_creation::{ generate_mobile_emulator_native_options, generate_native_options, setup_cc, }; -use notedeck::ui::{Preview, PreviewApp, ProfilePreview, RelayView}; +use notedeck::ui::{Preview, PreviewApp, ProfilePreview, RelayView, ProfilePic}; use std::env; struct PreviewRunner { @@ -73,5 +73,5 @@ async fn main() { let runner = PreviewRunner::new(is_mobile); - previews!(runner, name, RelayView, AccountLoginView, ProfilePreview,); + previews!(runner, name, RelayView, AccountLoginView, ProfilePreview, ProfilePic); }