aboutsummaryrefslogtreecommitdiff
path: root/src/client/apis/youtube/YoutubeBox.tsx
diff options
context:
space:
mode:
authorMohammad Amoush <mohammad_amoush@brown.edu>2019-06-27 12:55:31 -0400
committerMohammad Amoush <mohammad_amoush@brown.edu>2019-06-27 12:55:31 -0400
commitf31c0d97f9f59371d90d1396469aa9569933fb0d (patch)
tree5a64328ef6361bda1237e5588db395d698f1f210 /src/client/apis/youtube/YoutubeBox.tsx
parent21bc14319013e4757ca24f56a685b7d75eaa259a (diff)
Youtube Results Showing as List Implemented
Diffstat (limited to 'src/client/apis/youtube/YoutubeBox.tsx')
-rw-r--r--src/client/apis/youtube/YoutubeBox.tsx28
1 files changed, 26 insertions, 2 deletions
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<FieldViewProps> {
@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<FieldViewProps> {
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 <ul>
+ {this.searchResults.map((video) => {
+ return <li key={video.id.videoId}>{video.snippet.title}</li>;
+ })}
+ </ul>;
+ } else {
+ return (null);
+ }
+ }
+
render() {
let field = this.props.Document[this.props.fieldKey];
let content =
<div style={{ width: "100%", height: "100%", position: "absolute" }} onWheel={this.onPostWheel} onPointerDown={this.onPostPointer} onPointerMove={this.onPostPointer} onPointerUp={this.onPostPointer}>
<input type="text" placeholder="Search for a video" onKeyDown={this.onEnterKeyDown} style={{ width: "100%", border: "1px solid black", padding: 5, textAlign: "center" }} ref={(e) => this.YoutubeSearchElement = e!} />
+ {this.renderSearchResults()}
</div>;
let frozen = !this.props.isSelected() || DocumentDecorations.Instance.Interacting;