X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fhelpers%2FResult.js;h=205a42b27325050800c4fe55f728f43de1d0c8c0;hb=0a4af7267374d1a750ed07e9c4b491fea42490af;hp=06ade091803e4a649a14914247e761ac01ad9619;hpb=812a270c7a410461e931394496512d36b34ef7b5;p=alttp.git
diff --git a/resources/js/helpers/Result.js b/resources/js/helpers/Result.js
index 06ade09..205a42b 100644
--- a/resources/js/helpers/Result.js
+++ b/resources/js/helpers/Result.js
@@ -1,3 +1,6 @@
+import React from 'react';
+import Icon from '../components/common/Icon';
+
export const formatTime = result => {
const hours = `${Math.floor(result.time / 60 / 60)}`;
let minutes = `${Math.floor((result.time / 60) % 60)}`;
@@ -11,6 +14,38 @@ export const formatTime = result => {
return `${hours}:${minutes}:${seconds}`;
};
+export const getIcon = (result, maySee) => {
+ if (!result || !result.has_finished) {
+ return ;
+ }
+ if (result.forfeit && maySee) {
+ return ;
+ }
+ if (result.placement === 1 && maySee) {
+ return ;
+ }
+ if (result.placement === 2 && maySee) {
+ return ;
+ }
+ if (result.placement === 3 && maySee) {
+ return ;
+ }
+ return ;
+};
+
+export const getTime = (result, maySee) => {
+ if (!result || !maySee) {
+ return null;
+ }
+ if (result.time) {
+ return formatTime(result);
+ }
+ if (result.forfeit) {
+ return 'DNF';
+ }
+ return '?';
+};
+
export const parseTime = str => {
if (!str) return null;
return `${str}`.split(/[-.: ]+/).reduce((acc,time) => (60 * acc) + +time, 0);
@@ -18,5 +53,7 @@ export const parseTime = str => {
export default {
formatTime,
+ getIcon,
+ getTime,
parseTime,
};