From 21bc14319013e4757ca24f56a685b7d75eaa259a Mon Sep 17 00:00:00 2001 From: Mohammad Amoush Date: Wed, 26 Jun 2019 19:15:50 -0400 Subject: Searching through document for a youtube video done --- src/client/DocServer.ts | 6 +++--- src/client/apis/youtube/YoutubeBox.tsx | 26 +++++++++++++++----------- src/server/Message.ts | 7 ++++++- src/server/index.ts | 8 ++++---- src/server/youtubeApi/youtubeApiSample.js | 12 ++++++------ 5 files changed, 34 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts index b0060bfdc..65d662ebc 100644 --- a/src/client/DocServer.ts +++ b/src/client/DocServer.ts @@ -48,12 +48,12 @@ export namespace DocServer { } export async function getYoutubeChannels() { - let apiKey = await Utils.EmitCallback(_socket, MessageStore.YoutubeApiQuery, YoutubeQueryTypes.Channels); + let apiKey = await Utils.EmitCallback(_socket, MessageStore.YoutubeApiQuery, { type: YoutubeQueryTypes.Channels }); return apiKey; } - export function getYoutubeVideos() { - Utils.EmitCallback(_socket, MessageStore.YoutubeApiQuery, YoutubeQueryTypes.SearchVideo); + export function getYoutubeVideos(videoTitle: string) { + Utils.EmitCallback(_socket, MessageStore.YoutubeApiQuery, { type: YoutubeQueryTypes.SearchVideo, userInput: videoTitle }); } diff --git a/src/client/apis/youtube/YoutubeBox.tsx b/src/client/apis/youtube/YoutubeBox.tsx index dce891a07..b044e2a05 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 } from 'mobx'; +import { computed, reaction, IReactionDisposer, observable } from 'mobx'; import { DocumentDecorations } from "../../views/DocumentDecorations"; import { InkingControl } from "../../views/InkingControl"; import { Utils } from "../../../Utils"; @@ -14,12 +14,12 @@ import { DocServer } from "../../DocServer"; @observer export class YoutubeBox extends React.Component { + @observable YoutubeSearchElement: HTMLInputElement | undefined; public static LayoutString() { return FieldView.LayoutString(YoutubeBox); } componentWillMount() { DocServer.getYoutubeChannels(); - DocServer.getYoutubeVideos(); } _ignore = 0; @@ -39,19 +39,23 @@ export class YoutubeBox extends React.Component { e.stopPropagation(); } } + + onEnterKeyDown = (e: React.KeyboardEvent) => { + if (e.keyCode === 13) { + let submittedTitle = this.YoutubeSearchElement!.value; + console.log(submittedTitle); + this.YoutubeSearchElement!.value = ""; + this.YoutubeSearchElement!.blur(); + DocServer.getYoutubeVideos(submittedTitle); + + } + } + render() { let field = this.props.Document[this.props.fieldKey]; - let view; - if (field instanceof HtmlField) { - view = ; - } else if (field instanceof WebField) { - view =