react-code-dataset / wp-calypso /apps /notifications /src /panel /state /action-middleware /suggestions /index.js
react-code-dataset / wp-calypso /apps /notifications /src /panel /state /action-middleware /suggestions /index.js
Download wp-calypso/apps/notifications/src/panel/state/action-middleware/suggestions/index.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/apps/notifications/src/panel/state/action-middleware/suggestions/index.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/apps/notifications/src/panel/state/action-middleware/suggestions/index.js
-
curl -L -o index.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/apps/notifications/src/panel/state/action-middleware/suggestions/index.js
1.11 kB
| import { fetchSuggestions } from '../../../rest-client/wpcom'; | |
| import * as types from '../../action-types'; | |
| import actions from '../../actions'; | |
| import hasSiteSuggestions from '../../selectors/has-site-suggestions'; | |
| let isFetchingSuggestions = false; | |
| const getUsersSuggestions = ( { dispatch, getState }, { siteId } ) => { | |
| if ( isFetchingSuggestions || hasSiteSuggestions( getState(), siteId ) ) { | |
| return; | |
| } | |
| isFetchingSuggestions = true; | |
| fetchSuggestions( | |
| { | |
| site_id: siteId, | |
| }, | |
| ( error, data ) => { | |
| isFetchingSuggestions = false; | |
| if ( error ) { | |
| return; | |
| } | |
| // Create a composite index to search against of; username + real name | |
| // This will also determine ordering of results, so username matches will appear on top | |
| const newSuggestions = data.suggestions.map( ( suggestion ) => ( { | |
| ...suggestion, | |
| name: suggestion.name || `${ suggestion.user_login } ${ suggestion.display_name }`, | |
| } ) ); | |
| dispatch( actions.suggestions.storeSuggestions( siteId, newSuggestions ) ); | |
| } | |
| ); | |
| }; | |
| export default { | |
| [ types.SUGGESTIONS_FETCH ]: [ getUsersSuggestions ], | |
| }; | |