From f31c0d97f9f59371d90d1396469aa9569933fb0d Mon Sep 17 00:00:00 2001 From: Mohammad Amoush Date: Thu, 27 Jun 2019 12:55:31 -0400 Subject: Youtube Results Showing as List Implemented --- src/client/apis/youtube/YoutubeBox.tsx | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'src/client/apis') diff --git a/src/client/apis/youtube/YoutubeBox.tsx b/src/client/apis/youtube/YoutubeBox.tsx index b044e2a05..d4d37950e 100644 --- a/src/client/apis/youtube/YoutubeBox.tsx +++ b/src/client/apis/youtube/YoutubeBox.tsx @@ -4,7 +4,7 @@ import { FieldViewProps, FieldView } from "../../views/nodes/FieldView"; import { HtmlField } from "../../../new_fields/HtmlField"; import { WebField } from "../../../new_fields/URLField"; import { observer } from "mobx-react"; -import { computed, reaction, IReactionDisposer, observable } from 'mobx'; +import { computed, reaction, IReactionDisposer, observable, action } from 'mobx'; import { DocumentDecorations } from "../../views/DocumentDecorations"; import { InkingControl } from "../../views/InkingControl"; import { Utils } from "../../../Utils"; @@ -15,6 +15,8 @@ import { DocServer } from "../../DocServer"; export class YoutubeBox extends React.Component { @observable YoutubeSearchElement: HTMLInputElement | undefined; + @observable searchResultsFound: boolean = false; + @observable searchResults: any[] = []; public static LayoutString() { return FieldView.LayoutString(YoutubeBox); } @@ -46,16 +48,38 @@ export class YoutubeBox extends React.Component { console.log(submittedTitle); this.YoutubeSearchElement!.value = ""; this.YoutubeSearchElement!.blur(); - DocServer.getYoutubeVideos(submittedTitle); + DocServer.getYoutubeVideos(submittedTitle, this.processesVideoResults); } } + @action + processesVideoResults = (videos: any[]) => { + this.searchResults = videos; + console.log("Callback got called"); + if (this.searchResults.length > 0) { + this.searchResultsFound = true; + } + } + + renderSearchResults = () => { + if (this.searchResultsFound) { + return
    + {this.searchResults.map((video) => { + return
  • {video.snippet.title}
  • ; + })} +
; + } else { + return (null); + } + } + render() { let field = this.props.Document[this.props.fieldKey]; let content =
this.YoutubeSearchElement = e!} /> + {this.renderSearchResults()}
; let frozen = !this.props.isSelected() || DocumentDecorations.Instance.Interacting; -- cgit v1.2.3-70-g09d2