commit
1ca745d607
|
@ -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>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -27,6 +27,7 @@ export const PLAYER = gql`
|
|||
joinedAt
|
||||
servers
|
||||
deletedAt
|
||||
lastActivityAt
|
||||
nameChanges {
|
||||
oldName
|
||||
newName
|
||||
|
|
|
@ -28,6 +28,7 @@ export type Player = {
|
|||
bestRankAt: Date | string;
|
||||
joinedAt: Date | string;
|
||||
deletedAt?: Date | string;
|
||||
lastActivityAt: Date | string;
|
||||
servers: string[];
|
||||
nameChanges: NameChange[];
|
||||
tribe?: {
|
||||
|
|
|
@ -25,7 +25,7 @@ function Provider({ children }: Props) {
|
|||
ServerList,
|
||||
ServersQueryVariables
|
||||
>(SERVERS, {
|
||||
fetchPolicy: 'cache-first',
|
||||
fetchPolicy: 'cache-and-network',
|
||||
variables: {
|
||||
limit: 1,
|
||||
filter: {
|
||||
|
|
|
@ -24,6 +24,7 @@ const translations = {
|
|||
mostPoints: 'Most points',
|
||||
mostVillages: 'Most villages',
|
||||
servers: 'Servers',
|
||||
lastActivityAt: 'Last activity',
|
||||
},
|
||||
nameChanges: {
|
||||
title: 'Name changes',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
Reference in New Issue
Block a user