aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonika Hedman <monika_hedman@brown.edu>2019-05-07 13:11:13 -0400
committerMonika Hedman <monika_hedman@brown.edu>2019-05-07 13:11:13 -0400
commitc3e613aebc056fd75bb1a5b3ac95f2367532b098 (patch)
tree70f8cbf5d2f6aaf7359886f4fa4a06d27fbd3e2d
parent364396d9062381d72c618c5b9931267c6cc55c97 (diff)
type issues??
-rw-r--r--src/client/views/SearchBox.tsx87
-rw-r--r--src/client/views/SearchItem.tsx2
2 files changed, 56 insertions, 33 deletions
diff --git a/src/client/views/SearchBox.tsx b/src/client/views/SearchBox.tsx
index 2fd809d9e..eb3cd56fd 100644
--- a/src/client/views/SearchBox.tsx
+++ b/src/client/views/SearchBox.tsx
@@ -15,6 +15,7 @@ import { Search } from '../../server/Search';
import * as rp from 'request-promise';
import { Document } from '../../fields/Document';
import { SearchItem } from './SearchItem';
+import { isString } from 'util';
library.add(faSearch);
@@ -26,40 +27,41 @@ 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();
- }
- }
- }
+ //@observable
+ private _results: Document[] = [];
+
+ // 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;
- };
+ }
+ //@action
submitSearch = async () => {
let query = this.searchString;
@@ -74,17 +76,38 @@ export class SearchBox extends React.Component {
this._results = results;
- let doc = await Server.GetField(this._results[1]);
+ let doc = await Server.GetField(results[1]);
if (doc instanceof Document) {
console.log("doc");
console.log(doc.Title);
}
+ // weird things happening
// console.log("results")
// console.log(results);
// console.log("type")
// console.log(results.type)
- console.log(this._results);
+ let temp: string = this._results[1].Id;
+ // console.log(this._results)
+ // console.log(this._results[1])
+
+ console.log(this._results[1].constructor.name)
+
+ if (this._results[1] instanceof Document) {
+ console.log("is a doc")
+ }
+
+ if (this._results[1]) {
+ console.log("is a string")
+ }
+
+ console.log(temp);
+ let doc2 = await Server.GetField(temp);
+ console.log(doc2);
+ if (doc2 instanceof Document) {
+ console.log("doc2");
+ console.log(doc2.Title);
+ }
}
@@ -122,7 +145,7 @@ export class SearchBox extends React.Component {
<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} />)} */}
+ {this._results.map(doc => <SearchItem {...doc} key={doc.Title} />)}
<button className="filter-button" onClick={this.toggleDisplay}> Filter </button>
<div className="submit-search" id="submit" onClick={this.submitSearch}><FontAwesomeIcon style={{ height: "100%" }} icon="search" size="lg" /></div>
diff --git a/src/client/views/SearchItem.tsx b/src/client/views/SearchItem.tsx
index f030e011b..c8fd6457b 100644
--- a/src/client/views/SearchItem.tsx
+++ b/src/client/views/SearchItem.tsx
@@ -22,7 +22,7 @@ export class SearchItem extends React.Component<SearchProps> {
onClick = () => {
console.log("clicked search item");
- };
+ }
render() {
return (