-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10409 from notbakaneko/feature/ts-discussions-main
Convert beatmap discussions main component to typescript
- Loading branch information
Showing
60 changed files
with
1,897 additions
and
1,620 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,49 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
import { BeatmapsContext } from 'beatmap-discussions/beatmaps-context'; | ||
import { BeatmapsetsContext } from 'beatmap-discussions/beatmapsets-context'; | ||
import { Discussion } from 'beatmap-discussions/discussion'; | ||
import { DiscussionsContext } from 'beatmap-discussions/discussions-context'; | ||
import BeatmapsetCover from 'components/beatmapset-cover'; | ||
import BeatmapsetDiscussionsBundleJson from 'interfaces/beatmapset-discussions-bundle-json'; | ||
import { keyBy } from 'lodash'; | ||
import { computed, makeObservable } from 'mobx'; | ||
import { observer } from 'mobx-react'; | ||
import { deletedUserJson } from 'models/user'; | ||
import * as React from 'react'; | ||
import BeatmapsetDiscussionsBundleStore from 'stores/beatmapset-discussions-bundle-store'; | ||
import { makeUrl } from 'utils/beatmapset-discussion-helper'; | ||
import { trans } from 'utils/lang'; | ||
|
||
interface Props { | ||
bundle: BeatmapsetDiscussionsBundleJson; | ||
} | ||
|
||
@observer | ||
export default class Main extends React.Component<Props> { | ||
@computed | ||
private get beatmaps() { | ||
return keyBy(this.props.bundle.beatmaps, 'id'); | ||
} | ||
|
||
@computed | ||
private get beatmapsets() { | ||
return keyBy(this.props.bundle.beatmapsets, 'id'); | ||
} | ||
|
||
@computed | ||
private get discussions() { | ||
return keyBy(this.props.bundle.included_discussions, 'id'); | ||
} | ||
|
||
@computed | ||
private get users() { | ||
const values = keyBy(this.props.bundle.users, 'id'); | ||
// eslint-disable-next-line id-blacklist | ||
values.null = values.undefined = deletedUserJson; | ||
|
||
return values; | ||
} | ||
|
||
constructor(props: Props) { | ||
super(props); | ||
|
||
makeObservable(this); | ||
} | ||
export default class Main extends React.Component<BeatmapsetDiscussionsBundleJson> { | ||
private readonly store = new BeatmapsetDiscussionsBundleStore(this.props); | ||
|
||
render() { | ||
return ( | ||
<DiscussionsContext.Provider value={this.discussions}> | ||
<BeatmapsetsContext.Provider value={this.beatmapsets}> | ||
<BeatmapsContext.Provider value={this.beatmaps}> | ||
<div className='modding-profile-list modding-profile-list--index'> | ||
{this.props.bundle.discussions.length === 0 ? ( | ||
<div className='modding-profile-list__empty'> | ||
{trans('beatmap_discussions.index.none_found')} | ||
</div> | ||
) : (this.props.bundle.discussions.map((discussion) => { | ||
// TODO: handle in child component? Refactored state might not have beatmapset here (and uses Map) | ||
const beatmapset = this.beatmapsets[discussion.beatmapset_id]; | ||
|
||
return beatmapset != null && ( | ||
<div key={discussion.id} className='modding-profile-list__row'> | ||
<a | ||
className='modding-profile-list__thumbnail' | ||
href={makeUrl({ discussion })} | ||
> | ||
<BeatmapsetCover | ||
beatmapset={beatmapset} | ||
size='list' | ||
/> | ||
</a> | ||
<Discussion | ||
beatmapset={beatmapset} | ||
currentBeatmap={discussion.beatmap_id != null ? this.beatmaps[discussion.beatmap_id] : null} | ||
discussion={discussion} | ||
isTimelineVisible={false} | ||
preview | ||
readonly | ||
showDeleted | ||
users={this.users} | ||
/> | ||
</div> | ||
); | ||
}))} | ||
<div className='modding-profile-list modding-profile-list--index'> | ||
{this.props.discussions.length === 0 ? ( | ||
<div className='modding-profile-list__empty'> | ||
{trans('beatmap_discussions.index.none_found')} | ||
</div> | ||
) : (this.props.discussions.map((discussion) => { | ||
// TODO: handle in child component? Refactored state might not have beatmapset here (and uses Map) | ||
const beatmapset = this.store.beatmapsets.get(discussion.beatmapset_id); | ||
|
||
return beatmapset != null && ( | ||
<div key={discussion.id} className='modding-profile-list__row'> | ||
<a | ||
className='modding-profile-list__thumbnail' | ||
href={makeUrl({ discussion })} | ||
> | ||
<BeatmapsetCover | ||
beatmapset={beatmapset} | ||
size='list' | ||
/> | ||
</a> | ||
<Discussion | ||
discussion={discussion} | ||
discussionsState={null} | ||
isTimelineVisible={false} | ||
store={this.store} | ||
/> | ||
</div> | ||
</BeatmapsContext.Provider> | ||
</BeatmapsetsContext.Provider> | ||
</DiscussionsContext.Provider> | ||
); | ||
}))} | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.