Make the order of popular instances semi-randomized (#187)

* Make the order of popular instances semi-randomized

* Fix missing semicolons
This commit is contained in:
Jason Watkins 2023-06-20 06:25:20 -07:00 committed by GitHub
parent 256e9119cb
commit 663e7bf49a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 1 deletions

View File

@ -11,6 +11,14 @@ export class Instances extends Component<any, any> {
super(props, context); super(props, context);
} }
calculateInstanceSortValue(instance: any) {
// Mostly sort by active users, but add a large random component to
// randomize order of instances with about the same order of magnitude of
// users.
let active_users = instance.site_info.site_view.counts.users_active_month;
return active_users + active_users * 3 * Math.random();
}
render() { render() {
const title = i18n.t("join_title"); const title = i18n.t("join_title");
@ -35,6 +43,11 @@ export class Instances extends Component<any, any> {
.sort((a, b) => a.sort - b.sort) .sort((a, b) => a.sort - b.sort)
.map(({ value }) => value); .map(({ value }) => value);
let remaining2 = remaining
.map(i => ({ instance: i, sort: this.calculateInstanceSortValue(i) }))
.sort((a, b) => b.sort - a.sort)
.map(({ instance }) => instance);
return ( return (
<div class="container"> <div class="container">
<Helmet title={title}> <Helmet title={title}>
@ -45,7 +58,7 @@ export class Instances extends Component<any, any> {
<br /> <br />
<br /> <br />
{this.renderList(i18n.t("recommended_instances"), recommended2)} {this.renderList(i18n.t("recommended_instances"), recommended2)}
{this.renderList(i18n.t("popular_instances"), remaining)} {this.renderList(i18n.t("popular_instances"), remaining2)}
</div> </div>
); );
} }