Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make psychsheets sort by average by default #10368

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

pranav-027
Copy link
Member

Making new psych sheet behavior consistent with old one

Comment on lines 101 to 107
useEffect(() => {
if (psychSheetEvent === '333mbf') {
setPsychSheetSortBy('single');
} else {
setPsychSheetSortBy('average');
}
}, [psychSheetEvent]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good usage of useEffect. In essence, you're only recomputing the initial value for useMemo above. So, you should replace this whole effect hook with a single line along the lines of const default sort = isMultiBld ? 'single' : 'average' and then pass that new value as initializer: useMemo(psychSheetEvent)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@@ -95,7 +96,7 @@ export default function RegistrationList({ competitionInfo }) {
const changeSortColumn = (name) => dispatch({ type: 'CHANGE_SORT', sortColumn: name });

const [psychSheetEvent, setPsychSheetEvent] = useState();
const [psychSheetSortBy, setPsychSheetSortBy] = useState('single');
const psychSheetSortBy = useMemo(() => (psychSheetEvent === '333mbf' ? 'single' : 'average'), [psychSheetEvent]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC in the old system all blindfolded events were sorted by single, not just 333mbf

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reminding @maxidragon. It's implemented

@@ -115,7 +117,6 @@ export default function RegistrationList({ competitionInfo }) {

const registrationsWithPsychsheet = useMemo(() => {
if (psychSheet !== undefined) {
setPsychSheetSortBy(psychSheet.sort_by);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this line being deleted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, react throws an error that setPsychSheetSortBy is not defined

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, because you're changing to a useMemo above. I see. But that means when loading a psych sheet from the backend, you cannot change the sort order anymore. I feel like this will break lots of existing use-cases

(for example, this will break proper sorting on events like 333 which have genuine use-cases of using either single or average for sorting)

@@ -94,8 +94,10 @@ export default function RegistrationList({ competitionInfo }) {
const { sortColumn, sortDirection } = state;
const changeSortColumn = (name) => dispatch({ type: 'CHANGE_SORT', sortColumn: name });

const blindFoldedEvents = ['333mbf', '333bf', '444bf', '555bf'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to hardcode this. We have events data available as import { events } from 'lib/wca-data.js.erb' (note you might need to change the relative path to the file)

const [psychSheetEvent, setPsychSheetEvent] = useState();
const [psychSheetSortBy, setPsychSheetSortBy] = useState('single');
const psychSheetSortBy = useMemo(() => (blindFoldedEvents.includes(psychSheetEvent) ? 'single' : 'average'), [psychSheetEvent]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using my suggestion from above, you can compute this as events.byId[psychSheetEvent].recommendedFormat().sortBy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants