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

Refactor and fix types in events redux code #4977

Merged
merged 8 commits into from
Sep 25, 2024
Merged

Conversation

eikhr
Copy link
Member

@eikhr eikhr commented Sep 22, 2024

Description

Improves types and simplifies redux code related to events. Fixes most of the typescript errors in events code.

Number of typescript errors: 474 -> 371

Result

No visual changes.
Except that I fixed two small bugs:

  1. When unregistering people from the administrate view, the button loading state is now set correctly
  2. The registration countdown no longer shows 0 seconds left (mistake from Simplify event detail page by moving stuff into components #4974)

Testing

  • I have thoroughly tested my changes.

The redux code is fairly well tested using unit tests, these still pass of course. I have also manually tested by opening pages and testing some core functionality.

Copy link

vercel bot commented Sep 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
lego-bricks-storybook ⬜️ Ignored (Inspect) Visit Preview Sep 23, 2024 1:47pm

@github-actions github-actions bot added the review-needed Pull requests that need review label Sep 22, 2024
@eikhr eikhr force-pushed the improve-redux-events branch 2 times, most recently from 95a02a4 to c00ec5c Compare September 23, 2024 09:01
@eikhr eikhr changed the title Move interested button into a separate component Refactor and fix types in events redux code Sep 23, 2024
@eikhr eikhr requested review from ivarnakken, norbye, juniwbjerde, falbru and jonasdeluna and removed request for ivarnakken and norbye September 23, 2024 09:05
@eikhr eikhr marked this pull request as ready for review September 23, 2024 09:06
Comment on lines -28 to -36
usePreparedEffect(
'fetchEventAbacard',
() => {
if (query && typeof query === 'string') {
return dispatch(autocomplete(query, ['users.user']));
}
},
[query],
);
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know what this was supposed to do. typeof query is never a string

Copy link
Member

Choose a reason for hiding this comment

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

you never know with this webapp! 😆

Copy link
Member Author

Choose a reason for hiding this comment

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

This is all moved out of EventDetail with very minor changes

@eikhr eikhr merged commit 8ae9420 into master Sep 25, 2024
6 checks passed
@eikhr eikhr deleted the improve-redux-events branch September 25, 2024 11:03
Copy link
Member

@norbye norbye left a comment

Choose a reason for hiding this comment

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

Whop didn't get to review everything, but I'll submit my one comment

Comment on lines -17 to +19
initialState: legoAdapter.getInitialState(),
initialState: legoAdapter.getInitialState({
test: 1,
}),
Copy link
Member

Choose a reason for hiding this comment

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

What's the purpose of this test: 1?

Copy link
Member Author

Choose a reason for hiding this comment

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

well, heh, it was for testing the typescript types...
Fixed in #5002

Copy link
Member

@ivarnakken ivarnakken left a comment

Choose a reason for hiding this comment

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

Looks much cleaner! 😍 You've done an awesome job here! I love the custom hooks

@@ -402,7 +415,7 @@ const JoinEventForm = ({

{event.activationTime && registrationOpensIn && (
<Button disabled={disabledButton}>
{`Åpner om ${moment(registrationOpensIn.asMilliseconds()).format('mm:ss')}`}
{`Åpner om ${moment(registrationOpensIn.add(1, 'second').asMilliseconds()).format('mm:ss')}`}
Copy link
Member

Choose a reason for hiding this comment

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

Isn't the add supposed to be on the moment object instead of registrationOpensIn?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's ugly but it works correctly now. We add one second to the displayed time left until it opens, so that the countdown will end after showing 00:01 instead of showing 00:00 for one second. Normally it rounds down the number of seconds left.

Copy link
Member

Choose a reason for hiding this comment

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

I get that, but I was wondering if it was more "right" to do

Suggested change
{`Åpner om ${moment(registrationOpensIn.add(1, 'second').asMilliseconds()).format('mm:ss')}`}
{`Åpner om ${moment(registrationOpensIn).add(1, 'second').asMilliseconds().format('mm:ss')}`}

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, right of course. No, I don't think so, this does something weird to get the formatting we want. registrationOpensIn is a duration, we add one second to this duration, and then we change it into a moment which is more of a timestamp (I think?). And then we format this as "mm:ss" to get the countdown.
I'm not sure how it works, but I think it is correct now. The duration (registrationOpensIn) doesn't have .format, so we need to do moment() and I'm not sure if .add would work the same after doing moment()

@@ -385,6 +397,7 @@ const JoinEventForm = ({
!registrationPending &&
!registration &&
captchaOpen &&
config.environment !== 'ci' &&
Copy link
Member

Choose a reason for hiding this comment

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

This could probably just be on the Captcha Field itself

Comment on lines 98 to +101

unansweredSurveys: EntityId[];

actionGrant: ActionGrant;
Copy link
Member

Choose a reason for hiding this comment

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

What's up with the spacings

Copy link
Member Author

Choose a reason for hiding this comment

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

idk, sometimes I've put some spacing to separate admin-stuff from normal stuff f.ex. But this one seems unnecessary

selectAllEvents<ListEventWithUserRegistration>(state, {
pagination: previousEventsPagination,
}),
).filter((e) => e.userReg);
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 filter only done on previous events?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it filters out any events weher you were on the waiting list. For upcoming events we want to show these too.

).filter((e) => e.userReg);

const sortedPreviousEvents = previousEvents
?.filter((e) => !!e.userReg?.pool)
Copy link
Member

Choose a reason for hiding this comment

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

I suppose e.userReg will never be undefined since you've already filtered it out above

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree, but typescript is dumb

Comment on lines 39 to +40
For arrangement{' '}
<Link to={`/events/${event.id}`}>{event.title}</Link>
<Link to={`/events/${event?.id}`}>{event?.title}</Link>
Copy link
Member

Choose a reason for hiding this comment

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

Kinda useless to only show "For arrangement" if event is undefined

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think all surveys have an event. But it will probably look a bit weird while loading:/

Comment on lines 128 to +132
const params = useParams<{
eventIdOrSlug: string;
}>();
}>() as {
eventIdOrSlug: string;
};
Copy link
Member

Choose a reason for hiding this comment

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

Is this really how we have to do this now 💀

Copy link
Member Author

Choose a reason for hiding this comment

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

Argh, yes... I don't know why they changed this to make all params optional, it worked fine in react-router-v5. And the params are required, there is no way to reach this path without specifying an event id...

I have a plan to make a custom hook like useRequiredParams or something, that just typecasts this a bit prettier.

Copy link
Member

Choose a reason for hiding this comment

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

haha oh well 🤷🏼‍♂️

Comment on lines -28 to -36
usePreparedEffect(
'fetchEventAbacard',
() => {
if (query && typeof query === 'string') {
return dispatch(autocomplete(query, ['users.user']));
}
},
[query],
);
Copy link
Member

Choose a reason for hiding this comment

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

you never know with this webapp! 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review-needed Pull requests that need review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants