Youtube Video Search on Sharepoint!!
Scenario:- Users should be able to search for youtube videos and play them.
Pre-Requsite:- Basics of React and sharepoint content editor webpart.
UI Layout:-
React App steps for build
- The react solution has total five componenets of which only one is class based component all other are functional components.
- App
- Search Bar
- Video Details
- Video List
- Video List Item
- For searching youtube videos from the youtube we use youtube-api-search package. We also need to have an API Key for youtube to know who is searching the videos.
NPM install youtube-api-search
- We can use the YTSearch function from the api to perform the search. In the callback function we get the list of videos.
- App :- It’s a parent componenet which holds all the child components. Its contains internal state of Videos and selected Video.
- Search :- It’s a functional component where we show a search box and onchange event. Search expects a props for the onchange event. Whenever a search term changes this event gets called.
- Video Details:- It’s a functionla componenet which will show the selected videos passed as props to the component. It will display the title and description of the video. We will embed video on the page using the video url.
- Video List Item:- It’s a functional component which shows short information of the video. It handles onclick event to pass the selected video details to the parent component.
- Video List:- IT shows the list of videos which are passed as Props to the component. It uses the child component Video List Item to show short video details.
- On the App component the UI looks like below which shows all the details.
- Build the App and the generate the bundle.js file. Create a html page which contains a div html element with the class container, react components will be loaded under the div element.
Uploading the Files to sharepoint and configure the webpart.
- Upload the files bundle.js and index.html to the Style Assets library of the root site.
- Create a new page on the root web and add the content editor web part. Edit the properties of the content editor webpart. To refer the uploaded index.html page from the site assets library. Save the settings and publish the page.
- The final Youtube search page looks like below.
The complete code to the above app is located in the below git hub location.
Comments
Post a Comment