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

Convert beatmap discussions main component to typescript #10409

Merged
merged 140 commits into from
Jan 26, 2024

Conversation

notbakaneko
Copy link
Collaborator

@notbakaneko notbakaneko commented Jul 25, 2023

Includes refactoring the discussion state handling out of the top-level component into a separate object

Draft while I double check stuff since it's pretty large from moving all the state handling out of the component.

@notbakaneko notbakaneko self-assigned this Jul 25, 2023
@notbakaneko notbakaneko force-pushed the feature/ts-discussions-main branch 3 times, most recently from f83df57 to f222821 Compare July 26, 2023 10:19
@notbakaneko notbakaneko marked this pull request as ready for review July 31, 2023 09:09
Comment on lines 49 to 51
function isBeatmapsetDiscussionJsonForShow(value: Props['discussion']): value is BeatmapsetDiscussionJsonForShow {
return 'posts' in value;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

inlining 'posts' in discussion also works? 🤔 doesn't need manual type predicates

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The parts that use it are more "render if component is on the page that uses this type (so just main discussions page)" rather than "render if this property is available", it's just coincidental that posts is currently enough to discriminate the type.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought it's handled by the readonly props?

}

toJson() {
return {
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 have a note about non-trivial values needing matching reviver especially since there won't be any typing involved

? this.props.currentDiscussions.countsByBeatmap[beatmap.id]
: undefined;
// TODO: does it need to be computed?
private readonly getCount = (beatmap: BeatmapExtendedJson) => beatmap.deleted_at == null ? this.discussionsState.discussionsByBeatmap(beatmap.id).length : undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

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

the one here should be unresolved count, not total

entries={gameModes.map((mode) => ({
count: this.props.currentDiscussions.countsByPlaymode[mode],
disabled: (this.props.beatmaps.get(mode)?.length ?? 0) === 0,
count: this.discussionsState.discussionsCountByPlaymode[mode],
Copy link
Collaborator

Choose a reason for hiding this comment

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

also unresolved count only

Comment on lines 81 to 86
document.documentElement.style.removeProperty('--scroll-padding-top-extra');

window.clearTimeout(this.timeoutCheckNew);
this.xhrCheckNew?.abort();
this.disposers.forEach((disposer) => disposer?.());
this.discussionsState.destroy();
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 these should also be run on turbolinks:before-cache. the destroy() notably involves removing url handler which means if the state somehow changes between new page load and unmount, the url will be wrong

@nanaya nanaya merged commit e7cc303 into ppy:master Jan 26, 2024
3 checks passed
@notbakaneko notbakaneko deleted the feature/ts-discussions-main branch January 31, 2024 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants