mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-04-24 03:00:09 -04:00
[MyMeta] increased player listing to 150 (#541)
* increased player listing to 150 * removed unnecessary extra var
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user