-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
96 lines (89 loc) · 2.99 KB
/
index.js
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
import React from "react";
import { deSerialize, serialize, serPreview, getSearchableText } from "./util";
import "./style.css";
const MUTATION_NAME = "DebaterNote";
const HEADERS = ["1AC", "1NC", "2AC", "2NC", "1NR", "1AR", "2NR", "2AR"];
function debaterNote(ContentView, api) {
return class extends React.Component {
finishedLoadingContent = () => {
this.props.note.getContent().then(content => {
const editorState = deSerialize(content[this.props.note.mutationName]);
this.props.onContentLoaded(editorState);
});
};
onChange = (editorState, save) => {
const serializedContent = serialize(editorState);
const serializedPreview = serPreview(editorState);
const searchableText = getSearchableText(editorState);
this.props.onChange(
editorState,
serializedContent,
serializedPreview,
searchableText,
save
);
};
onSingleChange = (state, index) => {
const editorState = this.props.ourEditorState;
editorState.editors[index] = state;
this.onChange(editorState);
};
render() {
if (this.props.note && this.props.note.mutationName === MUTATION_NAME) {
const {
onChange,
isLoadingContent,
ourEditorState,
...props
} = this.props;
const Editor = api().Editor;
const editors = this.props.ourEditorState.editors.map((col, index) => {
if (index == 0) {
return (
<div className={"d-column"} key={"editor-div" + index}>
<div className={"d-column-header"} key={"header" + index}>
{HEADERS[index]}
</div>
<Editor
key={"editor" + index}
ourEditorState={col}
onChange={editorState => {
this.onSingleChange(editorState, index);
}}
placeholder={"Type here"}
isLoadingContent={isLoadingContent}
finishedLoadingContent={this.finishedLoadingContent}
{...props}
/>
</div>
);
} else {
return (
<div
className={"d-column d-not-first-editor"}
key={"editor-div" + index}>
<div className={"d-column-header"} key={"header" + index}>
{HEADERS[index]}
</div>
<Editor
key={"editor" + index}
ourEditorState={col}
onChange={editorState => {
this.onSingleChange(editorState, index);
}}
placeholder={"Type here"}
{...props}
/>
</div>
);
}
});
return <div className="d-editor-container">{editors}</div>;
}
return <ContentView {...this.props} />;
}
};
}
module.exports.mutations = {
ContentView: debaterNote
};