zkrising / Tachi

A Cutting-Edge, Modular Score Tracker
https://tachi.ac
132 stars 58 forks source link

refactor(client): unify user profile components #1156

Closed saintnoodle closed 2 months ago

saintnoodle commented 3 months ago

Currently, the UGS info component is used in two different ways. This new component merges the functionality of the two and simplifies the data flow.

Current behaviour fetches the game stats of the requested user whenever the component is created. This generates an unneccessary fetch everytime the component is created and, because the component isn't memoised, creates a second fetch after the component renders.

To fix this, it now chooses how to source data based on conditions:

One semi-important thing to note is that is that both instances currently use different methods to sort game:playtypes. The method I've left in is the oldest, and I'm not sure why the dashboard instance deviated from this; if there's a good reason for that let me know.

saintnoodle commented 3 months ago

The change to the React Query hook is important to verify too. I thought it was strange that an error is thrown inside the callback when skip is true when React Query exposes a method of preventing fetches already. The change favours that option instead of throwing inside the callback.

zkrising commented 2 months ago

Looked at this and forgot to merge it. It seems like a fairly benign cleanup change.