aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/views/SearchBox.tsx87
-rw-r--r--src/client/views/SearchItem.tsx34
2 files changed, 95 insertions, 26 deletions
diff --git a/src/client/views/SearchBox.tsx b/src/client/views/SearchBox.tsx
index 0670360a2..2fd809d9e 100644
--- a/src/client/views/SearchBox.tsx
+++ b/src/client/views/SearchBox.tsx
@@ -12,6 +12,9 @@ import { actionFieldDecorator } from 'mobx/lib/internal';
// const app = express();
// import * as express from 'express';
import { Search } from '../../server/Search';
+import * as rp from 'request-promise';
+import { Document } from '../../fields/Document';
+import { SearchItem } from './SearchItem';
library.add(faSearch);
@@ -23,43 +26,74 @@ export class SearchBox extends React.Component {
@observable private _open: boolean = false;
+ @observable
+ private _results: any;
+
+ constructor(props: any) {
+ super(props);
+ let searchInput = document.getElementById("input");
+ if (searchInput) {
+ searchInput.addEventListener("keydown", this.onKeyPress)
+ }
+ }
+
+ //this is not working?????
+ @action
+ onKeyPress = (e: KeyboardEvent) => {
+ console.log('things happening')
+ //Number 13 is the "Enter" key on the keyboard
+ if (e.keyCode === 13) {
+ console.log("happi")
+ // Cancel the default action, if needed
+ e.preventDefault();
+ // Trigger the button element with a click
+ let btn = document.getElementById("submit");
+ if (btn) {
+ console.log("yesyesyes")
+ btn.click();
+ }
+ }
+ }
+
@action.bound
onChange(e: React.ChangeEvent<HTMLInputElement>) {
this.searchString = e.target.value;
+ };
- }
-
- submitSearch = () => {
- // Utils.EmitCallback(Server.Socket, MessageStore.SearchFor, this.searchString, (results: string[]) => {
- // for (const result of results) {
- // console.log(result);
- // //Utils.GetQueryVariable();
- // }
- // });
+ submitSearch = async () => {
let query = this.searchString;
- console.log(query);
- //something bad is happening here
- let results = Search.Instance.search(query);
- console.log(results);
-
- // app.get("/search", async (req, res) => {
- // //let query = req.query.query || "hello";
- // let query = this.searchString;
- // let results = await Search.Instance.search(query);
- // res.send(results);
- // });
+
+ let response = await rp.get('http://localhost:1050/search', {
+ qs: {
+ query
+ }
+ });
+
+ let results = JSON.parse(response);
+
+ this._results = results;
+
+ let doc = await Server.GetField(this._results[1]);
+ if (doc instanceof Document) {
+ console.log("doc");
+ console.log(doc.Title);
+ }
+
+ // console.log("results")
+ // console.log(results);
+ // console.log("type")
+ // console.log(results.type)
+ console.log(this._results);
+
+
}
@action
handleClick = (e: Event): void => {
var className = (e.target as any).className;
var id = (e.target as any).id;
- console.log(id);
- //let imgPrev = document.getElementById("img_preview");
- console.log(className);
if (className !== "filter-button" && className !== "filter-form") {
- console.log("false");
this._open = false;
}
@@ -85,12 +119,13 @@ export class SearchBox extends React.Component {
{/* <input value={this.searchString} onChange={this.onChange} />
<button onClick={this.submitSearch} /> */}
- <input value={this.searchString} onChange={this.onChange} type="text" placeholder="Search.." className="search" />
+ <input value={this.searchString} onChange={this.onChange} type="text" placeholder="Search.." className="search" id="input" />
{/* {this._items.filter(prop => prop.description.toLowerCase().indexOf(this._searchString.toLowerCase()) !== -1).
map(prop => <ContextMenuItem {...prop} key={prop.description} />)} */}
+ {/* {this._results.map(doc => <SearchItem {...doc} key={doc.Title} />)} */}
<button className="filter-button" onClick={this.toggleDisplay}> Filter </button>
- <div className="submit-search" onClick={this.submitSearch}><FontAwesomeIcon style={{ height: "100%" }} icon="search" size="lg" /></div>
+ <div className="submit-search" id="submit" onClick={this.submitSearch}><FontAwesomeIcon style={{ height: "100%" }} icon="search" size="lg" /></div>
</div>
<div className="filter-form" id="filter" style={this._open ? { display: "flex" } : { display: "none" }}>
<div className="filter-form" id="header">Filter Search Results</div>
diff --git a/src/client/views/SearchItem.tsx b/src/client/views/SearchItem.tsx
new file mode 100644
index 000000000..f030e011b
--- /dev/null
+++ b/src/client/views/SearchItem.tsx
@@ -0,0 +1,34 @@
+import React = require("react");
+import { Document } from "../../fields/Document";
+
+export interface SearchProps {
+ doc: Document;
+ //description: string;
+ //event: (e: React.MouseEvent<HTMLDivElement>) => void;
+}
+
+// export interface SubmenuProps {
+// description: string;
+// subitems: ContextMenuProps[];
+// }
+
+// export interface ContextMenuItemProps {
+// type: ContextMenuProps | SubmenuProps;
+// }
+
+
+
+export class SearchItem extends React.Component<SearchProps> {
+
+ onClick = () => {
+ console.log("clicked search item");
+ };
+
+ render() {
+ return (
+ <div className="search-item" onClick={this.onClick}>
+ <div className="search-title">{this.props.doc.Title}</div>
+ </div>
+ );
+ }
+} \ No newline at end of file