mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 19:46:50 +00:00
Settings page setup and plumbed
This commit is contained in:
parent
2dfaee72ab
commit
a6feac8d4f
@ -294,7 +294,18 @@ impl Overlord {
|
||||
// FIXME: Handle EventKind::ContactList
|
||||
}
|
||||
}
|
||||
"minion_is_ready" => {}
|
||||
"minion_is_ready" => {},
|
||||
"save_settings" => {
|
||||
let settings: Settings = serde_json::from_str(&bus_message.json_payload)?;
|
||||
|
||||
// Save to database
|
||||
settings.save().await?; // to database
|
||||
|
||||
// Update in globals
|
||||
*GLOBALS.settings.lock().await = settings;
|
||||
|
||||
debug!("Settings saved.");
|
||||
},
|
||||
_ => {}
|
||||
},
|
||||
_ => {}
|
||||
|
@ -106,7 +106,7 @@ fn render_post(
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
// Indents first (if threaded)
|
||||
if app.threaded {
|
||||
if app.settings.view_threaded {
|
||||
for _ in 0..indent {
|
||||
ui.add_space(8.0);
|
||||
ui.separator();
|
||||
@ -170,7 +170,7 @@ fn render_post(
|
||||
|
||||
ui.separator();
|
||||
|
||||
if app.threaded {
|
||||
if app.settings.view_threaded {
|
||||
for reply_id in fevent.replies {
|
||||
render_post(app, _ctx, _frame, ui, reply_id, indent + 1);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ mod you;
|
||||
use crate::about::About;
|
||||
use crate::error::Error;
|
||||
use crate::globals::GLOBALS;
|
||||
use crate::settings::Settings;
|
||||
use eframe::{egui, IconData, Theme};
|
||||
use egui::{ColorImage, Context, ImageData, TextureHandle, TextureOptions};
|
||||
|
||||
@ -59,7 +60,7 @@ struct GossipUi {
|
||||
icon: TextureHandle,
|
||||
placeholder_avatar: TextureHandle,
|
||||
draft: String,
|
||||
threaded: bool,
|
||||
settings: Settings,
|
||||
}
|
||||
|
||||
impl GossipUi {
|
||||
@ -102,7 +103,7 @@ impl GossipUi {
|
||||
)
|
||||
};
|
||||
|
||||
let threaded = GLOBALS.settings.blocking_lock().view_threaded;
|
||||
let settings = GLOBALS.settings.blocking_lock().clone();
|
||||
|
||||
GossipUi {
|
||||
page: Page::Feed,
|
||||
@ -110,7 +111,7 @@ impl GossipUi {
|
||||
icon: icon_texture_handle,
|
||||
placeholder_avatar: placeholder_avatar_texture_handle,
|
||||
draft: "".to_owned(),
|
||||
threaded,
|
||||
settings: settings,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
use crate::GLOBALS;
|
||||
use crate::comms::BusMessage;
|
||||
use super::GossipUi;
|
||||
use eframe::egui;
|
||||
use egui::widgets::Button;
|
||||
use egui::{Context, Ui};
|
||||
use egui::{Align, Context, Layout, Ui};
|
||||
use egui::widgets::{Button, Slider};
|
||||
|
||||
pub(super) fn update(
|
||||
_app: &mut GossipUi,
|
||||
app: &mut GossipUi,
|
||||
_ctx: &Context,
|
||||
_frame: &mut eframe::Frame,
|
||||
ui: &mut Ui,
|
||||
@ -12,6 +14,50 @@ pub(super) fn update(
|
||||
) {
|
||||
ui.heading("Settings");
|
||||
|
||||
ui.separator();
|
||||
|
||||
ui.add_space(24.0);
|
||||
ui.heading("How Many Posts to Load");
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Feed Chunk: ").on_hover_text("This is the amount of time backwards from now that we will load events from. You'll eventually be able to load more, one chunk at a time. Mostly takes effect on restart.");
|
||||
ui.add(Slider::new(&mut app.settings.feed_chunk, 600..=86400).text("seconds, "));
|
||||
ui.label(secs_to_string(app.settings.feed_chunk));
|
||||
});
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Overlap: ").on_hover_text("If we recently loaded events up to time T, but restarted, we will now load events starting from time T minus overlap. Takes effect on restart.");
|
||||
ui.add(Slider::new(&mut app.settings.overlap, 0..=3600).text("seconds, "));
|
||||
ui.label(secs_to_string(app.settings.overlap));
|
||||
});
|
||||
|
||||
ui.add_space(24.0);
|
||||
ui.heading("Feed Style / Order");
|
||||
|
||||
ui.checkbox(&mut app.settings.view_threaded, "Threaded feed")
|
||||
.on_hover_text("If selected, replies are under what they reply to and the newest replied-to thread comes first. Otherwise all posts are independent and in time order.");
|
||||
|
||||
ui.add_space(24.0);
|
||||
ui.heading("What Posts to Include");
|
||||
|
||||
ui.checkbox(&mut app.settings.view_posts_referred_to, "View posts referred to by people you follow (not yet implemented)")
|
||||
.on_hover_text("Recommended, otherwise it's hard to understand what the person is talking about.");
|
||||
|
||||
ui.checkbox(&mut app.settings.view_posts_referring_to, "View posts referring to posts by people you follow (not yet implemented)")
|
||||
.on_hover_text("Not recommended, as anyone can reply to them and you'll certainly encounter spam this way.");
|
||||
|
||||
ui.add_space(24.0);
|
||||
ui.heading("Miscellaneous");
|
||||
|
||||
ui.checkbox(&mut app.settings.autofollow, "Autofollow everybody (not yet implemented)")
|
||||
.on_hover_text("Definately not recommended. In fact we may remove this soon.");
|
||||
|
||||
ui.add_space(24.0);
|
||||
ui.heading("Style");
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Switch to");
|
||||
|
||||
#[allow(clippy::collapsible_else_if)]
|
||||
if darkmode {
|
||||
if ui
|
||||
@ -30,6 +76,34 @@ pub(super) fn update(
|
||||
ui.ctx().set_visuals(super::style::dark_mode_visuals());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ui.label("SETTINGS PAGE - Coming Soon".to_string());
|
||||
ui.add_space(32.0);
|
||||
ui.with_layout(Layout::top_down(Align::Center), |ui| {
|
||||
if ui.button("SAVE CHANGES").clicked() {
|
||||
let tx = GLOBALS.to_overlord.clone();
|
||||
let _ = tx.send(BusMessage {
|
||||
target: "overlord".to_string(),
|
||||
kind: "save_settings".to_string(),
|
||||
json_payload: serde_json::to_string(&app.settings).unwrap()
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
fn secs_to_string(secs: u64) -> String {
|
||||
|
||||
let days = secs / 86400;
|
||||
let remainder = secs % 86400;
|
||||
let hours = remainder / 3600;
|
||||
let remainder = remainder % 3600;
|
||||
let minutes = remainder / 60;
|
||||
let seconds = remainder % 60;
|
||||
let mut output: String = String::new();
|
||||
if days>0 { output.push_str(&format!(" {} days", days)); }
|
||||
if hours>0 { output.push_str(&format!(" {} hours", hours)); }
|
||||
if minutes>0 { output.push_str(&format!(" {} minutes", minutes)); }
|
||||
output.push_str(&format!(" {} seconds", seconds));
|
||||
output
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user