Merge pull request #5 from tribalwarshelp/develop

merge develop branch
This commit is contained in:
Dawid Wysokiński 2021-02-10 21:50:54 +01:00 committed by GitHub
commit 1ca745d607
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 36 additions and 12 deletions

View File

@ -1,4 +1,4 @@
import React from 'react'; import React, { useState, useEffect } from 'react';
import useDateUtils from 'libs/date/useDateUtils'; import useDateUtils from 'libs/date/useDateUtils';
import useServer from 'features/ServerPage/libs/ServerContext/useServer'; import useServer from 'features/ServerPage/libs/ServerContext/useServer';
import useStyles from './useStyles'; import useStyles from './useStyles';
@ -20,9 +20,27 @@ const ServerInfo = ({ t }: Props) => {
numberOfVillages, numberOfVillages,
} = useServer(); } = useServer();
const dateUtils = useDateUtils(); const dateUtils = useDateUtils();
const classes = useStyles(); const classes = useStyles();
const getDataUpdatedAtText = () => {
return t('pageLayout.sidebar.serverInfo.dataUpdatedAt', {
date: dateUtils.formatDistanceToNow(new Date(dataUpdatedAt), {
addSuffix: true,
}),
});
};
const [dataUpdatedAtText, setDataUpdatedAtText] = useState<string>(
getDataUpdatedAtText()
);
useEffect(() => {
const intervalID = setInterval(() => {
setDataUpdatedAtText(getDataUpdatedAtText());
}, 30000);
return () => {
clearInterval(intervalID);
}; // eslint-disable-next-line
}, [dataUpdatedAt, t, dateUtils]);
return ( return (
<div className={classes.root}> <div className={classes.root}>
<Typography> <Typography>
@ -43,13 +61,7 @@ const ServerInfo = ({ t }: Props) => {
count: numberOfVillages, count: numberOfVillages,
})} })}
</Typography> </Typography>
<Typography> <Typography>{dataUpdatedAtText}</Typography>
{t('pageLayout.sidebar.serverInfo.dataUpdatedAt', {
date: dateUtils.formatDistanceToNow(new Date(dataUpdatedAt), {
addSuffix: true,
}),
})}
</Typography>
</div> </div>
); );
}; };

View File

@ -82,13 +82,18 @@ function IndexPage() {
})`, })`,
}, },
{ {
field: 'deletedAt', field: player.deletedAt ? 'deletedAt' : 'lastActivityAt',
value: player.deletedAt value: player.deletedAt
? dateUtils.format( ? dateUtils.format(
dateUtils.date(player.deletedAt), dateUtils.date(player.deletedAt),
DATE_FORMAT.DAY_MONTH_AND_YEAR DATE_FORMAT.DAY_MONTH_AND_YEAR
) )
: '-', : dateUtils.formatDistanceToNow(
new Date(player.lastActivityAt ?? 0),
{
addSuffix: true,
}
),
}, },
{ {
field: 'bestRank', field: 'bestRank',

View File

@ -21,6 +21,7 @@ const ctx = createContext<Player>({
mostPointsAt: new Date(0), mostPointsAt: new Date(0),
mostVillages: 0, mostVillages: 0,
mostVillagesAt: new Date(0), mostVillagesAt: new Date(0),
lastActivityAt: new Date(0),
bestRank: 0, bestRank: 0,
bestRankAt: new Date(0), bestRankAt: new Date(0),
joinedAt: new Date(0), joinedAt: new Date(0),

View File

@ -27,6 +27,7 @@ export const PLAYER = gql`
joinedAt joinedAt
servers servers
deletedAt deletedAt
lastActivityAt
nameChanges { nameChanges {
oldName oldName
newName newName

View File

@ -28,6 +28,7 @@ export type Player = {
bestRankAt: Date | string; bestRankAt: Date | string;
joinedAt: Date | string; joinedAt: Date | string;
deletedAt?: Date | string; deletedAt?: Date | string;
lastActivityAt: Date | string;
servers: string[]; servers: string[];
nameChanges: NameChange[]; nameChanges: NameChange[];
tribe?: { tribe?: {

View File

@ -25,7 +25,7 @@ function Provider({ children }: Props) {
ServerList, ServerList,
ServersQueryVariables ServersQueryVariables
>(SERVERS, { >(SERVERS, {
fetchPolicy: 'cache-first', fetchPolicy: 'cache-and-network',
variables: { variables: {
limit: 1, limit: 1,
filter: { filter: {

View File

@ -24,6 +24,7 @@ const translations = {
mostPoints: 'Most points', mostPoints: 'Most points',
mostVillages: 'Most villages', mostVillages: 'Most villages',
servers: 'Servers', servers: 'Servers',
lastActivityAt: 'Last activity',
}, },
nameChanges: { nameChanges: {
title: 'Name changes', title: 'Name changes',

View File

@ -24,6 +24,7 @@ const translations = {
mostPoints: 'Najwięcej punktów', mostPoints: 'Najwięcej punktów',
mostVillages: 'Najwięcej wiosek', mostVillages: 'Najwięcej wiosek',
servers: 'Serwery', servers: 'Serwery',
lastActivityAt: 'Ostatnia aktywność',
}, },
nameChanges: { nameChanges: {
title: 'Zmiany nicków', title: 'Zmiany nicków',

View File

@ -24,6 +24,7 @@ const translations = {
mostPoints: 'Maior pontuação', mostPoints: 'Maior pontuação',
mostVillages: 'Maior quantidade de aldeias', mostVillages: 'Maior quantidade de aldeias',
servers: 'Servidores', servers: 'Servidores',
lastActivityAt: 'Last activity',
}, },
nameChanges: { nameChanges: {
title: 'Mudanças de nome', title: 'Mudanças de nome',

View File

@ -24,6 +24,7 @@ const translations = {
mostPoints: 'Maior pontuação', mostPoints: 'Maior pontuação',
mostVillages: 'Maior quantidade de aldeias', mostVillages: 'Maior quantidade de aldeias',
servers: 'Servidores', servers: 'Servidores',
lastActivityAt: 'Last activity',
}, },
nameChanges: { nameChanges: {
title: 'Mudanças de nome', title: 'Mudanças de nome',