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

Use mobx for follow user button #11216

Merged
merged 12 commits into from
May 17, 2024

Conversation

notbakaneko
Copy link
Collaborator

Also fix the being read outside a reactive context warning on user card tooltips

fixes not reading from reactive context when trigger via usercard tooltip.
The other option is to do the setup in runInAction
super(props);
makeObservable(this);

this._following = this.props.following;
Copy link
Collaborator

@nanaya nanaya May 16, 2024

Choose a reason for hiding this comment

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

as this is the only place using this props, might as well remove the default value and make it optional?

looking again, none of the ones using it passes the value so just always init to true? Or put the actual state on page so it can be restored on navigation

following: core.currentUserModel.following.has(this.props.follow.notifiable_id),
});
}
this.xhr?.abort();
Copy link
Collaborator

Choose a reason for hiding this comment

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

return instead?

};
private get following() {
return this.props.follow.subtype === 'mapping'
? core.currentUserModel.following.has(this.props.follow.notifiable_id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

the field name should be something like followUserMapping instead of following...


private readonly eventId = `follow-toggle-${nextVal()}`;
private toggleXhr: null | JQueryXHR = null;
@observable _following: boolean;
Copy link
Collaborator

Choose a reason for hiding this comment

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

private

}

componentDidMount() {
if (this.props.follow.subtype === 'mapping') {
$.subscribe(`user:followUserMapping:refresh.${this.eventId}`, this.refresh);
Copy link
Collaborator

Choose a reason for hiding this comment

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

there doesn't seem to be anything using this event anymore so the publish can be removed

@observer
export default class FollowToggle extends React.PureComponent<Props> {
@observable private _following = true;
private readonly jsonId = `json-follow-toggle-${this.props.follow.subtype}-${this.props.follow.notifiable_type}-${this.props.follow.notifiable_id}`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should be a getter? doesn't matter now but it'll probably break if the component is ever shuffled around and get passed a different set of props

@nanaya nanaya changed the title Use mobx for follow user mapping button Use mobx for follow user button May 17, 2024
@nanaya nanaya enabled auto-merge May 17, 2024 13:09
@nanaya nanaya merged commit 596022b into ppy:master May 17, 2024
3 checks passed
@notbakaneko notbakaneko deleted the feature/mobx-follow-user-mapping-button branch June 4, 2024 05:39
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.

None yet

2 participants