Merge remote-tracking branch 'pr/80'

This commit is contained in:
William Casarin
2024-05-31 01:01:05 -05:00
26 changed files with 986 additions and 500 deletions

View File

@@ -1,12 +1,15 @@
use crate::account_manager::AccountManager;
use crate::app_creation::setup_cc;
use crate::app_style::user_requested_visuals_change;
use crate::error::Error;
use crate::frame_history::FrameHistory;
use crate::imgcache::ImageCache;
use crate::notecache::{CachedNote, NoteCache};
use crate::route::Route;
use crate::timeline;
use crate::timeline::{NoteRef, Timeline, ViewFilter};
use crate::ui::is_mobile;
use crate::ui::profile::SimpleProfilePreviewController;
use crate::ui::{is_mobile, DesktopSidePanel};
use crate::Result;
use egui::{Context, Frame, Style};
@@ -36,6 +39,8 @@ pub struct Damus {
note_cache: NoteCache,
pool: RelayPool,
/// global navigation for account management popups, etc.
nav: Vec<Route>,
pub textmode: bool,
pub timelines: Vec<Timeline>,
@@ -43,6 +48,7 @@ pub struct Damus {
pub img_cache: ImageCache,
pub ndb: Ndb,
pub account_manager: AccountManager,
frame_history: crate::frame_history::FrameHistory,
}
@@ -647,14 +653,47 @@ impl Damus {
img_cache: ImageCache::new(imgcache_dir),
note_cache: NoteCache::default(),
selected_timeline: 0,
nav: Vec::with_capacity(6),
timelines,
textmode: false,
ndb: Ndb::new(data_path.as_ref().to_str().expect("db path ok"), &config).expect("ndb"),
account_manager: AccountManager::new(
// TODO: should pull this from settings
None,
// TODO: use correct KeyStorage mechanism for current OS arch
crate::key_storage::KeyStorage::None,
),
//compose: "".to_string(),
frame_history: FrameHistory::default(),
}
}
pub fn mock<P: AsRef<Path>>(data_path: P) -> Self {
let mut timelines: Vec<Timeline> = vec![];
let _initial_limit = 100;
let filter = serde_json::from_str(include_str!("../queries/global.json")).unwrap();
timelines.push(Timeline::new(filter));
let imgcache_dir = data_path.as_ref().join(ImageCache::rel_datadir());
let _ = std::fs::create_dir_all(imgcache_dir.clone());
let mut config = Config::new();
config.set_ingester_threads(2);
Self {
state: DamusState::Initializing,
pool: RelayPool::new(),
img_cache: ImageCache::new(imgcache_dir),
note_cache: NoteCache::default(),
selected_timeline: 0,
timelines,
nav: vec![],
textmode: false,
ndb: Ndb::new(data_path.as_ref().to_str().expect("db path ok"), &config).expect("ndb"),
account_manager: AccountManager::new(None, crate::key_storage::KeyStorage::None),
frame_history: FrameHistory::default(),
}
}
pub fn note_cache_mut(&mut self) -> &mut NoteCache {
&mut self.note_cache
}
@@ -815,14 +854,6 @@ fn render_damus_desktop(ctx: &egui::Context, app: &mut Damus) {
Size::remainder()
};
if app.timelines.len() == 1 {
main_panel(&ctx.style()).show(ctx, |ui| {
timeline::timeline_view(ui, app, 0);
});
return;
}
main_panel(&ctx.style()).show(ctx, |ui| {
ui.spacing_mut().item_spacing.x = 0.0;
if need_scroll {
@@ -837,9 +868,24 @@ fn render_damus_desktop(ctx: &egui::Context, app: &mut Damus) {
fn timelines_view(ui: &mut egui::Ui, sizes: Size, app: &mut Damus, timelines: usize) {
StripBuilder::new(ui)
.size(Size::exact(40.0))
.sizes(sizes, timelines)
.clip(true)
.horizontal(|mut strip| {
strip.cell(|ui| {
let side_panel = DesktopSidePanel::new(
app.account_manager
.get_selected_account()
.map(|a| a.pubkey.bytes()),
SimpleProfilePreviewController::new(&app.ndb, &mut app.img_cache),
)
.show(ui);
if side_panel.response.clicked() {
info!("clicked {:?}", side_panel.action);
}
});
for timeline_ind in 0..timelines {
strip.cell(|ui| timeline::timeline_view(ui, app, timeline_ind));
}