[WarStatsPage] show the number of villages that each side has

This commit is contained in:
Dawid Wysokiński 2021-01-06 12:00:47 +01:00
parent 0f1e18b51d
commit 7f1f66b9e0
4 changed files with 25 additions and 0 deletions

View File

@ -80,6 +80,15 @@ function WarStatsPage() {
players: Player[] = [], players: Player[] = [],
tribes: Tribe[] = [] tribes: Tribe[] = []
): SideResult => { ): SideResult => {
let totalVillages = 0;
tribes.forEach(t => {
totalVillages += t.totalVillages;
});
players
.filter(p => !p.tribe || !tribes.some(t => t.id === p.tribe?.id))
.forEach(p => {
totalVillages += p.totalVillages;
});
return { return {
gained: totalGained, gained: totalGained,
lost: totalLost, lost: totalLost,
@ -87,6 +96,7 @@ function WarStatsPage() {
difference: totalGained - totalLost, difference: totalGained - totalLost,
players, players,
tribes, tribes,
totalVillages,
}; };
}; };

View File

@ -52,6 +52,10 @@ function OneSideResult({ data, t, server, title }: Props) {
))} ))}
</Typography> </Typography>
)} )}
<Typography>
{t('results.villages')}:{' '}
<strong>{formatNumber('commas', data.totalVillages)}</strong>
</Typography>
<Typography> <Typography>
{t('results.gained')}:{' '} {t('results.gained')}:{' '}
<strong>{formatNumber('commas', data.gained)}</strong> <strong>{formatNumber('commas', data.gained)}</strong>

View File

@ -18,6 +18,10 @@ export const PLAYERS = gql`
items { items {
id id
name name
totalVillages
tribe {
id
}
} }
} }
} }
@ -41,6 +45,7 @@ export const TRIBES = gql`
items { items {
id id
tag tag
totalVillages
} }
} }
} }

View File

@ -3,6 +3,7 @@ import { List, EnnoblementFilter } from '@libs/graphql/types';
export type Tribe = { export type Tribe = {
id: number; id: number;
tag: string; tag: string;
totalVillages: number;
}; };
export type TribeList = { export type TribeList = {
@ -12,6 +13,10 @@ export type TribeList = {
export type Player = { export type Player = {
id: number; id: number;
name: string; name: string;
totalVillages: number;
tribe?: {
id: number;
};
}; };
export type PlayerList = { export type PlayerList = {
@ -68,6 +73,7 @@ export type SideResult = {
againstOppositeSide: number; againstOppositeSide: number;
players: Player[]; players: Player[];
tribes: Tribe[]; tribes: Tribe[];
totalVillages: number;
}; };
export type Results = { export type Results = {