import PropTypes from 'prop-types';
import React from 'react';
import { ListGroup } from 'react-bootstrap';
-import { withTranslation } from 'react-i18next';
+import { Trans, withTranslation } from 'react-i18next';
import Icon from '../common/Icon';
+import Spoiler from '../common/Spoiler';
+import { formatTime } from '../../helpers/Result';
+import { getUserName } from '../../helpers/User';
import i18n from '../../i18n';
const getEntryDate = entry => {
: dateStr;
};
+const getEntryDetailsUsername = entry => {
+ if (!entry || !entry.details || !entry.details.user) return 'Anonymous';
+ return getUserName(entry.details.user);
+};
+
+const getEntryRoundNumber = entry =>
+ (entry && entry.details && entry.details.round && entry.details.round.number) || '?';
+
+const getEntryResultComment = entry => {
+ if (!entry || !entry.details || !entry.details.result || !entry.details.result.comment) {
+ return '';
+ }
+ return entry.details.result.comment;
+};
+
+const getEntryResultTime = entry => {
+ if (!entry || !entry.details || !entry.details.result) return 'ERROR';
+ const result = entry.details.result;
+ if (result.forfeit) return 'DNF XX';
+ return formatTime(result);
+};
+
const getEntryDescription = entry => {
switch (entry.type) {
+ case 'application.accepted':
+ case 'application.received':
+ case 'application.rejected':
+ return i18n.t(
+ `protocol.description.${entry.type}`,
+ {
+ ...entry,
+ username: getEntryDetailsUsername(entry),
+ },
+ );
+ case 'result.comment': {
+ const comment = getEntryResultComment(entry);
+ const number = getEntryRoundNumber(entry);
+ return <Trans i18nKey={`protocol.description.${entry.type}`}>
+ {{number}}
+ <Spoiler>{{comment}}</Spoiler>,
+ </Trans>;
+ }
+ case 'result.report': {
+ const number = getEntryRoundNumber(entry);
+ const time = getEntryResultTime(entry);
+ return <Trans i18nKey={`protocol.description.${entry.type}`}>
+ {{number}}
+ <Spoiler>{{time}}</Spoiler>,
+ </Trans>;
+ }
case 'round.create':
+ case 'round.edit':
+ case 'round.lock':
+ case 'round.seed':
+ case 'round.unlock':
+ return i18n.t(
+ `protocol.description.${entry.type}`,
+ {
+ ...entry,
+ number: getEntryRoundNumber(entry),
+ },
+ );
+ case 'tournament.close':
+ case 'tournament.discord':
+ case 'tournament.lock':
+ case 'tournament.open':
+ case 'tournament.settings':
+ case 'tournament.unlock':
return i18n.t(
`protocol.description.${entry.type}`,
entry,
const getEntryIcon = entry => {
switch (entry.type) {
+ case 'result.report':
+ return <Icon.RESULT />;
+ case 'round.create':
+ return <Icon.ADD />;
+ case 'round.lock':
+ case 'tournament.close':
+ case 'tournament.lock':
+ return <Icon.LOCKED />;
+ case 'round.unlock':
+ case 'tournament.open':
+ case 'tournament.unlock':
+ return <Icon.UNLOCKED />;
+ case 'tournament.discord':
+ return <Icon.DISCORD />;
default:
return <Icon.PROTOCOL />;
}