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 useServer from 'features/ServerPage/libs/ServerContext/useServer';
import useStyles from './useStyles';
@ -20,9 +20,27 @@ const ServerInfo = ({ t }: Props) => {
numberOfVillages,
} = useServer();
const dateUtils = useDateUtils();
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 (
<div className={classes.root}>
<Typography>
@ -43,13 +61,7 @@ const ServerInfo = ({ t }: Props) => {
count: numberOfVillages,
})}
</Typography>
<Typography>
{t('pageLayout.sidebar.serverInfo.dataUpdatedAt', {
date: dateUtils.formatDistanceToNow(new Date(dataUpdatedAt), {
addSuffix: true,
}),
})}
</Typography>
<Typography>{dataUpdatedAtText}</Typography>
</div>
);
};

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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