aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/search
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2021-08-25 11:53:50 -0400
committerbobzel <zzzman@gmail.com>2021-08-25 11:53:50 -0400
commit2790d5b6c374ca24e7307b03f1fd72be7172b033 (patch)
tree3884525c8027fbba467258df884143779db3ee94 /src/client/views/search
parentfe818efd80e649b841009b69841b176cee4c5c8c (diff)
parentd88db8300f400e89d50fb42ee8d9186e147c61e7 (diff)
Merge branch 'master' of https://github.com/brown-dash/Dash-Web
Diffstat (limited to 'src/client/views/search')
-rw-r--r--src/client/views/search/SearchBox.tsx39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx
index b07879674..07186fe8d 100644
--- a/src/client/views/search/SearchBox.tsx
+++ b/src/client/views/search/SearchBox.tsx
@@ -7,23 +7,31 @@ import { Id } from '../../../fields/FieldSymbols';
import { createSchema, makeInterface } from '../../../fields/Schema';
import { StrCast } from '../../../fields/Types';
import { DocumentType } from "../../documents/DocumentTypes";
-import { DocumentManager } from "../../util/DocumentManager";
import { CollectionDockingView } from "../collections/CollectionDockingView";
import { ViewBoxBaseComponent } from "../DocComponent";
import { FieldView, FieldViewProps } from '../nodes/FieldView';
import "./SearchBox.scss";
+import { DocumentManager } from '../../util/DocumentManager';
+import { DocUtils } from '../../documents/Documents';
-export const searchSchema = createSchema({ Document: Doc });
+export const searchSchema = createSchema({
+ Document: Doc
+});
type SearchBoxDocument = makeInterface<[typeof documentSchema, typeof searchSchema]>;
const SearchBoxDocument = makeInterface(documentSchema, searchSchema);
+export interface SearchBoxProps extends FieldViewProps {
+ linkSearch: boolean;
+ linkFrom?: (() => Doc | undefined) | undefined;
+}
+
/**
* This is the SearchBox component. It represents the search box input and results in
* the search panel on the left side of the screen.
*/
@observer
-export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDocument>(SearchBoxDocument) {
+export class SearchBox extends ViewBoxBaseComponent<SearchBoxProps, SearchBoxDocument>(SearchBoxDocument) {
public static LayoutString(fieldKey: string) { return FieldView.LayoutString(SearchBox, fieldKey); }
public static Instance: SearchBox;
@@ -100,6 +108,18 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
this._selectedResult = doc;
});
+ makeLink = action((linkTo: Doc) => {
+ console.log("[makeLink-1] got here!")
+ console.log(linkTo.title);
+ if (this.props.linkFrom){
+ const linkFrom = this.props.linkFrom();
+ if (linkFrom){
+ console.log(linkFrom.title);
+ DocUtils.MakeLink({doc: linkFrom}, {doc:linkTo});
+ }
+ }
+ });
+
/**
* @param {Doc[]} docs - docs to be searched through recursively
* @param {number, Doc => void} func - function to be called on each doc
@@ -275,6 +295,9 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
render() {
var validResults = 0;
+ const isLinkSearch:boolean = this.props.linkSearch;
+
+
const results = this._results.map(result => {
var className = "searchBox-results-scroll-view-result";
@@ -285,7 +308,7 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
if (this._docTypeString == "all" || this._docTypeString == result[0].type) {
validResults++;
return (
- <div key={result[0][Id]} onClick={() => this.onResultClick(result[0])} className={className}>
+ <div key={result[0][Id]} onClick={isLinkSearch ? () => this.makeLink(result[0]) : () => this.onResultClick(result[0])} className={className}>
<div className="searchBox-result-title">
{result[0].title}
</div>
@@ -306,11 +329,11 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
return (
<div style={{ pointerEvents: "all" }} className="searchBox-container">
- <div className="searchBox-bar">
- <select name="type" id="searchBox-type" className="searchBox-type" onChange={this.onSelectChange}>
+ <div className="searchBox-bar" >
+ {isLinkSearch ? (null) : <select name="type" id="searchBox-type" className="searchBox-type" onChange={this.onSelectChange}>
{this.selectOptions}
- </select>
- <input defaultValue={""} autoComplete="off" onChange={this.onInputChange} type="text" placeholder="Search..." id="search-input" className="searchBox-input" ref={this._inputRef} />
+ </select>}
+ <input defaultValue={""} autoComplete="off" onChange={this.onInputChange} type="text" placeholder="Search..." id="search-input" className="searchBox-input" style={{width: isLinkSearch ? "100%" : undefined, borderRadius: isLinkSearch ? "5px" : undefined}} ref={this._inputRef} />
</div >
<div className="searchBox-results-container">
<div className="searchBox-results-count">