Skip to content

Commit

Permalink
Merge pull request #210 from elmadev/dev
Browse files Browse the repository at this point in the history
Live release 9 Mar 2024
  • Loading branch information
sunehs authored Mar 9, 2024
2 parents 2c360b9 + 6f036b9 commit 2f64c32
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 59 deletions.
3 changes: 3 additions & 0 deletions src/components/CupResults.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const CupResults = props => {
{results.map((r, no) => (
<div>
{r.Position ? r.Position : no + 1}.{' '}
{r.KuskiData.Country
? `:flag_${r.KuskiData.Country.toLowerCase()}: `
: null}
{cup.TeamPoints ? (
<Kuski
kuskiData={{
Expand Down
2 changes: 1 addition & 1 deletion src/components/LeaderHistory.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default function LeaderHistory({
return (
<Container>
<TimeDevelopment>
{[...allFinished]
{[...(allFinished || [])]
.reduce((acc, cur) => {
if (acc.length < 1 || acc[acc.length - 1].Time > cur.Time)
acc.push(cur);
Expand Down
19 changes: 12 additions & 7 deletions src/features/LevelList/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default function LevelList({
const [searchQuery, setSearchQuery] = useState('');
const [page, setPage] = useState(defaultPage);
const [pageSize] = useState(defaultPageSize);
const { loggedIn } = useStoreState(state => state.Login);
const { levels, tagOptions, kuskiOptions, loadingLevels } = useStoreState(
state => state.LevelList,
);
Expand Down Expand Up @@ -104,8 +105,9 @@ export default function LevelList({
'Added',
'Filename',
'Level name',
'By',
'Added by',
'Best time',
'My time',
'Battles',
'Apples',
'Killers',
Expand Down Expand Up @@ -262,11 +264,12 @@ export default function LevelList({
<ListCell width={170}>Added</ListCell>
<ListCell width={150}>Filename</ListCell>
<ListCell>Level name</ListCell>
<ListCell width={100}>By</ListCell>
<ListCell width={100}>Added by</ListCell>
<ListCell width={100}>Best time</ListCell>
{loggedIn && <ListCell width={100}>My time</ListCell>}
<ListCell width={100}>Battles</ListCell>
<ListCell width={100}>Apples</ListCell>
<ListCell width={100}>Kiilers</ListCell>
<ListCell width={100}>Killers</ListCell>

{!summary && (
<>
Expand Down Expand Up @@ -297,7 +300,7 @@ export default function LevelList({
{columns.indexOf('Level name') !== -1 && (
<ListCell>{level.LongName}</ListCell>
)}
{columns.indexOf('By') !== -1 && (
{columns.indexOf('Added by') !== -1 && (
<ListCell width={100}>
{level.KuskiData ? (
<Kuski kuskiData={level.KuskiData} />
Expand All @@ -311,6 +314,11 @@ export default function LevelList({
{level.Besttime ? <Time time={level.Besttime} /> : '-'}
</ListCell>
)}
{loggedIn && columns.indexOf('My time') !== -1 && (
<ListCell width={100}>
{level.Mytime ? <Time time={level.Mytime} /> : '-'}
</ListCell>
)}
{columns.indexOf('Battles') !== -1 && (
<ListCell width={100}>{level.BattleCount || '-'}</ListCell>
)}
Expand All @@ -320,9 +328,6 @@ export default function LevelList({
{columns.indexOf('Killers') !== -1 && (
<ListCell width={100}>{level.Killers}</ListCell>
)}
{columns.indexOf('Unlisted') !== -1 && (
<ListCell>{level.Unlisted === 1 ? 'Yes' : ''}</ListCell>
)}
{columns.indexOf('Tags') !== -1 && (
<ListCell>
<Tags tags={getTags(level)} />
Expand Down
13 changes: 10 additions & 3 deletions src/pages/cup/Events.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Download from 'components/Download';
import EventItem from 'components/EventItem';
import config from 'config';
import { Paper } from 'components/Paper';
import { Level } from 'components/Names';
import { admins } from 'utils/cups';
import { nickId } from 'utils/nick';
import Interviews from './Interviews';
Expand Down Expand Up @@ -68,9 +69,15 @@ const Cups = props => {
)
}
level={
<Download href={`level/${e.LevelIndex}`}>
{e.Level ? e.Level.LevelName : ''}
</Download>
e.Level ? (
<>
<Download href={`level/${e.LevelIndex}`}>
{`${e.Level.LevelName}.lev`}
</Download>
<> - </>
<Level LevelIndex={e.LevelIndex} LevelData={e.Level} />
</>
) : null
}
by={<Kuski kuskiData={e.KuskiData} />}
eventTime={
Expand Down
131 changes: 108 additions & 23 deletions src/pages/cup/Personal.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
/* eslint-disable react/no-danger */
import React, { useEffect, Fragment, useState } from 'react';
import styled from 'styled-components';
import { nickId } from 'utils/nick';
import { forEach } from 'lodash';
import { format } from 'date-fns';
import { Grid, Checkbox } from '@material-ui/core';
import {
Grid,
Checkbox,
RadioGroup,
FormControlLabel,
Radio,
} from '@material-ui/core';
import { Paper } from 'components/Paper';
import Header from 'components/Header';
import LocalTime from 'components/LocalTime';
Expand All @@ -14,6 +19,7 @@ import Recplayer from 'components/Recplayer';
import { getPrivateCupRecUri } from 'utils/cups';
import PreviewRecButton from 'components/PreviewRecButton';
import config from 'config';
import FieldBoolean from 'components/FieldBoolean';

const eventSort = (a, b) => a.CupIndex - b.CupIndex;

Expand All @@ -31,10 +37,15 @@ const currentEventIndex = events => {
};

const Personal = () => {
const { myReplays, cup, events, myTimes } = useStoreState(state => state.Cup);
const { getMyReplays, updateReplay, getMyTimes } = useStoreActions(
actions => actions.Cup,
const { myReplays, cup, events, myTimes, myTimesOptions } = useStoreState(
state => state.Cup,
);
const {
getMyReplays,
updateReplay,
getMyTimes,
setMyTimesOptions,
} = useStoreActions(actions => actions.Cup);

const [previewRecIndex, setPreviewRecIndex] = useState(null);

Expand Down Expand Up @@ -62,6 +73,32 @@ const Personal = () => {
setPreviewRecIndex(newIndex);
};

const timesSort = (a, b) => {
if (myTimesOptions.order === 'byTime') {
return a.Time - b.Time;
}
if (myTimesOptions.order === 'byDriven') {
return a.Driven - b.Driven;
}
};

const timesFilter = times => {
if (myTimesOptions.onlyImproved) {
const improved = [];
times
.sort((a, b) => a.Driven - b.Driven)
.forEach((t, i) => {
if (i === 0) {
improved.push(t);
} else if (t.Time < improved[improved.length - 1].Time) {
improved.push(t);
}
});
return improved;
}
return times;
};

return (
<Container>
{nickId() > 0 && (
Expand Down Expand Up @@ -140,12 +177,47 @@ const Personal = () => {
<Grid item xs={12} sm={6}>
<Paper padding>
<Header h2>Current event times</Header>
<div>
<MyTimesDesc>
This shows your online times for current event. Can be used to
verify that your times was registered on the server, as you
can&apos;t see these anywhere else. Apples results are not shown
here.
</div>
</MyTimesDesc>
<RadioGroup
aria-label="type"
value={myTimesOptions.order}
onChange={n =>
setMyTimesOptions({
...myTimesOptions,
order: n.target.value,
})
}
name="weeks"
row
>
<FormControlLabel
value="byTime"
checked={myTimesOptions.order === 'byTime'}
label="Order by time"
control={<RadioThin size="small" />}
/>
<FormControlLabel
value="byDriven"
checked={myTimesOptions.order === 'byDriven'}
label="Order chronologically"
control={<RadioThin size="small" />}
/>
</RadioGroup>
<FieldBoolean
label="Show only improved times"
value={myTimesOptions.onlyImproved}
onChange={() =>
setMyTimesOptions({
...myTimesOptions,
onlyImproved: !myTimesOptions.onlyImproved,
})
}
/>
{myTimes && (
<>
{events.sort(eventSort).map((e, i) => {
Expand All @@ -158,22 +230,24 @@ const Personal = () => {
<Header h3 top>
Event {i + 1}
</Header>
{myTimesInLev[0].times.map(t => (
<ReplayCon key={t.TimeIndex}>
<div>
<Time time={t.Time} />
</div>
<Desc>
(
<LocalTime
date={t.Driven}
format="dddd HH:mm:ss"
parse="X"
/>
)
</Desc>
</ReplayCon>
))}
{timesFilter(myTimesInLev[0].times)
.sort(timesSort)
.map(t => (
<ReplayCon key={t.TimeIndex}>
<div>
<Time time={t.Time} />
</div>
<Desc>
(
<LocalTime
date={t.Driven}
format="dddd HH:mm:ss"
parse="X"
/>
)
</Desc>
</ReplayCon>
))}
</>
);
})}
Expand Down Expand Up @@ -205,4 +279,15 @@ const Container = styled.div`
padding: 8px;
`;

const RadioThin = styled(Radio)`
&& {
padding-top: 0;
padding-bottom: 0;
}
`;

const MyTimesDesc = styled.div`
margin-bottom: ${p => p.theme.padSmall};
`;

export default Personal;
12 changes: 12 additions & 0 deletions src/pages/cup/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ export default {
actions.pushMyTimes({ times: times.data, level: payload.LevelIndex });
}
}),
myTimesOptions: persist(
{
order: 'byTime',
onlyImproved: false,
},
{
storage: 'localStorage',
},
),
setMyTimesOptions: action((state, payload) => {
state.myTimesOptions = payload;
}),
teamReplays: [],
teamOptions: persist(
{
Expand Down
4 changes: 2 additions & 2 deletions src/pages/help/tabs/Donate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ const Donate = ({ cached = false, small = false }) => {
} = useStoreActions(actions => actions.Help);

useEffect(() => {
if (!donations) getDonations({ cached });
});
getDonations({ cached });
}, [cached]);

if (!donations) return <span>loading...</span>;

Expand Down
6 changes: 3 additions & 3 deletions src/pages/level/StatsTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ const finishedTypes = {
};

const StatsTable = ({ data, loading }) => {
if (data.length === 0) {
if (loading) return <Loading />;
if (!data?.length) {
return <Container>You have not played this level yet.</Container>;
}
if (loading) return <Loading />;

const getTotalRunCount = () => {
return sumBy(data, 'RunCount');
Expand Down Expand Up @@ -122,7 +122,7 @@ const StatsTable = ({ data, loading }) => {
};

StatsTable.propTypes = {
data: PropTypes.arrayOf(PropTypes.shape()).isRequired,
data: PropTypes.arrayOf(PropTypes.shape()),
};

const Container = styled.div`
Expand Down
2 changes: 1 addition & 1 deletion src/pages/level/TimeTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const TimeTable = ({ data, latestBattle, loading, height }) => {
};

TimeTable.propTypes = {
data: PropTypes.arrayOf(PropTypes.shape()).isRequired,
data: PropTypes.arrayOf(PropTypes.shape()),
};

export default TimeTable;
6 changes: 3 additions & 3 deletions src/pages/level/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const Level = ({ LevelId }) => {
} = useQueryAlt(
['CrippledTimes', LevelId, cripple],
async () => CrippledTimes(LevelId, cripple, 1000, 1, 10000),
{ enabled: cripple !== '' && tab !== 2 },
{ enabled: cripple !== '' && tab !== 2, retry: 0 },
);

const {
Expand All @@ -126,7 +126,7 @@ const Level = ({ LevelId }) => {
} = useQueryAlt(
['CrippledPersonal', LevelId, kuskiIndex, cripple],
async () => CrippledPersonal(LevelId, kuskiIndex, cripple, 1000),
{ enabled: cripple !== '' && kuskiIndex > 0 && tab === 2 },
{ enabled: cripple !== '' && kuskiIndex > 0 && tab === 2, retry: 0 },
);

const {
Expand All @@ -141,7 +141,7 @@ const Level = ({ LevelId }) => {
} = useQueryAlt(
['CrippledTimeStats', LevelId, kuskiIndex, cripple],
async () => CrippledTimeStats(LevelId, kuskiIndex, cripple),
{ enabled: cripple !== '' && kuskiIndex > 0 && tab === 2 },
{ enabled: cripple !== '' && kuskiIndex > 0 && tab === 2, retry: 0 },
);

const fetchPersonalStats = () => {
Expand Down
Loading

0 comments on commit 2f64c32

Please sign in to comment.