This repository has been archived by the owner on Jun 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.tsx
168 lines (151 loc) · 4.64 KB
/
index.tsx
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import React from "react";
import { Link, withRouter } from 'react-router-dom'
import PapperEV from "../PapperEV";
import { IReview } from "../Firebase/interface";
import * as ROUTES from "../../constants/routes";
import { AddReviewIcon, ReadIcon, ToReadIcon, PinIcon, TrashIcon } from '../../assets/icons';
interface IMenuBarButtonActivations {
readButton: boolean;
toReadButton: boolean;
pinnedButton: boolean;
trashButton: boolean;
}
const IMenuBarButtonActivationsInit: IMenuBarButtonActivations = {
readButton: false,
toReadButton: false,
pinnedButton: false,
trashButton: false
}
interface IModalState {
modalShow : boolean;
}
const menu = (pathname: string) => {
switch (pathname) {
case ROUTES.READ:
return "readButton";
case ROUTES.TO_READ:
return "toReadButton";
case ROUTES.PINNED:
return "pinnedButton";
case ROUTES.DELETED:
return "trashButton";
default:
return "default";
}
}
class MenuBar extends React.Component<any, IMenuBarButtonActivations & IModalState> {
constructor(props: any) {
super(props);
this.state = {
...IMenuBarButtonActivationsInit,
[menu(this.props.location.pathname)]: true,
modalShow : false
}
}
componentDidUpdate(prevProps: any) {
if (this.props.history.location.pathname !== prevProps.location.pathname) {
this.setState({
...IMenuBarButtonActivationsInit,
[menu(this.props.location.pathname)]: true
})
}
}
changeColor = (event: React.MouseEvent<HTMLButtonElement>) => {
const target = event.currentTarget;
this.setState(() => ({
...IMenuBarButtonActivationsInit,
[target.name]: true
}));
}
showPapperView = () => {
this.setState(prevState => ({
modalShow: !prevState.modalShow,
}));
}
render() {
const {
readButton,
toReadButton,
pinnedButton,
trashButton
} = this.state;
const setButtonID = (activation: boolean) => (
activation ? "tab_button_activeState" : "tab_button"
)
return (
<div className="component-menu-bar box">
<div className="row">
<button onClick={this.showPapperView} type="button" className="btn text-uppercase" style={{marginTop:'50px'}}>
<span><img src={AddReviewIcon} alt="addbutton"/></span>Add
</button>
</div>
{this.state.modalShow ? <PapperEV edit={true} review={{} as IReview} handleModal={this.showPapperView}/> : null}
<Link to={ROUTES.READ} style={{textDecoration:'none'}}>
<div className="row">
<button
name="readButton"
type="button"
id={setButtonID(readButton)}
className="btn text-uppercase"
onClick={this.changeColor}
>
<span>
<img src={ReadIcon} alt="addbutton" />
</span>
Read
</button>
</div>
</Link>
<Link to={ROUTES.TO_READ} style={{textDecoration:'none'}}>
<div className="row">
<button
name="toReadButton"
type="button"
id={setButtonID(toReadButton)}
className="btn text-uppercase"
onClick={this.changeColor}
>
<span>
<img src={ToReadIcon} alt="addbutton" />
</span>
To Read
</button>
</div>
</Link>
<Link to={ROUTES.PINNED} style={{textDecoration:'none'}}>
<div className="row">
<button
name="pinnedButton"
type="button"
id={setButtonID(pinnedButton)}
className="btn text-uppercase"
onClick={this.changeColor}
>
<span>
<img src={PinIcon} alt="addbutton" />
</span>
Pinned
</button>
</div>
</Link>
<Link to={ROUTES.DELETED} style={{textDecoration:'none'}}>
<div className="row">
<button
name="trashButton"
type="button"
id={setButtonID(trashButton)}
className="btn text-uppercase"
onClick={this.changeColor}
>
<span>
<img src={TrashIcon} alt="addbutton" />
</span>
Deleted
</button>
</div>
</Link>
</div>
);
}
}
export default withRouter(MenuBar);