Skip to content

implement filtering by completion status #180

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

Merged
merged 6 commits into from
Jul 25, 2022

Conversation

leo-step
Copy link
Contributor

@leo-step leo-step commented Jul 23, 2022

  • Added dropdown to filter problems based on whether they are marked done or not

Resolves #156

Copy link
Owner

@seanprashad seanprashad left a comment

Choose a reason for hiding this comment

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

Love the work you've done here @leo-step! I was able to test the patch out locally and everything is working smoothly. I do have one change request as well as 2 comments/questions for ya!

Let me know if anything doesn't make sense! We're very close to being able to land this 😁

localStorage.setItem(id, e.target.value);
setFilter(e.target.value || '');
Copy link
Owner

Choose a reason for hiding this comment

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

For my own learning, is this a best practice of updating localStorage first and then state? 🤔

Copy link
Contributor Author

@leo-step leo-step Jul 25, 2022

Choose a reason for hiding this comment

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

I swapped the order because the setFilter function for the checkbox filter reads localStorage and needs the value to be up to date. It doesn't make a difference for any of the other filters.

Copy link
Owner

Choose a reason for hiding this comment

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

This makes total sense to me - I forgot we had included this behaviour in #167!

@@ -31,20 +32,19 @@ import PatternFrequencies from '../PatternFrequencies';
const iconPath = `${process.env.PUBLIC_URL}/assets/icons/`;

const Table = () => {
const data = React.useMemo(() => questions, []);
Copy link
Owner

Choose a reason for hiding this comment

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

If I remember correctly, we introduced useMemo() to capture performance gains - see the docs here:

Pass a “create” function and an array of dependencies. useMemo will only recompute the memoized value when one of the dependencies has changed. This optimization helps to avoid expensive calculations on every render.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This new filter is a little different from the other ones because it works with a dynamic checkbox field instead of static properties like difficulty. Previously, the caching worked well because nothing could really be overwritten, but now I encountered problems with it because my assigned properties would constantly be reset. Using useState instead of useMemo solved this problem.

Also I'm not sure if there is a performance gain from useMemo for this line in particular. Isn't it just saving a reference to the questions array? It doesn't seem like a very expensive operation, but correct me if I'm wrong.

@leo-step leo-step requested a review from seanprashad July 25, 2022 17:20
Copy link
Owner

@seanprashad seanprashad left a comment

Choose a reason for hiding this comment

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

Thank you very much for making those adjustments - everything is looking good now!

@seanprashad seanprashad merged commit 53a7758 into seanprashad:master Jul 25, 2022
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.

Be able to filter by completion status
2 participants