diff --git a/client/pages/viewerpage/org_viewer.js b/client/pages/viewerpage/org_viewer.js index a0db6447..be3a5055 100644 --- a/client/pages/viewerpage/org_viewer.js +++ b/client/pages/viewerpage/org_viewer.js @@ -31,7 +31,8 @@ class OrgViewer extends React.Component { constructor(props){ super(props); this.state = { - headlines: this.buildHeadlines(props.headlines) + headlines: this.buildHeadlines(props.headlines), + content: props.content }; } @@ -59,20 +60,11 @@ class OrgViewer extends React.Component { }); } - navigate(line){ - this.props.onQuit(); - this.props.goTo(line); - } - - onTaskUpdate(type, line, value){ - const content = this.props.content.split("\n"); + const content = this.state.content.split("\n"); switch(type){ case "status": - const [status, state] = value; - let next = "DONE"; - if(status === "DONE") next = "TODO"; - content[line] = content[line].replace(status, next); + content[line] = content[line].replace(/^(\*+\s)[A-Z]{3,}(\s.*)$/, "$1"+value+"$2"); break; case "subtask": if(value === "DONE"){ @@ -86,15 +78,25 @@ class OrgViewer extends React.Component { case "deadline": break; }; - this.props.onUpdate(content.join("\n")); + this.setState({content: content.join("\n")}); + } + + navigate(line){ + this.props.goTo(line); + this.onQuit(); + } + + onQuit(){ + this.props.onUpdate(this.state.content); + this.props.onQuit(); } render(){ return ( - +
- +

{this.props.title}

@@ -155,6 +157,7 @@ class Headline extends React.Component { constructor(props){ super(props); this.state = { + status: props.todo_status, properties: false }; } @@ -167,11 +170,24 @@ class Headline extends React.Component { } } + onStatusToggle(){ + if(!this.props.todo_status) return; + + const new_status = this.state.status === 'todo' ? 'done' : 'todo'; + this.setState({status: new_status}); + + const new_status_label = function(new_status, initial_status, initial_keyword){ + if(new_status === initial_status) return initial_keyword; + return new_status === "todo" ? "TODO" : "DONE"; + }(new_status, this.props.todo_status, this.props.status); + this.props.onTaskUpdate('status', this.props.line, new_status_label); + } + render(){ return (
-
-
+
+
{this.props.title}
@@ -206,7 +222,7 @@ class Headline extends React.Component {
- 0 && this.props.todo_status === "todo" && this.props.type === 'todos'} className="subtask_container"> + 0 && this.state.status === "todo" && this.props.type === 'todos'} className="subtask_container"> { this.props.tasks.map((task, i) => { return (