More person list pages work

This commit is contained in:
Mike Dilger 2023-11-29 12:06:47 +13:00
parent 358a04c612
commit df7af04299
2 changed files with 35 additions and 33 deletions

View File

@ -12,22 +12,26 @@ pub(super) fn update(
ui: &mut Ui,
list: PersonList,
) {
let members = GLOBALS
.storage
.get_people_in_list(list)
.unwrap_or_default();
let people = {
let members = GLOBALS
.storage
.get_people_in_list(list)
.unwrap_or_default();
let mut people: Vec<(Person, bool)> = Vec::new();
for (pk, public) in &members {
if let Ok(Some(person)) = GLOBALS.storage.read_person(pk) {
people.push((person, *public));
} else {
let person = Person::new(pk.to_owned());
let _ = GLOBALS.storage.write_person(&person, None);
people.push((person, *public));
let mut people: Vec<(Person, bool)> = Vec::new();
for (pk, public) in &members {
if let Ok(Some(person)) = GLOBALS.storage.read_person(pk) {
people.push((person, *public));
} else {
let person = Person::new(pk.to_owned());
let _ = GLOBALS.storage.write_person(&person, None);
people.push((person, *public));
}
}
}
people.sort_by(|a,b| a.0.cmp(&b.0));
people.sort_by(|a,b| a.0.cmp(&b.0));
people
};
ui.add_space(12.0);
@ -193,11 +197,20 @@ pub(super) fn update(
.color(app.theme.warning_marker_text_color()),
);
}
});
// FIXME indicate if public or not
ui.horizontal(|ui| {
if crate::ui::components::switch_simple(ui, *public).clicked() {
let _ = GLOBALS.storage.add_person_to_list(&person.pubkey, list, !*public, None);
}
ui.label(if *public { "public" } else { "private" });
});
});
});
if ui.button("Remove").clicked() {
let _ = GLOBALS.storage.remove_person_from_list(&person.pubkey, list, None);
}
ui.add_space(4.0);
ui.separator();
}

View File

@ -27,17 +27,17 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
};
if matches!(list, PersonList::Custom(_)) {
if ui.button("DELETE").clicked() {
// FIXME -- confirm with a popup, then call the delete() function (see below)
GLOBALS
.status_queue
.write()
.write("Person List Delete is NOT YET IMPLEMENTED".to_string());
// FIXME -- confirm with a popup first!
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::DeletePersonList(list));
}
}
});
}
if ui.button("Create a new list").clicked() {
// FIXME -- prompt for a name with a popup, then call the create() function (see below)
// FIXME -- prompt for a name with a popup, then create with:
// let _ = PersonList::allocate(name, None);
GLOBALS
.status_queue
.write()
@ -48,14 +48,3 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
ui.separator();
ui.add_space(10.0);
}
fn delete(list: PersonList) {
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::ClearPersonList(list));
let _ = list.deallocate(None);
}
fn create(name: &str) {
let _ = PersonList::allocate(name, None);
}