-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathProposals.js
More file actions
181 lines (156 loc) · 6.45 KB
/
Proposals.js
File metadata and controls
181 lines (156 loc) · 6.45 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
import React, {Component} from "react";
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import moment from 'moment';
import classNames from 'classnames'
import marked from 'marked'
import {fetchCurrentProposal, proposalDeadlineReached, authorize} from '../Actions/ProposalsActions';
import Container from '../../Layout/Components/Container/Container';
import Content from '../../Layout/Components/Content/Content';
import CommentBoxFormContainer from '../Containers/CommentBoxContainer/CommentBoxFormContainer';
import Countdown from '../../Common/Components/Countdown';
import {changePageTitle} from '../../Layout/Actions/LayoutActions';
class Proposals extends Component {
constructor(props) {
super(props);
this.deadline = this.deadline.bind(this);
this.login = this.login.bind(this);
this.logout = this.logout.bind(this);
this.getAuthorizedUser = this.getAuthorizedUser.bind(this);
this.state = {
authorizedUser: null,
ready: false
}
}
componentWillMount() {
const {title} = Proposals.getPageMeta();
this.props.changePageTitle(title);
}
componentWillReceiveProps(nextProps) {
if (nextProps.user && this.state.authorizedUser) {
this.setState({ready: true})
}
}
componentDidMount() {
this.getAuthorizedUser();
}
static getPageMeta() {
return {
title: `Request for Comment | Data Skeptic`
}
}
login() {
window.location.href = '/api/v1/auth/login/google/'
}
logout(){
window.location.href = '/api/v1/auth/logout/'
}
getAuthorizedUser() {
const {user} = this.props;
if (user && user.hasAccess) {
try {
this.setState({ authorizedUser: user })
} catch (e) {}
}
}
getMarkdown(text) {
const rawMarkup = marked(text, {sanitize: true});
return {__html: rawMarkup};
}
deadline() {
this.props.proposalDeadlineReached();
}
render() {
const {ready, authorizedUser} = this.state;
if (ready) {
const {proposal = {}, aws_proposals_bucket} = this.props;
const {topic, long_description, deadline, active} = proposal;
const to = moment(deadline);
const isClosed = !active;
const user = {
email: authorizedUser.email,
name: authorizedUser.displayName
}
return (
<div className={classNames('proposals-page', {'closed': isClosed, 'open': !isClosed})}>
<Container>
<Content>
<div class="row">
<div className="col-xs-12 col-md-8 countdown-wrapper">
{deadline ?
<p className="deadline"><b>Time to comment:</b><Countdown to={to.toString()}
onDeadlineReached={this.deadline}/>
</p>
: null}
</div>
<div className="col-xs-12 col-md-4 log-out-wrapper">
<button className="btn" onClick={this.logout}><i className="glyphicon glyphicon-arrow-left"></i>Log out</button>
</div>
</div>
<div class="row">
{!isClosed && (
<div className="col-xs-12">
<span className="rfc-title"><b>Topic:</b> {topic}</span>
<p dangerouslySetInnerHTML={this.getMarkdown(`${long_description}`)}>
</p>
</div>
)}
{isClosed
?
<div className="col-xs-12 panel panel-default">
<div className="panel-heading">
<h3 className="panel-title">The last Request For Comment has closed</h3>
</div>
<div className="panel-body">
We don't have any active topics. Please check back soon when we launch the next!
</div>
</div>
:
<CommentBoxFormContainer user={user} aws_proposals_bucket={aws_proposals_bucket}/>
}
</div>
</Content>
</Container>
</div>
)
}
else {
return (
<div className='proposals-page'>
<Container>
<div className="login-container">
<h2>Welcome to the Data Skeptic</h2>
<h3>Request For Comment System</h3>
<p>
This is the login to an invite-only browser based recording system<br/>
where you can share your thoughts on a chosen topic. Your comments<br/>
are likely to be included in a future episode of Data Skeptic.
</p>
<button onClick={this.login} className="btn btn-primary">Login</button>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
</div>
</Container>
</div>
);
}
}
}
export default connect(
state => ({
aws_proposals_bucket: state.proposals.getIn(['aws_proposals_bucket']),
proposal: state.proposals.getIn(['proposal']).toJS(),
user: state.auth.getIn(['user']).toJS()
}),
dispatch => bindActionCreators({
fetchCurrentProposal,
proposalDeadlineReached,
changePageTitle,
authorize
}, dispatch)
)(Proposals)