mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-10-01 07:37:55 -05:00
use custom random element function instead of lodash
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { PlusRegion, Prisma } from "@prisma/client";
|
||||
import { httpError } from "@trpc/server";
|
||||
import prisma from "prisma/client";
|
||||
import { shuffleArray } from "utils/arrays";
|
||||
import { ADMIN_ID } from "utils/constants";
|
||||
import { getPercentageFromCounts, getVotingRange } from "utils/plus";
|
||||
import { userBasicSelection } from "utils/prisma";
|
||||
import { shuffleArray } from "utils/shuffleArray";
|
||||
import { suggestionFullSchema } from "utils/validators/suggestion";
|
||||
import { voteSchema, votesSchema } from "utils/validators/votes";
|
||||
import { vouchSchema } from "utils/validators/vouch";
|
||||
|
||||
1
package-lock.json
generated
1
package-lock.json
generated
@@ -63,7 +63,6 @@
|
||||
"cross-env": "^7.0.3",
|
||||
"cypress": "^6.8.0",
|
||||
"fishery": "^1.2.0",
|
||||
"lodash": "^4.17.21",
|
||||
"prettier": "^2.2.1",
|
||||
"prisma": "^2.20.1",
|
||||
"ts-node": "^9.1.1",
|
||||
|
||||
@@ -79,7 +79,6 @@
|
||||
"cross-env": "^7.0.3",
|
||||
"cypress": "^6.8.0",
|
||||
"fishery": "^1.2.0",
|
||||
"lodash": "^4.17.21",
|
||||
"prettier": "^2.2.1",
|
||||
"prisma": "^2.20.1",
|
||||
"ts-node": "^9.1.1",
|
||||
|
||||
@@ -28,9 +28,9 @@ import HeaderBanner from "components/layout/HeaderBanner";
|
||||
import { useRouter } from "next/router";
|
||||
import { ChangeEvent, Fragment, useEffect, useState } from "react";
|
||||
import { FiCheck, FiFilter, FiRotateCw } from "react-icons/fi";
|
||||
import { shuffleArray } from "utils/arrays";
|
||||
import { stages } from "utils/lists/stages";
|
||||
import { setManySearchParams } from "utils/setSearchParams";
|
||||
import { shuffleArray } from "utils/shuffleArray";
|
||||
|
||||
const MapsGeneratorPage = () => {
|
||||
const router = useRouter();
|
||||
|
||||
@@ -12,8 +12,8 @@ import prisma from "prisma/client";
|
||||
import { getAllLadderRegisteredTeamsForMatches } from "prisma/queries/getAllLadderRegisteredTeamsForMatches";
|
||||
import { getLadderDay, GetLadderDayData } from "prisma/queries/getLadderDay";
|
||||
import { Fragment } from "react";
|
||||
import { shuffleArray } from "utils/arrays";
|
||||
import { getLadderRounds } from "utils/playFunctions";
|
||||
import { shuffleArray } from "utils/shuffleArray";
|
||||
|
||||
interface Props {
|
||||
ladderDay: GetLadderDayData;
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import { PlusStatus } from "@prisma/client";
|
||||
import { Factory } from "fishery";
|
||||
import { PlusStatus, PlusRegion } from "@prisma/client";
|
||||
import { randomElement } from "utils/arrays";
|
||||
import prisma from "../client";
|
||||
import _ from "lodash";
|
||||
|
||||
export default Factory.define<PlusStatus>(({ params, onCreate }) => {
|
||||
onCreate(plusStatus => {
|
||||
onCreate((plusStatus) => {
|
||||
return prisma.plusStatus.create({ data: plusStatus });
|
||||
});
|
||||
|
||||
return {
|
||||
userId: 1, // TODO: automatically build a User object, if necessary
|
||||
membershipTier: 1,
|
||||
region: _.sample(Object.values(PlusRegion))!,
|
||||
region: randomElement(["EU", "NA"]),
|
||||
voucherId: null,
|
||||
vouchTier: null,
|
||||
canVouchFor: null,
|
||||
canVouchAgainAfter: null,
|
||||
nameForVoting: null
|
||||
nameForVoting: null,
|
||||
};
|
||||
});
|
||||
|
||||
16
utils/arrays.ts
Normal file
16
utils/arrays.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export const shuffleArray = <T>(array: T[]) => {
|
||||
return array
|
||||
.map((a) => ({ sort: Math.random(), value: a }))
|
||||
.sort((a, b) => a.sort - b.sort)
|
||||
.map((a) => a.value);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get random element from array.
|
||||
* @link https://stackoverflow.com/a/5915122
|
||||
* @example
|
||||
* randomElement(["dog", "cat", "horse"])
|
||||
*/
|
||||
export const randomElement = <T>(items: [T, ...T[]]) => {
|
||||
return items[Math.floor(Math.random() * items.length)];
|
||||
};
|
||||
@@ -1,6 +0,0 @@
|
||||
export const shuffleArray = <T>(array: T[]) => {
|
||||
return array
|
||||
.map((a) => ({ sort: Math.random(), value: a }))
|
||||
.sort((a, b) => a.sort - b.sort)
|
||||
.map((a) => a.value);
|
||||
};
|
||||
Reference in New Issue
Block a user