-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.jsx
171 lines (147 loc) · 4.77 KB
/
index.jsx
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
'use strict'
import {findDOMNode} from 'react-dom'
import React from 'react'
import { render } from 'react-dom';
import LogtimePicker from './log-time-picker'
const onChange = (dateString, { dateMoment }) => {
console.log(dateString)
}
import { NotificationStack } from 'react-notification';
import { OrderedSet } from 'immutable';
import SlackFeedback from 'react-slack-feedback';
import $ from 'jquery';
class NotificationSystem extends React.Component {
constructor() {
super();
this.state = {
notifications: OrderedSet(),
count:1
};
this.addNotification = this.addNotification.bind(this);
this.removeNotification = this.removeNotification.bind(this);
}
addNotification() {
const newCount = this.state.count + 1;
console.log(newCount);
this.setState((prevState) => {
return {count: prevState.count + 1};
});
this.setState({
notifications: this.state.notifications.add({
message: `Lazy Loading Finish`,
key: newCount,
action: 'X',
onClick: (deactivate) => {
deactivate();
setTimeout(() => this.removeNotification(newCount), 400);
},
barStyle:{
left:'auto',
bottom:'unset',
top: '0.5rem',
right: '-100%',
padding: '1rem 1rem 1rem 1rem',
width: 'auto',
color: '#00BCD4',
font: '0.9rem normal Roboto, sans-serif',
background: 'rgba(255,255,255,0.8)',
boxShadow: '0 0 2px 2px rgba(10, 10, 11, .125)'
},
activeBarStyle:{
right: '1rem',
},
actionStyle:{
marginLeft: '4rem'
},
dismissAfter:2000
})
});
}
removeNotification(count) {
this.setState({
notifications: this.state.notifications.filter(n => n.key !== count)
})
}
render() {
console.log("rerender")
return (
<div>
<button onClick={this.addNotification}>Add</button>
<NotificationStack
notifications={this.state.notifications.toArray()}
onDismiss={notification => this.setState({
notifications: this.state.notifications.delete(notification)
})}
barStyleFactory ={(index, style) => {
return Object.assign({}, style, { top: 0.5 + index * 4 + 'rem' });
}}
activeBarStyleFactory ={(index, style) => {
return Object.assign({}, style, { top: 0.5 + index * 4 + 'rem' });
}}
/>
</div>
);
}
}
var myHeaders = new Headers();
myHeaders.append("Content-Type", "text/plain");
var data = new FormData();
data.append( "json", JSON.stringify( 'payload=' + JSON.stringify({
"text": "test"
})) );
const url ='https://hooks.slack.com/services/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'
function sendToSlack(payload) {
// $.ajax({
// data: 'payload=' + JSON.stringify({
// "text": "test"
// }),
// dataType: 'json',
// type: 'POST',
// url: url
// });
fetch(url, {
method: 'POST',
mode:'cors',
body:'payload=' + JSON.stringify({
"text": "testliurendong"
}),
headers: new Headers({
"Content-Type":"application/x-www-form-urlencoded"
})
}).then(function() { /* handle response */ });
}
function uploadImage(file) {
var form = new FormData();
form.append('image', file);
fetch('/api/upload', {
method: 'POST',
body: form
})
.then(res => {
console.log(res.status, res.statusText);
if (res.status < 200 || res.status >= 300) {
this.uploadError(res.statusText);
}
return res.json();
})
.then(url => this.imageUploaded(url));
}
var App = React.createClass({
render: function(){
let hue_time = '2015-04-24 10:38:45'
return (
<div style={{marginLeft: 500}}>
<SlackFeedback
onSubmit={sendToSlack}
onImageUpload={uploadImage}
user="Mark Murray"
emoji=":bug:"
channel="#OperationTool"
/>
<span>testing demo</span>
<LogtimePicker onChange={onChange}/>
<NotificationSystem/>
</div>)
}
})
render(<App />, document.getElementById('content'))