aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/search/Pager.tsx
blob: 9bcfb1676e03737f2013a06a9fbce0bdd2b1a04c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import * as React from 'react';
import { observer } from 'mobx-react';
import { faArrowCircleRight, faArrowCircleLeft } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { library } from '@fortawesome/fontawesome-svg-core';
import "./Pager.scss";
import { SearchBox } from './SearchBox';
import { observable, action } from 'mobx';
import { FilterBox } from './FilterBox';

library.add(faArrowCircleRight);
library.add(faArrowCircleLeft);

@observer
export class Pager extends React.Component {

    @observable _leftHover: boolean = false;
    @observable _rightHover: boolean = false;

    @action
    onLeftClick(e: React.PointerEvent) {
        FilterBox.Instance._pointerTime = e.timeStamp;
        if (SearchBox.Instance._pageNum > 0) {
            SearchBox.Instance._pageNum -= 1;
        }
    }

    @action
    onRightClick(e: React.PointerEvent) {
        FilterBox.Instance._pointerTime = e.timeStamp;
        if (SearchBox.Instance._pageNum + 1 < SearchBox.Instance._maxNum) {
            SearchBox.Instance._pageNum += 1;
        }
    }

    @action.bound
    mouseInLeft() {
        this._leftHover = true;
    }

    @action.bound
    mouseOutLeft() {
        this._leftHover = false;
    }

    @action.bound
    mouseInRight() {
        this._rightHover = true;
    }

    @action.bound
    mouseOutRight() {
        this._rightHover = false;
    }

    render() {
        return (
            <div className="search-pager">
                <div className="search-arrows">
                    <div className = "arrow"
                    onPointerDown = {this.onLeftClick} style = {SearchBox.Instance._pageNum === 0 ? {opacity: .2} : this._leftHover ? {opacity: 1} : {opacity: .7}}
                    onMouseEnter = {this.mouseInLeft} onMouseLeave = {this.mouseOutLeft}>
                        <FontAwesomeIcon className="fontawesome-icon" icon={faArrowCircleLeft} />
                    </div>
                    <div className="pager-title">
                        page {SearchBox.Instance._pageNum + 1} of {SearchBox.Instance._maxNum}
                    </div>
                    <div className = "arrow"
                    onPointerDown = {this.onRightClick} style = {SearchBox.Instance._pageNum === SearchBox.Instance._maxNum-1 ? {opacity: .2} : this._rightHover ? {opacity: 1} : {opacity: .7}}
                    onMouseEnter = {this.mouseInRight} onMouseLeave = {this.mouseOutRight}>
                        <FontAwesomeIcon className="fontawesome-icon" icon={faArrowCircleRight} />
                    </div>
                </div>
            </div>
        );
    }

}