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
Fix Spinner does not stop when favorites is an empty list #430
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed write-up! I think the solution you landed on is the best balance of simplicity & functionality 🙂
I have one bit of feedback on the prop name, but this is working well in my testing 👍🏻
public_html/wp-content/themes/pattern-directory/src/components/my-favorites/index.js
Outdated
Show resolved
Hide resolved
Well explained! I'm a bit hesitant introducing Instead of passing the props down into the |
I'm thinking that About not passing props down to Some perks of the change:
Drawback:
|
Yes, but I was also thinking something within
Yep, that's sounds fine. If we do use a Parent component do we need to make any other changes? Will |
I'm tempted to consider |
960a803
to
6d95bca
Compare
If users' favorite pattern list is empty, do not show spinner.
6d95bca
to
b2df1b2
Compare
If a user didn't add any pattern to its favorite list, when switching to other categories, the loading spinner would keep spinning even if the loading is over.
Root cause
Details
This is the logic that decides whether to stop showing the spinner.
pattern-directory/public_html/wp-content/themes/pattern-directory/src/components/context-bar/index.js
Line 115 in 21e69c4
Its logic comes from this function:
pattern-directory/public_html/wp-content/themes/pattern-directory/src/components/context-bar/index.js
Line 69 in 21e69c4
pattern-directory/public_html/wp-content/themes/pattern-directory/src/store/selectors.js
Lines 20 to 24 in 21e69c4
isLoading
would always betrue
when the favorites list is empty (i.e., You won't see any patterns under FavoritesAll
)Once there's a pattern in the favorites list,
isLoading
would becomefalse
(explained later), and the problem is solved then.The reason
isLoading
is alwaystrue
in this case is that thequeryString
could not be found instate.patterns.queries
.Why so? That's because we didn't call
getPatternsByQuery( modifiedQuery )
pattern-directory/public_html/wp-content/themes/pattern-directory/src/components/my-favorites/index.js
Line 37 in 21e69c4
when the fav list is empty, which causes that the
queryString
isn't stored via dispatching theloadPatterns
.And this is also why
isLoading
would becomefalse
once there's a pattern in the favorites list - thegetPatternsByQuery( modifiedQuery )
is called.pattern-directory/public_html/wp-content/themes/pattern-directory/src/store/resolvers.js
Lines 53 to 58 in 21e69c4
So here comes the first solution
Sol 1
Call
getPatternsByQuery( modifiedQuery )
no matter if thefavorites.length===0
or notHowever, though it solved the
isLoading
is alwaystrue
problem, it would bring another issue.Since we don't have any items in the favorites list for the moment, the
include
inmodifiedQuery
would be[]
, and when thismodifiedQuery
is sent as payload through thegetPatternsByQuery( modifiedQuery )
, theinclude=[]
would be filtered out in advance inaddQueryArgs
before sending to the endpoint'/wp/v2/wporg-pattern'
.pattern-directory/public_html/wp-content/themes/pattern-directory/src/components/my-favorites/index.js
Line 35 in 21e69c4
pattern-directory/public_html/wp-content/themes/pattern-directory/src/store/resolvers.js
Lines 48 to 49 in 21e69c4
Usually, for a normal case, it would include something like
include[0]=732
in the payload when sending to that endpoint and gets the response with the pattern data of patternId 732.And since in the case mentioned above,
include=[]
is filtered out from payload, the endpoint response would still return withour suggested favorite patterns
for a certain category and the patterns would be stored instate.patterns.queries
.Since there are favorite patterns returned by endpoint and stored into state, it would make the number of patterns in a category wrong.
pattern-directory/public_html/wp-content/themes/pattern-directory/src/components/context-bar/index.js
Line 74 in 21e69c4
pattern-directory/public_html/wp-content/themes/pattern-directory/src/store/selectors.js
Lines 60 to 63 in 21e69c4
This issue could be solved by making it still send
include
in payload with value like[-1]
to make it return[]
, which is definitely a bad idea and confusing solution that needs some comments.Or we can modify the logic of the endpoint and the
addQueryArgs
instead to make it send something legit wheninclude=[]
from client to the endpoint and have some corresponding process to it. And this is where I found it difficult for the moment to locate where and how the query string paramspattern-categories
andinclude
are processed. Might need more studies and some clarifying for my doubts on my side if we choose this solution at the end of the day.Sol 2
Add a condition check for
query.include
inisLoadingPatternByQuery
.It's not that ideal as it's kind of specifically for a certain case and might need some comments.
But it probably is safe for the moment to my knowledge as the
include=[favorite patternIds]
is only used and included byMyFavorites
.Sol 3
Pass isEmpty as isFavoritesEmpty to ContextBar
It's also not that ideal as far as I'm concerned as it's a bit not clean and consistent.
But the code could speak itself.
Fixes #362
Screencasts
Before:
https://d.pr/v/pTI4lI
After:
https://d.pr/v/pdkMqt
How to test the changes in this Pull Request: