Skip to content

Commit

Permalink
Merge pull request #251 from elmadev/dev
Browse files Browse the repository at this point in the history
Live release 5 Oct 2024
  • Loading branch information
sunehs authored Oct 5, 2024
2 parents 8efb595 + 8ff95d8 commit aa054b8
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 48 deletions.
7 changes: 6 additions & 1 deletion src/components/RecListItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const RecListItem = ({ replay, selected, columns, mergable = false }) => {
const getTags = () => {
return replay.Tags.map(tag => tag.Name);
};

return (
<ListRow
key={`${replay.ReplayIndex}${replay.TimeIndex}`}
Expand All @@ -64,7 +65,11 @@ const RecListItem = ({ replay, selected, columns, mergable = false }) => {
)}
{columns.indexOf('Time') !== -1 && (
<ListCell right to={url}>
<Time thousands time={replay.ReplayTime} />
{replay.BattleIndex ? (
<Time time={replay.ReplayTime / 10} apples={replay.Apples} />
) : (
<Time thousands time={replay.ReplayTime} />
)}
</ListCell>
)}
{columns.indexOf('By') !== -1 && (
Expand Down
8 changes: 6 additions & 2 deletions src/components/TagFilter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const TagFilter = ({
multiple
id="Tags"
size="small"
options={tagOptions.filter(tag => !excludedTags.includes(tag))}
options={tagOptions.filter(
tag => !excludedTags.find(t => t.TagIndex === tag.TagIndex),
)}
getOptionLabel={option => option.Name}
getOptionSelected={(option, value) => option.Name === value.Name}
filterSelectedOptions
Expand All @@ -34,7 +36,9 @@ const TagFilter = ({
multiple
id="Excluded tags"
size="small"
options={tagOptions.filter(tag => !selectedTags.includes(tag))}
options={tagOptions.filter(
tag => !selectedTags.find(t => t.TagIndex === tag.TagIndex),
)}
getOptionLabel={option => option.Name}
getOptionSelected={(option, value) => option.Name === value.Name}
filterSelectedOptions
Expand Down
28 changes: 12 additions & 16 deletions src/features/RecList/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useEffect } from 'react';
import PropTypes from 'prop-types';
import { useStoreState, useStoreActions } from 'easy-peasy';
import { sortBy, filter, intersectionBy } from 'lodash';
Expand All @@ -18,21 +18,17 @@ const RecList = ({
LevelIndex,
mergable = false,
}) => {
const { loading, replays, tagOptions } = useStoreState(
state => state.RecList,
);
const { getTagOptions, getReplays } = useStoreActions(
actions => actions.RecList,
);
const [includedTags, setIncludedTags] = useState([]);
const [excludedTags, setExcludedTags] = useState([]);

useEffect(() => {
// Autoexclude DNF and TAS
setExcludedTags(
tagOptions.filter(tag => ['DNF', 'TAS'].includes(tag.Name)),
);
}, [tagOptions]);
const {
loading,
replays,
tagOptions,
tags: { includedTags, excludedTags },
} = useStoreState(state => state.RecList);
const {
getTagOptions,
getReplays,
tags: { setIncludedTags, setExcludedTags },
} = useStoreActions(actions => actions.RecList);

useEffect(() => {
getReplays(LevelIndex);
Expand Down
15 changes: 14 additions & 1 deletion src/features/RecList/store.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-param-reassign */
import { action, thunk } from 'easy-peasy';
import { action, thunk, persist } from 'easy-peasy';
import { ReplaysByLevelIndex, GetReplayTags } from 'api';

export default {
Expand Down Expand Up @@ -29,4 +29,17 @@ export default {
actions.setTagOptions(get.data);
}
}),
tags: persist(
{
includedTags: [],
setIncludedTags: action((state, payload) => {
state.includedTags = payload;
}),
excludedTags: [],
setExcludedTags: action((state, payload) => {
state.excludedTags = payload;
}),
},
{ storage: 'localStorage' },
),
};
21 changes: 12 additions & 9 deletions src/features/ReplayList/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,22 @@ export default function ReplayList({
persist = '',
uploadFab = false,
}) {
const [selectedTags, setSelectedTags] = useState([]);
const [excludedTags, setExcludedTags] = useState([]);
const [previewRec, setPreviewRec] = useState(null);
const [page, setPage] = useState(defaultPage);
const [pageSize] = useState(defaultPageSize);
const { replays, tagOptions, settings, persistPage } = useStoreState(
state => state.ReplayList,
);
const {
replays,
tagOptions,
settings,
persistPage,
tags: { includedTags, excludedTags },
} = useStoreState(state => state.ReplayList);
const {
getReplays,
getTagOptions,
setSettings,
setPersistPage,
tags: { setIncludedTags, setExcludedTags },
} = useStoreActions(actions => actions.ReplayList);
const { loggedIn, userid } = useStoreState(state => state.Login);

Expand All @@ -60,15 +63,15 @@ export default function ReplayList({
getReplays({
page: getPage(),
pageSize,
tags: selectedTags.map(tag => tag.TagIndex),
tags: includedTags.map(tag => tag.TagIndex),
excludedTags: excludedTags.map(tag => tag.TagIndex),
sortBy: !summary ? settings.sortBy : 'uploaded',
order: settings.sortBy === 'time' ? 'asc' : 'desc',
drivenBy,
uploadedBy,
levelPack,
});
}, [page, pageSize, selectedTags, excludedTags, settings.sortBy]);
}, [page, pageSize, includedTags, excludedTags, settings.sortBy]);

const updatePage = pageNo => {
setPage(pageNo);
Expand Down Expand Up @@ -151,9 +154,9 @@ export default function ReplayList({
<StickyContainer nonsticky={nonsticky}>
<TagFilter
tagOptions={tagOptions}
selectedTags={selectedTags}
selectedTags={includedTags}
onSelectedTagsChange={(_event, newValue) => {
setSelectedTags(newValue);
setIncludedTags(newValue);
updatePage(0);
}}
excludedTags={excludedTags}
Expand Down
13 changes: 13 additions & 0 deletions src/features/ReplayList/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,17 @@ export default {
setPersistPage: action((state, payload) => {
state.persistPage[payload.key] = payload.pageNo;
}),
tags: persist(
{
includedTags: [],
setIncludedTags: action((state, payload) => {
state.includedTags = payload;
}),
excludedTags: [],
setExcludedTags: action((state, payload) => {
state.excludedTags = payload;
}),
},
{ storage: 'localStorage' },
),
};
33 changes: 14 additions & 19 deletions src/pages/replay/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ import { Row, Column } from 'components/Containers';
import { pts } from 'utils/cups';
import { mod } from 'utils/nick';

const RecTime = ({ type, replay }) => {
if (type === 'cup') {
return <Time time={replay.ReplayTime / 10} apples={-1} />;
}
if (type === 'winner') {
return <Time time={replay.ReplayTime / 10} apples={replay.Apples} />;
}
return <Time thousands time={replay.ReplayTime} />;
};

const getLink = replay => {
let link = '';
let type = 'replay';
Expand Down Expand Up @@ -232,26 +242,11 @@ const Replay = ({ ReplayUuid, RecFileName }) => {
</div>
<div>
{isWindow ? (
<>
<a href={dlLink}>
{type === 'cup' ? (
<Time
time={replay.ReplayTime / 10}
apples={-1}
/>
) : (
<Time thousands time={replay.ReplayTime} />
)}
</a>{' '}
</>
<a href={dlLink}>
<RecTime type={type} replay={replay} />
</a>
) : (
<>
{type === 'cup' ? (
<Time time={replay.ReplayTime / 10} apples={-1} />
) : (
<Time thousands time={replay.ReplayTime} />
)}
</>
<RecTime type={type} replay={replay} />
)}{' '}
in{' '}
<Level
Expand Down

0 comments on commit aa054b8

Please sign in to comment.