aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/DocServer.ts4
-rw-r--r--src/client/apis/youtube/YoutubeBox.tsx28
-rw-r--r--src/server/index.ts4
-rw-r--r--src/server/youtubeApi/youtubeApiSample.js5
4 files changed, 33 insertions, 8 deletions
diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts
index 65d662ebc..4fb8b8b7b 100644
--- a/src/client/DocServer.ts
+++ b/src/client/DocServer.ts
@@ -52,8 +52,8 @@ export namespace DocServer {
return apiKey;
}
- export function getYoutubeVideos(videoTitle: string) {
- Utils.EmitCallback(_socket, MessageStore.YoutubeApiQuery, { type: YoutubeQueryTypes.SearchVideo, userInput: videoTitle });
+ export function getYoutubeVideos(videoTitle: string, callBack: (videos: any[]) => void) {
+ Utils.EmitCallback(_socket, MessageStore.YoutubeApiQuery, { type: YoutubeQueryTypes.SearchVideo, userInput: videoTitle }, callBack);
}
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;
diff --git a/src/server/index.ts b/src/server/index.ts
index 9faeee381..9e4ad9d86 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -367,13 +367,13 @@ function GetRefFields([ids, callback]: [string[], (result?: Transferable[]) => v
Database.Instance.getDocuments(ids, callback, "newDocuments");
}
-function HandleYoutubeQuery([query, callback]: [YoutubeQueryInput, (result?: string) => void]) {
+function HandleYoutubeQuery([query, callback]: [YoutubeQueryInput, (result?: any[]) => void]) {
switch (query.type) {
case YoutubeQueryType.Channels:
YoutubeApi.authorizedGetChannel(youtubeApiKey);
break;
case YoutubeQueryType.SearchVideo:
- YoutubeApi.authorizedGetVideos(youtubeApiKey, query.userInput);
+ YoutubeApi.authorizedGetVideos(youtubeApiKey, query.userInput, callback);
}
}
diff --git a/src/server/youtubeApi/youtubeApiSample.js b/src/server/youtubeApi/youtubeApiSample.js
index cd2e89cae..e95f99015 100644
--- a/src/server/youtubeApi/youtubeApiSample.js
+++ b/src/server/youtubeApi/youtubeApiSample.js
@@ -29,8 +29,8 @@ module.exports.authorizedGetChannel = (apiKey) => {
authorize(JSON.parse(apiKey), getChannel);
}
-module.exports.authorizedGetVideos = (apiKey, userInput) => {
- authorize(JSON.parse(apiKey), getSampleVideos, { userInput: userInput });
+module.exports.authorizedGetVideos = (apiKey, userInput, callBack) => {
+ authorize(JSON.parse(apiKey), getSampleVideos, { userInput: userInput, callBack: callBack });
}
@@ -154,5 +154,6 @@ function getSampleVideos(auth, args) {
}
let videos = response.data.items;
console.log('Videos found: ' + videos[0].id.videoId, " ", videos[0].snippet.title);
+ args.callBack(videos);
});
} \ No newline at end of file