Download wp-calypso/client/my-sites/posts/controller.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.57 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/my-sites/posts/controller.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/my-sites/posts/controller.js
-
curl -L -o controller.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/my-sites/posts/controller.js
1.57 kB
| import page from '@automattic/calypso-router'; | |
| import debugFactory from 'debug'; | |
| import { createElement } from 'react'; | |
| import Posts from 'calypso/my-sites/posts/main'; | |
| import { getCurrentUserId } from 'calypso/state/current-user/selectors'; | |
| import areAllSitesSingleUser from 'calypso/state/selectors/are-all-sites-single-user'; | |
| import { isJetpackSite, isSingleUserSite } from 'calypso/state/sites/selectors'; | |
| import { getSelectedSiteId } from 'calypso/state/ui/selectors'; | |
| const debug = debugFactory( 'calypso:my-sites:posts' ); | |
| export default { | |
| posts: function ( context, next ) { | |
| const state = context.store.getState(); | |
| const siteId = getSelectedSiteId( state ); | |
| const author = context.params.author === 'my' ? getCurrentUserId( state ) : null; | |
| let search = context.query.s || ''; | |
| const category = context.query.category; | |
| const tag = context.query.tag; | |
| function shouldRedirectMyPosts() { | |
| if ( ! author ) { | |
| return false; | |
| } | |
| if ( areAllSitesSingleUser( state ) ) { | |
| return true; | |
| } | |
| if ( isSingleUserSite( state, siteId ) || isJetpackSite( state, siteId ) ) { | |
| return true; | |
| } | |
| } | |
| debug( 'author: `%s`', author ); | |
| // Disable search in all-sites mode because it doesn't work. | |
| if ( ! siteId ) { | |
| search = ''; | |
| } | |
| debug( 'search: `%s`', search ); | |
| if ( shouldRedirectMyPosts() ) { | |
| page.redirect( context.path.replace( /\/my\b/, '' ) ); | |
| return; | |
| } | |
| context.primary = createElement( Posts, { | |
| context, | |
| author, | |
| statusSlug: context.params.status, | |
| search, | |
| category, | |
| tag, | |
| } ); | |
| next(); | |
| }, | |
| }; | |