cubing / cubingcontests.com

A place for hosting results from unofficial Rubik's cube competitions
https://cubingcontests.com
GNU General Public License v3.0
9 stars 4 forks source link

Add event filter to the contests page #30

Closed maxidragon closed 1 month ago

maxidragon commented 1 month ago

Closes #27

dmint789 commented 1 month ago

@maxidragon is it good to be merged now? Were you able to fix the bugs?

maxidragon commented 1 month ago

@maxidragon is it good to be merged now? Were you able to fix the bugs?

Everything works except for one thing: I sent you a video on Discord a couple of days ago. After refreshing page with eventId set and unselecting, nothing changes. I don't know how to fix this, though

dmint789 commented 1 month ago

Ohh, right, cause the EventButtons component isn't rerendering, since eventId is just a prop, not state. Can you add key={eventId} right after <EventButtons in the page.tsx file? That will force it to rerender when the eventId search param changes. Also, can you please rename the parameter eventId in handleEventClick to newEventId? That way it's different from the eventId prop.

dmint789 commented 1 month ago

Turns out, that doesn't work, because when the searchParam is removed, there is no update. In that case, remove the key attribute, and just add a selectedEvent state to the EventButtons component, and update it inside of handleEventClick at the very top. If newEventId === eventId, just set selectedEvent to ''. Then use selectedEvent instead of eventId in the isActive attribute of the EventIcon component.

dmint789 commented 1 month ago

For whatever reason, when searchParams is empty, it doesn't update the page component. Let's just go back to the key={eventId} solution, get rid of the new state, and just use window.location.href = ... when newEventId is the same as eventId.