Skip to content

Commit

Permalink
fixed notification bubble updating when field edited
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikwilkowski committed Jan 14, 2024
1 parent aec1549 commit 9ac804e
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 114 deletions.
26 changes: 15 additions & 11 deletions src/ui/app_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,21 @@ pub fn app_view(config: Config) -> impl View {
.hover(|s| s.cursor(CursorStyle::Pointer))
.apply_if(!search_text.get().is_empty(), |s| s.display(Display::Flex))
}),
icon_button(String::from(settings_icon), 0, |_| {
opening_window(
settings_view,
WindowSpec {
id: String::from("settings-window"),
title: String::from("Vault Settings"),
},
Size::new(430.0, 400.0),
|| {},
);
}),
icon_button(
String::from(settings_icon),
create_rw_signal(Vec::new()),
|_| {
opening_window(
settings_view,
WindowSpec {
id: String::from("settings-window"),
title: String::from("Vault Settings"),
},
Size::new(430.0, 400.0),
|| {},
);
},
),
))
.style(|s| {
s.z_index(3)
Expand Down
84 changes: 53 additions & 31 deletions src/ui/details/button_slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ pub fn view_button_slot(

if is_secret {
h_stack((
icon_button(String::from(see_icon), 0, move |_| {
let data = getter();
value.set(data);
see_btn_visible.set(false);
hide_btn_visible.set(true);
tooltip_signals.hide();
})
icon_button(
String::from(see_icon),
create_rw_signal(Vec::new()),
move |_| {
let data = getter();
value.set(data);
see_btn_visible.set(false);
hide_btn_visible.set(true);
tooltip_signals.hide();
},
)
.style(move |s| {
s.apply_if(!see_btn_visible.get(), |s| s.display(Display::None))
})
Expand All @@ -57,12 +61,16 @@ pub fn view_button_slot(
}
EventPropagation::Continue
}),
icon_button(String::from(hide_icon), 0, move |_| {
value.set(String::from(SECRET_PLACEHOLDER));
see_btn_visible.set(true);
hide_btn_visible.set(false);
tooltip_signals.hide();
})
icon_button(
String::from(hide_icon),
create_rw_signal(Vec::new()),
move |_| {
value.set(String::from(SECRET_PLACEHOLDER));
see_btn_visible.set(true);
hide_btn_visible.set(false);
tooltip_signals.hide();
},
)
.style(move |s| {
s.apply_if(!hide_btn_visible.get(), |s| s.display(Display::None))
})
Expand Down Expand Up @@ -90,10 +98,14 @@ pub fn clipboard_button_slot(
) -> impl View {
let clipboard_icon = include_str!("../icons/clipboard.svg");

container(icon_button(String::from(clipboard_icon), 0, move |_| {
let data = getter();
let _ = Clipboard::set_contents(data);
}))
container(icon_button(
String::from(clipboard_icon),
create_rw_signal(Vec::new()),
move |_| {
let data = getter();
let _ = Clipboard::set_contents(data);
},
))
.on_event(EventListener::PointerEnter, move |_event| {
tooltip_signals.show(String::from("Copy to clipboard"));
EventPropagation::Continue
Expand All @@ -104,14 +116,26 @@ pub fn clipboard_button_slot(
})
}

pub fn history_button_slot(
id: usize,
field: DbFields,
is_secret: bool,
field_title: String,
tooltip_signals: TooltipSignals,
config: Config,
) -> impl View {
pub struct HistoryButtonSlot {
pub id: usize,
pub field: DbFields,
pub dates: RwSignal<Vec<(usize, u64)>>,
pub is_secret: bool,
pub field_title: String,
pub tooltip_signals: TooltipSignals,
pub config: Config,
}

pub fn history_button_slot(param: HistoryButtonSlot) -> impl View {
let HistoryButtonSlot {
id,
field,
dates,
is_secret,
field_title,
tooltip_signals,
config,
} = param;
let history_icon = include_str!("../icons/history.svg");
let hide_history_icon = include_str!("../icons/hide_history.svg");

Expand All @@ -120,15 +144,13 @@ pub fn history_button_slot(

if is_secret {
let config_history = config.clone();
let dates = config.db.read().unwrap().get_history_dates(&id, &field);
let dates_len = dates.len();

h_stack((
icon_button(String::from(history_icon), dates_len, move |_| {
icon_button(String::from(history_icon), dates, move |_| {
let config_history_inner = config_history.clone();
tooltip_signals.hide();
let window_title = format!("{} Field History", field_title);
let dates_window = dates.clone();
let dates_window = dates.get();

opening_window(
move || {
Expand Down Expand Up @@ -168,7 +190,7 @@ pub fn history_button_slot(
}
EventPropagation::Continue
}),
icon_button(String::from(hide_history_icon), dates_len, move |_| {
icon_button(String::from(hide_history_icon), dates, move |_| {
closing_window(make_field_path(id, &field), || {
history_btn_visible.set(true);
hide_history_btn_visible.set(false);
Expand Down Expand Up @@ -232,7 +254,7 @@ pub fn delete_button_slot(param: DeleteButtonSlot) -> impl View {
} else {
String::from(delete_icon)
},
0,
create_rw_signal(Vec::new()),
move |_| {
tooltip_signals.hide();
if is_hidden {
Expand Down
4 changes: 4 additions & 0 deletions src/ui/details/detail_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct SaveEdit {
pub id: usize,
pub field: DbFields,
pub value: RwSignal<String>,
pub dates: RwSignal<Vec<(usize, u64)>>,
pub is_secret: bool,
pub tooltip_signals: TooltipSignals,
pub edit_btn_visible: RwSignal<bool>,
Expand All @@ -48,6 +49,7 @@ pub fn save_edit(params: SaveEdit) {
id,
field,
value,
dates,
is_secret,
tooltip_signals,
edit_btn_visible,
Expand All @@ -65,6 +67,8 @@ pub fn save_edit(params: SaveEdit) {
});
}

dates.set(config.db.read().unwrap().get_history_dates(&id, &field));

edit_btn_visible.set(true);
save_btn_visible.set(false);
tooltip_signals.hide();
Expand Down
72 changes: 43 additions & 29 deletions src/ui/details/list_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
details::{
button_slots::{
clipboard_button_slot, delete_button_slot, history_button_slot,
view_button_slot, DeleteButtonSlot,
view_button_slot, DeleteButtonSlot, HistoryButtonSlot,
},
detail_view::{
save_edit, SaveEdit, INPUT_LINE_WIDTH, LINE_WIDTH, SECRET_PLACEHOLDER,
Expand Down Expand Up @@ -61,6 +61,8 @@ pub fn list_item(param: ListItem) -> impl View {
let edit_btn_visible = create_rw_signal(true);
let save_btn_visible = create_rw_signal(false);
let reset_text = create_rw_signal(String::from(""));
let dates =
create_rw_signal(config.db.read().unwrap().get_history_dates(&id, &field));

let field_title = match field {
DbFields::Fields(_) => {
Expand Down Expand Up @@ -125,6 +127,7 @@ pub fn list_item(param: ListItem) -> impl View {
id,
field,
value: field_value,
dates,
is_secret,
tooltip_signals,
edit_btn_visible,
Expand Down Expand Up @@ -171,17 +174,21 @@ pub fn list_item(param: ListItem) -> impl View {
let edit_slot = if is_hidden {
container(label(|| "")).style(|s| s.width(26.5))
} else {
container(icon_button(String::from(edit_icon), 0, move |_| {
reset_text.set(field_value.get());
edit_btn_visible.set(false);
save_btn_visible.set(true);
tooltip_signals.hide();
if is_secret {
field_value
.set(config_edit.db.read().unwrap().get_last_by_field(&id, &field));
}
input_id.request_focus();
}))
container(icon_button(
String::from(edit_icon),
create_rw_signal(Vec::new()),
move |_| {
reset_text.set(field_value.get());
edit_btn_visible.set(false);
save_btn_visible.set(true);
tooltip_signals.hide();
if is_secret {
field_value
.set(config_edit.db.read().unwrap().get_last_by_field(&id, &field));
}
input_id.request_focus();
},
))
.style(move |s| {
s.apply_if(!edit_btn_visible.get(), |s| s.display(Display::None))
})
Expand Down Expand Up @@ -210,6 +217,7 @@ pub fn list_item(param: ListItem) -> impl View {
id,
field,
value: field_value,
dates,
is_secret,
tooltip_signals,
edit_btn_visible,
Expand Down Expand Up @@ -251,20 +259,25 @@ pub fn list_item(param: ListItem) -> impl View {
)),
h_stack((
edit_slot,
icon_button(String::from(save_icon), 0, move |_| {
save_edit(SaveEdit {
id,
field,
value: field_value,
is_secret,
tooltip_signals,
edit_btn_visible,
save_btn_visible,
input_id,
set_list,
config: config_save.clone(),
});
})
icon_button(
String::from(save_icon),
create_rw_signal(Vec::new()),
move |_| {
save_edit(SaveEdit {
id,
field,
value: field_value,
dates,
is_secret,
tooltip_signals,
edit_btn_visible,
save_btn_visible,
input_id,
set_list,
config: config_save.clone(),
});
},
)
.style(move |s| {
s.apply_if(!save_btn_visible.get(), |s| s.display(Display::None))
}),
Expand All @@ -290,14 +303,15 @@ pub fn list_item(param: ListItem) -> impl View {
view_button_slot(is_secret, tooltip_signals, field_value, move || {
config_viewbtn.db.read().unwrap().get_last_by_field(&id, &field)
}),
history_button_slot(
history_button_slot(HistoryButtonSlot {
id,
field,
dates,
is_secret,
field_title,
tooltip_signals,
config_history,
),
config: config_history,
}),
delete_button_slot(DeleteButtonSlot {
id,
field,
Expand Down
Loading

0 comments on commit 9ac804e

Please sign in to comment.