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

Refactor username input lookup component #11451

Merged
merged 22 commits into from
Aug 30, 2024

Conversation

notbakaneko
Copy link
Collaborator

To be used by #11377

Combined the checkUsernameExists into the new lookup as well.

@notbakaneko
Copy link
Collaborator Author

I wonder if having a ref to the component and just getting the value out directly would be better than passing the updated value through a callback 🤔

@observer
export default class CreateAnnouncement extends React.Component<Props> {
private usernameInputInitialProps: typeof this.model.propsForUsernameInput = {
// dummy value so the field isn't nullablel runInAction in contructor doesn't count as initialized.
Copy link
Collaborator

Choose a reason for hiding this comment

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

"nullablel" 🤔 (the sentence also ends up unreadable)

additionally, this works:

this.stuff = runInAction(() => {
  ...
  return valueForStuff;
});

this.xhr.userLookup.done((user) => runInAction(() => {
if (user.id > 0) {
this.props.userByName.set(currentCheckingUser, user);
this.xhr.userLookup = apiLookup([currentCheckingUser]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

the function name is a bit too generic...

type: 'POST',
url: route('users.check-username-exists'),
});
this.xhr = apiLookup([username]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

the gift link generated in user menu should be @ prefixed as it was previously strictly username lookup

Copy link
Collaborator

Choose a reason for hiding this comment

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

or maybe just prefix it before sending the request

Comment on lines 236 to 239
if (response.users.length > 0) {
this.user = response.users[0];
} else {
this.user = userNotFoundJson;
Copy link
Collaborator

Choose a reason for hiding this comment

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

the response isn't an observable so might as well just response.users[0] ?? userNotFoundJson?

@@ -26,11 +31,12 @@ public function index()
if (ctype_digit($id)) {
$numericIds[] = $id;
} elseif (present($id)) {
$stringIds[] = $id;
$stringIds[] = $id[0] ? substr($id, 1) : $id;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you forgot a === '@'

there's also UsernamesForDbLookup::make (but it also ignores _/ difference)

}
}

private validUsersContains(userIdOrUsername?: string | null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

...shouldn't this be Contain instead? 🤔

@nanaya nanaya merged commit a380f26 into ppy:master Aug 30, 2024
3 checks passed
@notbakaneko notbakaneko deleted the feature/refactor-username-input-lookup branch September 17, 2024 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants