-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Posts: Convert PostSelector to using posts Redux state #2350
Conversation
I like this from the how-it-works side, and how it turns I think this could be solved (or at least improved) with better conventions and naming. For instance, |
} | ||
|
||
PostsTypeahead.propTypes = { | ||
siteId: PropTypes.number.isRequired, |
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.
It'd be nice to support cross-site results here.
165b973
to
376b5c4
Compare
The intent of this pull request has changed significantly. I've left the original commits in case we want to recover some of the This required a handful of changes to the posts Redux state to better manage pagination. |
@timmyc : If you have a spare moment, would you mind taking a pass over the changes to the |
Reading the code it looks good, let me run some tests on the branch and see how it goes. One thought though, is the query key case-sensitive, i.e. would searching for "Hello" vs "hello" yield two different query keys and spawn multiple api calls? If so would it be safe to downcase query strings before searching / creating the key? |
That's a very good point. Another potential issue is that explicit requests for default values will not be smart about reusing prior results, e.g. I'll take a look at improving how these keys are serialized to remove default values and lower-case. Thanks! |
Changes look good, and good call on stripping out the default query values too. One other question: Should/can |
Yeah, the plan is that |
Tested out the post-selector on the page editor and all seems well. It does seem ( though it could just be local env, or a slow connection ) that the initial load of the posts is slower than the old fetcher approach. But this is LGTM and a big improvement over the list-approach. |
... definitely my internet connection ( as my last comment failed to post to github on the first try ) :) |
|
||
## Usage | ||
|
||
Render the component, passing `siteId` and `query`. It does not accept any children, nor does it render any elements to the page. You can use it adjacent to other sibling components which make use of the fetched data made available through the global application state. |
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.
Can we make siteId
determine whether to fetch single site or all sites?
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.
Can we make
siteId
determine whether to fetch single site or all sites?
I think that's a reasonable enhancement, though also requires additional action creators in the sites state to handle fetching posts from /me
endpoints. Seems appropriate for a subsequent pull request.
One "issue" with how persistent the cache is here is that there's never a point at which the cache is invalidated. For example, if I were to publish a page and then start drafting another, I'd not be presented with the option to choose the first page as the parent page unless I triggered a full-page refresh. I think this will be an interesting challenge moving forward across Redux stores. Especially as we consider persisting the Redux state to browser storage, we'll want to think through cache-busting techniques. This pull request is quite large already, but I've considered a few options for resolving this particular need:
The first of these is probably the most minimal approach if we were to try to tackle a solution in this pull request. |
8df0cb5
to
b06b979
Compare
Added reset action in 32703e5, dispatched when navigating to the editor route in b06b979. Appreciate the reviews and apologies again for how large this pull request became. I'll plan to merge this in the morning unless either of you'd like more time to look over the latest changes. |
Need satisfied by existence of PostSelector
Optionally for a specific site
b06b979
to
18df734
Compare
Posts: Convert PostSelector to using posts Redux state
How does lowercasing the query string work for non-English / far east queries? Maybe it's worth investigating using |
The lower-casing doesn't affect the actual query to the REST API, but instead is used only as a reference for lookup. As long long as it results in a consistent and unique string, there shouldn't be a problem. We could/should probably be using |
@aduth calypso core is working on allowing for creating a new post while offline in the desktop for our meetup project. As part of this we were planning to persist global state, including the posts-list data. And we were thinking we would store some sort of ephemeral post object with some "offline" flag into the posts-list redux store. That way we could show the new post within the context of the draft drawer. But if we're busting the posts-list cache when you hit the editor, that sorta negates the plan. Could we instead trigger this on a post create, update, or delete? I understand we'd need to merge #2167 or something like it in order to sniff out those flux actions and replay them as redux actions. Are there other concerns with that approach that I'm missing? |
@rralian : Summarizing our chat conversation:
|
Related: #303, #2248
Edit: The purpose of this pull request has changed significantly. Refer to this gist for the original pull request content.
This pull request seeks to convert the existing
<PostSelector />
component to make use of the global Redux post state. It introduces a new<QueryPosts />
component for managing requests to the REST API, and implements the prerequisite pagination behavior to the posts state.Implementation notes:
An advantage of the new posts state is that previous post queries are cached, so if a user enters a search term, then clears their query, the component no longer needs to make another request for the original posts.
The
<QueryPosts />
component is the first example of a proposed fetching components pattern in managing the fetching of data to be accessed via global application state by sibling components.Testing instructions:
Confirm that there are no regressions with the parent page selector in the Calypso post editor, including infinite scroll pagination, search queries, and lack of results/pages.
Also confirm that Mocha tests pass by running
make test
from the project root directory or directly fromclient/state/posts
.