[MyMeta] increased player listing to 150 (#541)

* increased player listing to 150

* removed unnecessary extra var
This commit is contained in:
dan13ram
2021-05-12 08:03:54 +05:30
committed by GitHub
parent 8162d8eaeb
commit efe0e8bde3
2 changed files with 29 additions and 6 deletions

View File

@@ -1,21 +1,31 @@
import gql from 'fake-tag';
import { GetPlayersQuery, GetPlayersQueryVariables } from './autogen/types';
import {
GetPlayersQuery,
GetPlayersQueryVariables,
PlayerFragmentFragment,
} from './autogen/types';
import { client } from './client';
import { PlayerFragment } from './fragments';
const playersQuery = gql`
query GetPlayers($limit: Int) {
player(order_by: { total_xp: desc }, limit: $limit) {
query GetPlayers($limit: Int, $offset: Int) {
player(order_by: { total_xp: desc }, limit: $limit, offset: $offset) {
...PlayerFragment
}
}
${PlayerFragment}
`;
export const getPlayers = async (limit = 50) => {
export const getPlayers = async (
limit = 50,
offset = 0,
): Promise<PlayerFragmentFragment[]> => {
const { data, error } = await client
.query<GetPlayersQuery, GetPlayersQueryVariables>(playersQuery, { limit })
.query<GetPlayersQuery, GetPlayersQueryVariables>(playersQuery, {
limit,
offset,
})
.toPromise();
if (!data) {

View File

@@ -1,13 +1,26 @@
import { PageContainer } from 'components/Container';
import { PlayerList } from 'components/PlayerList';
import { PlayerFragmentFragment } from 'graphql/autogen/types';
import { getPlayers } from 'graphql/getPlayers';
import { InferGetStaticPropsType } from 'next';
import React from 'react';
type Props = InferGetStaticPropsType<typeof getStaticProps>;
const LIMIT = 50;
const TOTAL_PLAYERS = 150;
export const getStaticProps = async () => {
const players = await getPlayers();
const promises: Promise<PlayerFragmentFragment[]>[] = new Array(
TOTAL_PLAYERS / LIMIT,
)
.fill(false)
.map((_, i) => getPlayers(LIMIT, i * LIMIT));
const playersArr = await Promise.all(promises);
const players = playersArr.reduce(
(_total, _players) => [..._total, ..._players],
[],
);
return {
props: {
players,