diff options
author | madelinegr <monika_hedman@brown.edu> | 2019-06-18 14:32:08 -0400 |
---|---|---|
committer | madelinegr <monika_hedman@brown.edu> | 2019-06-18 14:32:08 -0400 |
commit | d01a7faa6ec2ad2437d1d80e9a5e81c30762868b (patch) | |
tree | d873b5db7d1eb2cfc701bce151fac835a8a0b977 /src | |
parent | 15d8c7542e506767e2af72686a3703d0450fe44f (diff) |
big changes coming
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/search/IconBar.tsx | 37 | ||||
-rw-r--r-- | src/client/views/search/IconButton.tsx | 46 |
2 files changed, 59 insertions, 24 deletions
diff --git a/src/client/views/search/IconBar.tsx b/src/client/views/search/IconBar.tsx index 52eba8027..fca6c01d7 100644 --- a/src/client/views/search/IconBar.tsx +++ b/src/client/views/search/IconBar.tsx @@ -40,8 +40,10 @@ export class IconBar extends React.Component<IconBarProps> { allIcons: string[] = [DocTypes.AUDIO, DocTypes.COL, DocTypes.HIST, DocTypes.IMG, DocTypes.LINK, DocTypes.PDF, DocTypes.TEXT, DocTypes.VID, DocTypes.WEB]; @observable typesToFind: string[]; + @observable selectedItems: string[] = []; @observable public ResetClicked: boolean = false; public Reset: number = 0; + @observable activeType = "none"; constructor(props: IconBarProps) { super(props); @@ -50,11 +52,6 @@ export class IconBar extends React.Component<IconBarProps> { } @action.bound - onClick = (value: string) => { - console.log("hello!") - } - - @action.bound getList = (): string[] => { return this.typesToFind; } @@ -65,9 +62,33 @@ export class IconBar extends React.Component<IconBarProps> { } @action.bound - resetSelf() { - this.ResetClicked = true; + resetSelf = () => { + // this.ResetClicked = true; this.typesToFind = this.allIcons; + this.selectedItems = []; + this.activeType = "none"; + console.log("resetting") + } + + @action.bound + getActiveType() { + return this.activeType; + } + + @action.bound + updateActiveType(type: string) { + this.resetSelf(); + this.activeType = type; + } + + @action.bound + updateSelectedList(type: string){ + if(this.selectedItems.indexOf(type) === -1){ + this.selectedItems.push(type); + } + else{ + _.pull(this.selectedItems, type); + } } render() { @@ -83,7 +104,7 @@ export class IconBar extends React.Component<IconBarProps> { <div className="filter-description">Clear</div> </div> {this.allIcons.map((type: string) => - <IconButton type={type} onClick={this.onClick} getList={this.getList} updateList={this.updateList} /> + <IconButton getActiveType = {this.getActiveType} updateSelectedList= {this.updateSelectedList} type={type} changeActiveType = {this.updateActiveType} active={this.selectedItems.indexOf(type) !== -1} getList={this.getList} updateList={this.updateList} /> )} </div> </div> diff --git a/src/client/views/search/IconButton.tsx b/src/client/views/search/IconButton.tsx index 9af4b3a93..129348b91 100644 --- a/src/client/views/search/IconButton.tsx +++ b/src/client/views/search/IconButton.tsx @@ -10,6 +10,7 @@ import { DocTypes } from '../../documents/Documents'; import '../globalCssVariables.scss'; import * as _ from "lodash"; import { IconBar } from './IconBar'; +import { props } from 'bluebird'; library.add(faSearch); library.add(faObjectGroup); @@ -25,19 +26,22 @@ library.add(faBan); interface IconButtonProps { type: string; - onClick(type: string): void; getList(): string[]; updateList(list: string[]): void; + updateSelectedList(type: string): void; + active: boolean; + getActiveType(): string; + changeActiveType(value: string): void; } @observer export class IconButton extends React.Component<IconButtonProps>{ - @observable isSelected: boolean = false; - @observable isAdded: boolean = false; - @observable isRemoved: boolean = false; + @observable isSelected: boolean = this.props.active; @observable removeType = false; @observable hover = false; + @observable isRemoved: boolean = (this.props.getActiveType() === "remove"); + @observable isAdded: boolean = (this.props.getActiveType() === "add"); private _reactionDisposer?: IReactionDisposer; @@ -47,11 +51,12 @@ export class IconButton extends React.Component<IconButtonProps>{ IconButton.Instance = this; } - componentDidMount() { + componentDidMount = () => { this._reactionDisposer = reaction( () => IconBar.Instance.ResetClicked, () => { if (IconBar.Instance.ResetClicked) { + console.log("running") this.reset() IconBar.Instance.Reset++; if (IconBar.Instance.Reset === 9) { @@ -59,7 +64,8 @@ export class IconButton extends React.Component<IconButtonProps>{ IconBar.Instance.ResetClicked = false; } } - } + }, + {fireImmediately: true} ) } @@ -137,13 +143,23 @@ export class IconButton extends React.Component<IconButtonProps>{ return this.isAdded; } - @action.bound - onClick() { + @action + onClick = () => { let newList: string[] = this.props.getList(); + if(this.removeType && this.props.getActiveType() !== "remove"){ + this.props.changeActiveType("remove") + // console.log("resetting") + } + else if(!this.removeType && this.props.getActiveType() !== "add"){ + this.props.changeActiveType("add"); + // console.log("resetting") + } + //if it's not already selected if (!this.isSelected) { this.isSelected = true; + console.log("changing") //if actions pertain to removal if (this.removeType) { @@ -162,7 +178,8 @@ export class IconButton extends React.Component<IconButtonProps>{ this.isRemoved = false; if (!this.isAdded) { if (newList.length === 9) { - newList = [this.props.type]; + newList = []; + newList.push(this.props.type) } else { newList.push(this.props.type); } @@ -185,14 +202,11 @@ export class IconButton extends React.Component<IconButtonProps>{ this.isRemoved = false; newList.push(this.props.type) } - - - this.isAdded = false; - this.isRemoved = false; + this.props.changeActiveType("none") } - - this.props.onClick(this.props.type); - this.props.updateList(newList); + this.props.updateList(newList) + console.log(this); + console.log(this.isAdded, this.isSelected) } selectedAdded = { |