-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
media state: create
fetchNextMediaPage
thunk and replace usages of …
…`MediaActions.fetchNextPage` (#44023) * create 'isFetchingNextPage' selector * create 'fetchNextPage' thunk and prepare data layer * replace usages of `MediaActions.fetchNextPage` with `fetchNextPage` thunk * fix tests * make flux removal comment more prominent * fetch-next-page: fix jsdoc description * media state: rename `fetchNextPage` to `fetchNextMediaPage`
- Loading branch information
Showing
12 changed files
with
148 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import debugFactory from 'debug'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import isFetchingNextPage from 'state/selectors/is-fetching-next-page'; | ||
import MediaListStore from 'lib/media/list-store'; | ||
import { dispatchFluxFetchMediaItems } from 'state/media/utils/flux-adapter'; | ||
import { requestMedia } from 'state/media/actions'; | ||
|
||
const debug = debugFactory( 'calypso:media' ); | ||
|
||
/** | ||
* Redux thunk to fetch next page of media items | ||
* | ||
* @param {number} siteId site identifier | ||
*/ | ||
export const fetchNextMediaPage = ( siteId ) => ( dispatch, getState ) => { | ||
if ( isFetchingNextPage( getState(), siteId ) ) { | ||
return; | ||
} | ||
|
||
/* | ||
* @TODO: Temporarily this action will dispatch to the flux store, until | ||
* the flux store is removed. After we completely removed the flux store | ||
* it should be enough to just call the `requestMedia( ... )` action | ||
*/ | ||
dispatchFluxFetchMediaItems( siteId ); | ||
|
||
const query = MediaListStore.getNextPageQuery( siteId ); | ||
|
||
debug( 'Fetching media for %d using query %o', siteId, query ); | ||
|
||
dispatch( requestMedia( siteId, query ) ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { get } from 'lodash'; | ||
|
||
/** | ||
* Returns true if media is being requested for a specified site ID and query. | ||
* | ||
* @param {object} state Global state tree | ||
* @param {number} siteId Site ID | ||
* @returns {boolean} True if media is being requested | ||
*/ | ||
export default function isFetchingNextPage( state, siteId ) { | ||
return get( state.media.fetching, [ siteId, 'nextPage' ], false ); | ||
} |
Oops, something went wrong.