mirror of
https://github.com/aljazceru/notedeck.git
synced 2026-01-25 19:24:20 +01:00
fun large profile grid preview
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user