Download wp-calypso/client/data/media/use-add-media.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/media/use-add-media.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/data/media/use-add-media.js
-
curl -L -o use-add-media.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/media/use-add-media.js
1.12 kB
| import { useCallback } from 'react'; | |
| import { getFileUploader, canUseVideoPress } from 'calypso/lib/media/utils'; | |
| import { isFileList } from 'calypso/state/media/utils/is-file-list'; | |
| import { useUploadMediaMutation } from './use-upload-media-mutation'; | |
| export const useAddMedia = () => { | |
| const { uploadMediaAsync } = useUploadMediaMutation(); | |
| const addVideopressStatusToFile = ( file, site ) => { | |
| const siteCanUseVideoPress = canUseVideoPress( site ); | |
| const addVideoPressStatusToFileObject = ( fileObject ) => { | |
| fileObject.canUseVideoPress = siteCanUseVideoPress; | |
| }; | |
| if ( isFileList( file ) ) { | |
| Array.from( file ).forEach( addVideoPressStatusToFileObject ); | |
| } else if ( Array.isArray( file ) ) { | |
| file.forEach( addVideoPressStatusToFileObject ); | |
| } else if ( 'object' === typeof file ) { | |
| addVideoPressStatusToFileObject( file ); | |
| } | |
| return file; | |
| }; | |
| const addMedia = useCallback( | |
| ( file, site, postId ) => { | |
| return uploadMediaAsync( | |
| addVideopressStatusToFile( file, site ), | |
| site, | |
| postId, | |
| getFileUploader | |
| ); | |
| }, | |
| [ uploadMediaAsync ] | |
| ); | |
| return addMedia; | |
| }; | |