Skip to content

Commit

Permalink
feat(Lists): simplify remove design (#1255)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeopJr authored Dec 10, 2024
1 parent 28336ca commit c41700a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
2 changes: 1 addition & 1 deletion data/ui/dialogs/list_edit.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<property name="title" translatable="yes">Members</property>
<child>
<object class="AdwPreferencesGroup" id="members_group">
<property name="title" translatable="yes">Remove Members</property>
<property name="title" translatable="yes">Members</property>
</object>
</child>
</object>
Expand Down
45 changes: 30 additions & 15 deletions src/Dialogs/ListEdit.vala
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,23 @@ public class Tuba.Dialogs.ListEdit : Adw.PreferencesDialog {
on_radio_toggled ();
}

private class MemberCheckButton : Gtk.CheckButton {
public signal void changed (string member_id, bool active);

string member_id { get; set; }
public MemberCheckButton (string member_id) {
this.member_id = member_id;
this.css_classes = { "selection-mode", "error" };
this.tooltip_text = _("Remove");

this.toggled.connect (on_toggled);
}

private void on_toggled () {
changed (member_id, this.active);
}
}

private void update_members () {
new Request.GET (@"/api/v1/lists/$(list.id)/accounts")
.with_account (accounts.active)
Expand All @@ -114,29 +131,19 @@ public class Tuba.Dialogs.ListEdit : Adw.PreferencesDialog {
size = 32
};

var m_switch = new Gtk.Switch () {
active = true,
state = true,
var remove_button = new MemberCheckButton (member.id) {
active = false,
valign = Gtk.Align.CENTER,
halign = Gtk.Align.CENTER
halign = Gtk.Align.CENTER,
};

m_switch.state_set.connect ((state) => {
if (!state) {
memebers_to_be_removed.add (member.id);
} else if (memebers_to_be_removed.contains (member.id)) {
memebers_to_be_removed.remove (member.id);
}

return state;
});
remove_button.changed.connect (on_member_remove_changed);

var member_row = new Adw.ActionRow () {
title = member.full_handle
};

member_row.add_prefix (avi);
member_row.add_suffix (m_switch);
member_row.add_suffix (remove_button);

members_group.add (member_row);
});
Expand All @@ -145,6 +152,14 @@ public class Tuba.Dialogs.ListEdit : Adw.PreferencesDialog {
.exec ();
}

private void on_member_remove_changed (string member_id, bool active) {
if (active) {
memebers_to_be_removed.add (member_id);
} else if (memebers_to_be_removed.contains (member_id)) {
memebers_to_be_removed.remove (member_id);
}
}

[GtkCallback]
private void on_close () {
on_apply ();
Expand Down

0 comments on commit c41700a

Please sign in to comment.