mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-19 01:24:21 +01:00
feat(settings): persist settings to storage
This commit is contained in:
@@ -10,13 +10,11 @@ use crate::{
|
||||
subscriptions::{SubKind, Subscriptions},
|
||||
support::Support,
|
||||
timeline::{self, kind::ListKind, thread::Threads, TimelineCache, TimelineKind},
|
||||
ui::{self, DesktopSidePanel, SidePanelAction},
|
||||
ui::{self, DesktopSidePanel, ShowSourceClientOption, SidePanelAction},
|
||||
view_state::ViewState,
|
||||
Result,
|
||||
};
|
||||
|
||||
use crate::ui::settings::ShowNoteClientOption;
|
||||
|
||||
use egui_extras::{Size, StripBuilder};
|
||||
use enostr::{ClientMessage, PoolRelay, Pubkey, RelayEvent, RelayMessage, RelayPool};
|
||||
use nostrdb::Transaction;
|
||||
@@ -506,12 +504,12 @@ impl Damus {
|
||||
);
|
||||
note_options.set(
|
||||
NoteOptions::ShowNoteClientTop,
|
||||
ShowNoteClientOption::Top == app_context.settings_handler.show_source_client().into()
|
||||
ShowSourceClientOption::Top == app_context.settings_handler.show_source_client().into()
|
||||
|| parsed_args.is_flag_set(ColumnsFlag::ShowNoteClientTop),
|
||||
);
|
||||
note_options.set(
|
||||
NoteOptions::ShowNoteClientBottom,
|
||||
ShowNoteClientOption::Bottom
|
||||
ShowSourceClientOption::Bottom
|
||||
== app_context.settings_handler.show_source_client().into()
|
||||
|| parsed_args.is_flag_set(ColumnsFlag::ShowNoteClientBottom),
|
||||
);
|
||||
|
||||
@@ -21,7 +21,7 @@ use crate::{
|
||||
note::{custom_zap::CustomZapView, NewPostAction, PostAction, PostType, QuoteRepostView},
|
||||
profile::EditProfileView,
|
||||
search::{FocusState, SearchView},
|
||||
settings::SettingsAction,
|
||||
settings::{SettingsAction, ShowSourceClientOption},
|
||||
support::SupportView,
|
||||
wallet::{get_default_zap_state, WalletAction, WalletState, WalletView},
|
||||
AccountsView, PostReplyView, PostView, ProfileView, RelayView, SettingsView, ThreadView,
|
||||
@@ -30,8 +30,6 @@ use crate::{
|
||||
Damus,
|
||||
};
|
||||
|
||||
use crate::ui::settings::ShowNoteClientOption;
|
||||
|
||||
use egui_nav::{Nav, NavAction, NavResponse, NavUiType, Percent, PopupResponse, PopupSheet};
|
||||
use enostr::ProfileState;
|
||||
use nostrdb::{Filter, Ndb, Transaction};
|
||||
@@ -588,7 +586,7 @@ fn render_nav_body(
|
||||
.map(RenderNavAction::RelayAction),
|
||||
|
||||
Route::Settings => {
|
||||
let mut show_note_client: ShowNoteClientOption = app.note_options.into();
|
||||
let mut show_note_client: ShowSourceClientOption = app.note_options.into();
|
||||
|
||||
let mut theme: String = (if ui.visuals().dark_mode {
|
||||
"Dark"
|
||||
|
||||
@@ -26,7 +26,7 @@ pub use preview::{Preview, PreviewApp, PreviewConfig};
|
||||
pub use profile::ProfileView;
|
||||
pub use relay::RelayView;
|
||||
pub use settings::SettingsView;
|
||||
pub use settings::ShowNoteClientOption;
|
||||
pub use settings::ShowSourceClientOption;
|
||||
pub use side_panel::{DesktopSidePanel, SidePanelAction};
|
||||
pub use thread::ThreadView;
|
||||
pub use timeline::TimelineView;
|
||||
|
||||
@@ -6,35 +6,35 @@ use strum::Display;
|
||||
use crate::{nav::RouterAction, Damus, Route};
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Display)]
|
||||
pub enum ShowNoteClientOption {
|
||||
pub enum ShowSourceClientOption {
|
||||
Hide,
|
||||
Top,
|
||||
Bottom,
|
||||
}
|
||||
|
||||
impl From<ShowNoteClientOption> for String {
|
||||
fn from(value: ShowNoteClientOption) -> Self {
|
||||
match value {
|
||||
ShowNoteClientOption::Hide => "hide".to_string(),
|
||||
ShowNoteClientOption::Top => "top".to_string(),
|
||||
ShowNoteClientOption::Bottom => "bottom".to_string(),
|
||||
impl Into<String> for ShowSourceClientOption {
|
||||
fn into(self) -> String {
|
||||
match self {
|
||||
Self::Hide => "hide".to_string(),
|
||||
Self::Top => "top".to_string(),
|
||||
Self::Bottom => "bottom".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<NoteOptions> for ShowNoteClientOption {
|
||||
impl From<NoteOptions> for ShowSourceClientOption {
|
||||
fn from(note_options: NoteOptions) -> Self {
|
||||
if note_options.contains(NoteOptions::ShowNoteClientTop) {
|
||||
ShowNoteClientOption::Top
|
||||
ShowSourceClientOption::Top
|
||||
} else if note_options.contains(NoteOptions::ShowNoteClientBottom) {
|
||||
ShowNoteClientOption::Bottom
|
||||
ShowSourceClientOption::Bottom
|
||||
} else {
|
||||
ShowNoteClientOption::Hide
|
||||
ShowSourceClientOption::Hide
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for ShowNoteClientOption {
|
||||
impl From<String> for ShowSourceClientOption {
|
||||
fn from(s: String) -> Self {
|
||||
match s.to_lowercase().as_str() {
|
||||
"hide" => Self::Hide,
|
||||
@@ -45,7 +45,7 @@ impl From<String> for ShowNoteClientOption {
|
||||
}
|
||||
}
|
||||
|
||||
impl ShowNoteClientOption {
|
||||
impl ShowSourceClientOption {
|
||||
pub fn set_note_options(self, note_options: &mut NoteOptions) {
|
||||
match self {
|
||||
Self::Hide => {
|
||||
@@ -67,7 +67,7 @@ impl ShowNoteClientOption {
|
||||
pub enum SettingsAction {
|
||||
SetZoomFactor(f32),
|
||||
SetTheme(ThemePreference),
|
||||
SetShowSourceClient(ShowNoteClientOption),
|
||||
SetShowSourceClient(ShowSourceClientOption),
|
||||
SetLocale(LanguageIdentifier),
|
||||
OpenRelays,
|
||||
OpenCacheFolder,
|
||||
@@ -125,7 +125,7 @@ impl SettingsAction {
|
||||
pub struct SettingsView<'a> {
|
||||
theme: &'a mut String,
|
||||
selected_language: &'a mut String,
|
||||
show_note_client: &'a mut ShowNoteClientOption,
|
||||
show_note_client: &'a mut ShowSourceClientOption,
|
||||
i18n: &'a mut Localization,
|
||||
img_cache: &'a mut Images,
|
||||
}
|
||||
@@ -135,7 +135,7 @@ impl<'a> SettingsView<'a> {
|
||||
img_cache: &'a mut Images,
|
||||
selected_language: &'a mut String,
|
||||
theme: &'a mut String,
|
||||
show_note_client: &'a mut ShowNoteClientOption,
|
||||
show_note_client: &'a mut ShowSourceClientOption,
|
||||
i18n: &'a mut Localization,
|
||||
) -> Self {
|
||||
Self {
|
||||
@@ -160,19 +160,19 @@ impl<'a> SettingsView<'a> {
|
||||
}
|
||||
|
||||
/// Get the localized label for ShowNoteClientOption
|
||||
fn get_show_note_client_label(&mut self, option: ShowNoteClientOption) -> String {
|
||||
fn get_show_note_client_label(&mut self, option: ShowSourceClientOption) -> String {
|
||||
match option {
|
||||
ShowNoteClientOption::Hide => tr!(
|
||||
ShowSourceClientOption::Hide => tr!(
|
||||
self.i18n,
|
||||
"Hide",
|
||||
"Option in settings section to hide the source client label in note display"
|
||||
),
|
||||
ShowNoteClientOption::Top => tr!(
|
||||
ShowSourceClientOption::Top => tr!(
|
||||
self.i18n,
|
||||
"Top",
|
||||
"Option in settings section to show the source client label at the top of the note"
|
||||
),
|
||||
ShowNoteClientOption::Bottom => tr!(
|
||||
ShowSourceClientOption::Bottom => tr!(
|
||||
self.i18n,
|
||||
"Bottom",
|
||||
"Option in settings section to show the source client label at the bottom of the note"
|
||||
@@ -463,9 +463,9 @@ impl<'a> SettingsView<'a> {
|
||||
);
|
||||
|
||||
for option in [
|
||||
ShowNoteClientOption::Hide,
|
||||
ShowNoteClientOption::Top,
|
||||
ShowNoteClientOption::Bottom,
|
||||
ShowSourceClientOption::Hide,
|
||||
ShowSourceClientOption::Top,
|
||||
ShowSourceClientOption::Bottom,
|
||||
] {
|
||||
let label = self.get_show_note_client_label(option);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user