Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user label settings page #1481

Merged
merged 3 commits into from
Jul 10, 2024

Conversation

micahmo
Copy link
Member

@micahmo micahmo commented Jul 8, 2024

Pull Request Description

This PR adds a settings page to manage user labels.

  • All user labels will be listed (regardless of your current instance).
  • A label can be edited by tapping on it, or deleted by tapping the x.
  • New labels can be created. First you pick the user (only users on your current instance will be selectable), then you write the label.
    • If you happen to "create" a label that already exists, any changes you make in the dialog will be reflected in the list.

Issue Being Fixed

Issue Number: N/A

Screenshots / Recordings

qemu-system-x86_64_jxnmwGj9lh.mp4

Checklist

  • If a new package was added, did you ensure it uses an appropriate license and is actively maintained?
  • Did you use localized strings (and added appropriate descriptions) where applicable?
  • Did you add semanticLabels where applicable for accessibility?

Copy link
Member

@hjiangsu hjiangsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just a couple of very minor points

lib/settings/pages/user_labels_settings_page.dart Outdated Show resolved Hide resolved
Comment on lines 37 to 43
if (result.deleted) {
// It exists in our list and was deleted, so remove it.
setState(() => userLabels.removeWhere((userLabel) => userLabel.username == result.userLabel!.username));
} else {
// It exists in our list but was changed, so update it.
setState(() => userLabels[userLabels.indexOf(existingLabel)] = result.userLabel!);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more of a preference thing (so no need to change anything!), but I generally like to return early on these types of boolean conditions to reduce the logic. Of course, this only works if this is the last thing that needs to be performed.

Suggested change
if (result.deleted) {
// It exists in our list and was deleted, so remove it.
setState(() => userLabels.removeWhere((userLabel) => userLabel.username == result.userLabel!.username));
} else {
// It exists in our list but was changed, so update it.
setState(() => userLabels[userLabels.indexOf(existingLabel)] = result.userLabel!);
}
if (result.deleted) {
// It exists in our list and was deleted, so remove it.
setState(() => userLabels.removeWhere((userLabel) => userLabel.username == result.userLabel!.username));
return;
}
// It exists in our list but was changed, so update it.
setState(() => userLabels[userLabels.indexOf(existingLabel)] = result.userLabel!);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense! In this case, since there's only one line of logic in the else, I think the parallelism of having both statements in conditions helps to see what's going on without too much clutter.

@hjiangsu hjiangsu merged commit 3e3f4d5 into thunder-app:develop Jul 10, 2024
1 check passed
@micahmo micahmo deleted the feature/user-label-settings branch July 10, 2024 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants