Skip to content

Commit e55b05f

Browse files
committed
add notes widget
1 parent b70ea59 commit e55b05f

File tree

5 files changed

+94
-5
lines changed

5 files changed

+94
-5
lines changed

app/scripts/config/rdb-config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ var widgetsB = [
4646
{
4747
type: 'barchart',
4848
properties: {
49-
data: getRandomData(50)
49+
data: getRandomData(15)
5050
}
5151
},
5252
{
5353
type: 'linechart',
5454
properties: {
55-
data: getRandomData(100)
55+
data: getRandomData(75)
5656
}
5757
},
5858
{
5959
type: 'barchart',
6060
properties: {
61-
data: getRandomData(78)
61+
data: getRandomData(30)
6262
}
6363
}
6464
];

app/scripts/widgets/notes/index.jsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
var React = require('react');
22
var BaseWidget = require('BaseWidget');
3-
3+
4+
var Note = require('./note.js');
5+
var NotesStore = require('./notesStore.js');
6+
var NotesActions = require('./notesActions.js');
7+
48
var Widget = React.createClass({
59

610
getDefaultProps: function(){
@@ -12,6 +16,20 @@ var Widget = React.createClass({
1216
propTypes: {
1317
data: React.PropTypes.array
1418
},
19+
20+
componentDidMount: function(){
21+
this.unsubscribe = NotesStore.listen(this.onStatusChange);
22+
23+
NotesActions.getNotes();
24+
},
25+
26+
conponentWillUnmount: function(){
27+
this.unsubscribe();
28+
},
29+
30+
onStatusChange: function(state){
31+
this.setState(state);
32+
},
1533

1634
render: function() {
1735

@@ -20,7 +38,7 @@ var Widget = React.createClass({
2038
return <Note {...note}/>;
2139
}),
2240
widget = (
23-
<div className="rdb-widget">
41+
<div className="rdb-widget rdb-widget-notes">
2442
<ul>
2543
{ notes }
2644
</ul>

app/scripts/widgets/notes/note.jsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var React = require('react/addons');
2+
var cx = React.addons.classSet;
3+
4+
var Note = React.createClass({
5+
6+
render: function(){
7+
var classes = cx({
8+
'done': this.props.isDone,
9+
'rdb-widget-notes-note' : true
10+
});
11+
12+
return (
13+
<div className={classes}>
14+
<div><div>
15+
{ this.props.text }
16+
</div>
17+
);
18+
}
19+
20+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var Reflux = require('reflux');
2+
3+
var NotesActions = Reflux.createActions([
4+
'getNotes',
5+
'addNote'
6+
]);
7+
8+
module.exports = NotesActions;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
var Reflux = require('reflux');
2+
var store = require('store');
3+
4+
var NotesActions = require('./notesActions');
5+
6+
var Store = Reflux.createStore({
7+
8+
init : function(){
9+
this.notes = [];
10+
11+
this.listenTo(NotesActions.getNotes,this.getNotes);
12+
this.listenTo(NotesActions.addNote,this.addNote);
13+
},
14+
15+
getNotes: function(){
16+
17+
this.notes = store.get('notes') || [];
18+
19+
this.trigger({
20+
data: this.notes
21+
});
22+
},
23+
24+
addNote: function(note){
25+
26+
this.notes = store.get('notes') || [];
27+
this.notes.push(note);
28+
29+
store.set('notes', this.notes);
30+
31+
this.trigger({
32+
data: this.notes
33+
});
34+
35+
},
36+
37+
removeNote: function(){
38+
39+
}
40+
41+
});
42+
43+
module.exports = Store;

0 commit comments

Comments
 (0)