mirror of
https://github.com/LemmyNet/joinlemmy-site.git
synced 2024-11-24 21:31:16 +00:00
parent
15bd9d2844
commit
97c3e4aae6
3 changed files with 12 additions and 8 deletions
|
@ -13,6 +13,7 @@ import {
|
|||
} from "./app-definitions";
|
||||
import { Icon } from "./icon";
|
||||
import { I18nKeys } from "i18next";
|
||||
import { sortRandom } from "../utils";
|
||||
|
||||
const TitleBlock = () => (
|
||||
<div className="flex flex-col items-center pt-16 mb-4">
|
||||
|
@ -146,6 +147,9 @@ export class Apps extends Component<any, State> {
|
|||
apps = apps.filter(a => a.platforms.includes(this.state.platform));
|
||||
}
|
||||
|
||||
// Random sort
|
||||
apps = sortRandom(apps);
|
||||
|
||||
this.setState({ apps });
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import { Helmet } from "inferno-helmet";
|
|||
import { i18n, LANGUAGES } from "../i18next";
|
||||
import { T } from "inferno-i18next";
|
||||
import { instance_stats } from "../instance_stats";
|
||||
import { getQueryParams, mdToHtml, numToSI } from "../utils";
|
||||
import { getQueryParams, mdToHtml, numToSI, sortRandom } from "../utils";
|
||||
import { Badge, SELECT_CLASSES, SectionTitle, TEXT_GRADIENT } from "./common";
|
||||
import {
|
||||
INSTANCE_HELPERS,
|
||||
|
@ -351,13 +351,6 @@ const LEAST_ACTIVE_SORT: Sort = {
|
|||
|
||||
const SORTS: Sort[] = [RANDOM_SORT, MOST_ACTIVE_SORT, LEAST_ACTIVE_SORT];
|
||||
|
||||
function sortRandom(instances: any[]): any[] {
|
||||
return instances
|
||||
.map(value => ({ value, sort: Math.random() }))
|
||||
.sort((a, b) => a.sort - b.sort)
|
||||
.map(({ value }) => value);
|
||||
}
|
||||
|
||||
function sortActive(instances: any[]): any[] {
|
||||
return instances.sort(
|
||||
(a, b) =>
|
||||
|
|
|
@ -57,3 +57,10 @@ export function monthsBetween(startDate: Date, endDate: Date) {
|
|||
// Convert back to days and return
|
||||
return Math.round(differenceMs / oneMonth);
|
||||
}
|
||||
|
||||
export function sortRandom<T>(list: T[]): T[] {
|
||||
return list
|
||||
.map(value => ({ value, sort: Math.random() }))
|
||||
.sort((a, b) => a.sort - b.sort)
|
||||
.map(({ value }) => value);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue