From ea76b0561099b6bc1f2b8c8bc10895d4dde7fea2 Mon Sep 17 00:00:00 2001 From: Mateusz Tylka Date: Tue, 11 Apr 2023 11:35:30 +0200 Subject: [PATCH] MyEntries and Leaderboard Table on mobile hard code synchro --- .../Leaderboard/Leaderboard.js | 1 + .../specific_challenge/MyEntries/MyEntries.js | 5 +- src/components/specific_challenge/Table.js | 123 ++++-------------- 3 files changed, 33 insertions(+), 96 deletions(-) diff --git a/src/components/specific_challenge/Leaderboard/Leaderboard.js b/src/components/specific_challenge/Leaderboard/Leaderboard.js index 3e21f77..3309153 100644 --- a/src/components/specific_challenge/Leaderboard/Leaderboard.js +++ b/src/components/specific_challenge/Leaderboard/Leaderboard.js @@ -180,6 +180,7 @@ const Leaderboard = (props) => { { const getMyEntriesHeader = () => { let header = ['#']; + if (IS_MOBILE()) header.push('when'); for (let myEval of getPossibleMetrics()) { header.push(myEval); } - header.push('when'); + if (!IS_MOBILE()) header.push('when'); return header; }; @@ -136,6 +138,7 @@ const MyEntries = (props) => { challengeName={props.challengeName} headerElements={getMyEntriesHeader()} possibleMetrics={getPossibleMetrics()} + tableType="myEntries" gridTemplateColumns={ '1fr ' + '4fr '.repeat(getMyEntriesHeader().length - 1) } diff --git a/src/components/specific_challenge/Table.js b/src/components/specific_challenge/Table.js index 1690229..718a1c9 100644 --- a/src/components/specific_challenge/Table.js +++ b/src/components/specific_challenge/Table.js @@ -2,7 +2,7 @@ import React from 'react'; import { Container, FlexColumn, FlexRow, Grid } from '../../utils/containers'; import Media from 'react-media'; import theme from '../../utils/theme'; -import { ELEMENTS_PER_PAGE } from '../../utils/globals'; +import { ELEMENTS_PER_PAGE, IS_MOBILE } from '../../utils/globals'; import { Body, Medium } from '../../utils/fonts'; import styled from 'styled-components'; import ColumnFilterIcon from './ColumnFilterIcon'; @@ -58,66 +58,16 @@ const MobileTableStyle = styled(Container)` border-bottom: 1px solid ${({ theme }) => theme.colors.dark01}; position: relative; padding-left: 50%; - - &:before { - font-weight: 400; - position: absolute; - top: 6px; - left: 6px; - width: 45%; - padding-right: 10px; - white-space: nowrap; - } } - td:nth-of-type(1):before { - content: ${({ headerElements }) => - headerElements[0] ? `'${headerElements[0]}'` : ''}; - } - - td:nth-of-type(2):before { - content: ${({ headerElements }) => - headerElements[1] ? `'${headerElements[1]}'` : ''}; - } - - td:nth-of-type(3):before { - content: ${({ headerElements }) => - headerElements[2] ? `'${headerElements[2]}'` : ''}; - } - - td:nth-of-type(4):before { - content: ${({ headerElements }) => - headerElements[3] ? `'${headerElements[3]}'` : ''}; - } - - td:nth-of-type(5):before { - content: ${({ headerElements }) => - headerElements[4] ? `'${headerElements[4]}'` : ''}; - } - - td:nth-of-type(6):before { - content: ${({ headerElements }) => - headerElements[5] ? `'${headerElements[5]}'` : ''}; - } - - td:nth-of-type(7):before { - content: ${({ headerElements }) => - headerElements[6] ? `'${headerElements[6]}'` : ''}; - } - - td:nth-of-type(8):before { - content: ${({ headerElements }) => - headerElements[7] ? `'${headerElements[7]}'` : ''}; - } - - td:nth-of-type(9):before { - content: ${({ headerElements }) => - headerElements[8] ? `'${headerElements[8]}'` : ''}; - } - - td:nth-of-type(10):before { - content: ${({ headerElements }) => - headerElements[9] ? `'${headerElements[9]}'` : ''}; + .mobile-table-header { + font-weight: 400; + position: absolute; + top: 6px; + left: 6px; + width: 45%; + padding-right: 10px; + white-space: nowrap; } `; @@ -144,6 +94,8 @@ const Table = (props) => { } elem = newElem; } + let indexModificator = 2; + if (props.tableType === 'Leaderboard') indexModificator = 4; return elem.map((iterableElem, i) => { return ( { textAlign={props.iterableColumnElement.align} minWidth="72px" > + {IS_MOBILE() && ( + + {props.headerElements[indexModificator + i]} + + )} {props.iterableColumnElement.format ? props.iterableColumnElement.format(iterableElem) : iterableElem} @@ -162,34 +119,25 @@ const Table = (props) => { }; const rowRender = (elem) => { - if (elem.submitter === props.user) { - return props.staticColumnElements.map((elemName, i) => { - return ( - - {elemName.format - ? elemName.format(elem[elemName.name]) - : elem[elemName.name]} - - ); - }); - } + let RowStyle = Body; + if (elem.submitter === props.user) RowStyle = Medium; return props.staticColumnElements.map((elemName, i) => { return ( - + {IS_MOBILE() && ( + + {props.headerElements[i]} + + )} {elemName.format ? elemName.format(elem[elemName.name]) : elem[elemName.name]} - + ); }); }; @@ -239,15 +187,13 @@ const Table = (props) => { > {elem.replace('.', ' ')} - {elem !== '#' ? ( + {elem !== '#' && ( - ) : ( - '' )} ); @@ -276,9 +222,8 @@ const Table = (props) => { ); - } else { - return No results ;c; } + return No results ;c; }; const mobileRender = () => { @@ -291,17 +236,6 @@ const Table = (props) => { staticColumnElements={props.staticColumnElements} headerElements={props.headerElements} > - - - {props.headerElements.map((elem, i) => { - return ( - - {elem} - - ); - })} - - {elementsToMap.map((elem, index) => { return ( @@ -314,9 +248,8 @@ const Table = (props) => { ); - } else { - return No results ;c; } + return No results ;c; }; return (