Skip to content

Commit a5cd711

Browse files
committed
Add updateNotes context function for spectacle-code-slide
1 parent 3c8843e commit a5cd711

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

src/components/presenter.js

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,33 @@ const startTime = function startTime(date) {
1616

1717
@Radium
1818
export default class Presenter extends Component {
19-
constructor() {
19+
static childContextTypes = {
20+
updateNotes: PropTypes.func
21+
};
22+
23+
getChildContext() {
24+
return {
25+
updateNotes: this.updateNotes.bind(this)
26+
};
27+
}
28+
29+
getCurrentSlide() {
30+
return this.context.store.getState().route.slide;
31+
}
32+
33+
updateNotes(newNotes) {
34+
var notes = Object.assign({}, this.state.notes);
35+
notes[this.getCurrentSlide()] = newNotes;
36+
37+
this.setState({
38+
notes: notes
39+
});
40+
}
41+
42+
constructor(props) {
2043
super();
2144
this.state = {
45+
notes: {},
2246
time: startTime(new Date())
2347
};
2448
}
@@ -80,12 +104,22 @@ export default class Presenter extends Component {
80104
}) : <h1 style={[endStyle]}>END</h1>;
81105
}
82106
_renderNotes() {
83-
const child = this.props.slides[this.props.slide];
84-
if (!child.props.notes) { return false; }
85-
if (typeof child.props.notes === "string") {
86-
return <div dangerouslySetInnerHTML={{__html: child.props.notes}} />;
107+
var notes;
108+
var currentSlide = this.getCurrentSlide();
109+
110+
if (this.state.notes[currentSlide]) {
111+
notes = this.state.notes[currentSlide];
112+
} else {
113+
const child = this.props.slides[this.props.slide];
114+
notes = child.props.notes;
115+
}
116+
117+
if (!notes) { return false; }
118+
119+
if (typeof notes === "string") {
120+
return <div dangerouslySetInnerHTML={{__html: notes}} />;
87121
}
88-
return <div>{child.props.notes}</div>;
122+
return <div>{notes}</div>;
89123
}
90124
render() {
91125
const styles = {
@@ -198,5 +232,6 @@ Presenter.propTypes = {
198232
};
199233

200234
Presenter.contextTypes = {
201-
styles: PropTypes.object
235+
styles: PropTypes.object,
236+
store: PropTypes.object.isRequired,
202237
};

0 commit comments

Comments
 (0)