diff options
author | Monika <monika_hedman@brown.edu> | 2019-06-19 13:48:31 -0400 |
---|---|---|
committer | Monika <monika_hedman@brown.edu> | 2019-06-19 13:48:31 -0400 |
commit | 1980d7009606bef0fb52104db0856b691c12bb9e (patch) | |
tree | e910332dfd62b27fb9209fe2d8e260dc7d6581ba | |
parent | 3e7b7ea48e8ee6b4f2059f54e7cbc81c19ef4bef (diff) |
checkboxes working and clearing
-rw-r--r-- | src/client/views/search/CheckBox.tsx | 63 | ||||
-rw-r--r-- | src/client/views/search/FieldFilters.tsx | 23 | ||||
-rw-r--r-- | src/client/views/search/SearchBox.tsx | 2 |
3 files changed, 66 insertions, 22 deletions
diff --git a/src/client/views/search/CheckBox.tsx b/src/client/views/search/CheckBox.tsx index fc1d4005e..163507ec3 100644 --- a/src/client/views/search/CheckBox.tsx +++ b/src/client/views/search/CheckBox.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; import { observer } from 'mobx-react'; -import { observable, action, runInAction } from 'mobx'; +import { observable, action, runInAction, IReactionDisposer, reaction } from 'mobx'; import "./CheckBox.scss"; import * as anime from 'animejs'; @@ -8,6 +8,8 @@ interface CheckBoxProps { originalStatus: boolean; updateStatus(newStatus: boolean): void; title: string; + parent: any; + numCount: number; } @observer @@ -17,6 +19,7 @@ export class CheckBox extends React.Component<CheckBoxProps>{ @observable uncheckTimeline: anime.AnimeTimelineInstance; @observable checkTimeline: anime.AnimeTimelineInstance; @observable checkRef: any; + @observable _resetReaction?: IReactionDisposer; constructor(props: CheckBoxProps) { @@ -28,21 +31,19 @@ export class CheckBox extends React.Component<CheckBoxProps>{ loop: false, autoplay: false, direction: "normal", - });this.uncheckTimeline = anime.timeline({ + }); this.uncheckTimeline = anime.timeline({ loop: false, autoplay: false, direction: "normal", }); } - //testiing - componentDidMount = () => { this.uncheckTimeline.add({ targets: this.checkRef.current, easing: "easeInOutQuad", duration: 500, - opacity: 0 , + opacity: 0, }); this.checkTimeline.add({ targets: this.checkRef.current, @@ -52,37 +53,63 @@ export class CheckBox extends React.Component<CheckBoxProps>{ opacity: 1 }); - if(this.props.originalStatus){ + if (this.props.originalStatus) { this.checkTimeline.play(); } + + this._resetReaction = reaction( + () => this.props.parent.resetBoolean, + () => { + if (this.props.parent.resetBoolean) { + runInAction(() => { + this.reset(); + this.props.parent.resetCounter++; + if (this.props.parent.resetCounter === this.props.numCount) { + this.props.parent.resetCounter = 0; + this.props.parent.resetCounter = false; + } + }) + } + }, + ) } @action.bound - onClick = () => { - this.props.updateStatus(!this._status); + reset() { + if (!this._status) { + this._status = true; + this.checkTimeline.play(); + this.checkTimeline.restart(); + } - if(this._status){ + } + + @action.bound + onClick = () => { + if (this._status) { this.uncheckTimeline.play(); this.uncheckTimeline.restart(); } - else{ + else { this.checkTimeline.play(); this.checkTimeline.restart(); } this._status = !this._status; + this.props.updateStatus(this._status); + } render() { return ( - <div className="checkbox" onClick = {this.onClick}> - <div className = "outer"> - <div className="check-container"> - <svg viewBox="0 12 40 40"> - <path ref = {this.checkRef} className="checkmark" d="M14.1 27.2l7.1 7.2 16.7-18" /> - </svg> - </div> - <div className="check-box"/> + <div className="checkbox" onClick={this.onClick}> + <div className="outer"> + <div className="check-container"> + <svg viewBox="0 12 40 40"> + <path ref={this.checkRef} className="checkmark" d="M14.1 27.2l7.1 7.2 16.7-18" /> + </svg> + </div> + <div className="check-box" /> </div> <div className="checkbox-title">{this.props.title}</div> </div> diff --git a/src/client/views/search/FieldFilters.tsx b/src/client/views/search/FieldFilters.tsx index e84137d69..81391e73b 100644 --- a/src/client/views/search/FieldFilters.tsx +++ b/src/client/views/search/FieldFilters.tsx @@ -16,13 +16,30 @@ export interface FieldFilterProps { } export class FieldFilters extends React.Component<FieldFilterProps> { + + static Instance: FieldFilters; + @observable public resetBoolean = false; + @observable public resetCounter: number = 0; + + constructor(props: FieldFilterProps){ + super(props); + FieldFilters.Instance = this; + } + +resetFieldFilters() { + this.props.updateAuthorStatus(true); + this.props.updateDataStatus(true); + this.props.updateTitleStatus(true); + this.resetBoolean = true; +} + render() { return ( <div> <div className="filter field-title">Filter by Basic Keys</div> - <CheckBox originalStatus={this.props.titleFieldStatus} updateStatus={this.props.updateTitleStatus} title={Keys.TITLE} /> - <CheckBox originalStatus={this.props.authorFieldStatus} updateStatus={this.props.updateAuthorStatus} title={Keys.AUTHOR} /> - <CheckBox originalStatus={this.props.dataFieldStatus} updateStatus={this.props.updateDataStatus} title={Keys.DATA} /> + <CheckBox numCount = {3} parent = {this} originalStatus={this.props.titleFieldStatus} updateStatus={this.props.updateTitleStatus} title={Keys.TITLE} /> + <CheckBox numCount = {3} parent = {this} originalStatus={this.props.authorFieldStatus} updateStatus={this.props.updateAuthorStatus} title={Keys.AUTHOR} /> + <CheckBox numCount = {3} parent = {this} originalStatus={this.props.dataFieldStatus} updateStatus={this.props.updateDataStatus} title={Keys.DATA} /> </div> ) } diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx index a25fff32d..4a0fe452a 100644 --- a/src/client/views/search/SearchBox.tsx +++ b/src/client/views/search/SearchBox.tsx @@ -72,9 +72,9 @@ export class SearchBox extends React.Component { resetFilters = () => { ToggleBar.Instance.resetToggle(); IconBar.Instance.selectAll(); + FieldFilters.Instance.resetFieldFilters(); } - @action.bound onChange(e: React.ChangeEvent<HTMLInputElement>) { this._searchString = e.target.value; |