From ccad908657652459563835051c5a729d5e15725e Mon Sep 17 00:00:00 2001 From: Fredrik Bolmsten Date: Tue, 19 Mar 2019 13:45:42 +0100 Subject: [PATCH 1/4] Add buttons for hiding logbookstree and logbook --- frontend/src/app.js | 48 +++++++++++++++++++++++++++++++------ frontend/src/entry.js | 12 ++++++++++ frontend/src/logbook.css | 4 ++++ frontend/src/logbook.js | 11 ++++++++- frontend/src/logbooktree.js | 8 +++++++ 5 files changed, 75 insertions(+), 8 deletions(-) diff --git a/frontend/src/app.js b/frontend/src/app.js index 93c7223..d8c19a2 100644 --- a/frontend/src/app.js +++ b/frontend/src/app.js @@ -77,14 +77,47 @@ class NoEntry extends React.Component { ); } } +class Elogy extends React.Component { -const Elogy = () => ( + constructor() { + super(); + this.state = { + hideLogbookTree: false, + hideLogbook: false + }; + this._hideLogbookTree = this._hideLogbookTree.bind(this); + this._hideLogbook = this._hideLogbook.bind(this); + } + + componentDidMount() { + eventbus.subscribe("logbooktree.hide", this._hideLogbookTree); + eventbus.subscribe("logbook.hide", this._hideLogbook); + } + + componentWillUnmount() { + eventbus.unsubscribe("logbooktree.hide", this._hideLogbookTree); + eventbus.unsubscribe("logbook.hide", this._hideLogbook); + } + + _hideLogbookTree(hide) { + this.setState({hideLogbookTree: hide}); + } + + _hideLogbook(hide) { + console.log("called"); + this.setState({hideLogbook: hide}); + } + + render() { + const EntryWithEventbus = withProps(Entry, { "eventbus": eventbus, "hideLogbookTree": this.state.hideLogbookTree, "hideLogbook": this.state.hideLogbook }); + + return ( /* Set up a browser router that will render the correct component in the right places, all depending on the current URL. */
-
+ {!this.state.hideLogbookTree ?
( /> -
+
: null} -
+ {!this.state.hideLogbook ?
( /> -
+
: null}
@@ -128,7 +161,7 @@ const Elogy = () => ( (
); - +} +} export default Elogy; diff --git a/frontend/src/entry.js b/frontend/src/entry.js index 4b99858..7d7bdea 100644 --- a/frontend/src/entry.js +++ b/frontend/src/entry.js @@ -253,6 +253,18 @@ class Entry extends React.Component {
{this.state.logbook ? ( + {this.props.hideLogbookTree && + + this.props.eventbus.publish("logbooktree.hide", false)}>Show logbooks +  |  + + } + {this.props.hideLogbook && + + this.props.eventbus.publish("logbook.hide", false)}>Show logbook +  |  + + } {this.state.follows ? ( {logbook.id === 0 ? "[All logbooks]" : logbook.name} - +
+ + this.hide()}/> + +   +
{logbook.id ? ( diff --git a/frontend/src/logbooktree.js b/frontend/src/logbooktree.js index ab2d696..6d5eb62 100644 --- a/frontend/src/logbooktree.js +++ b/frontend/src/logbooktree.js @@ -106,6 +106,10 @@ class LogbookTree extends React.Component { this.props.eventbus.unsubscribe("logbook.reload", this._reload); } + hide(){ + this.props.eventbus.publish("logbooktree.hide", true); + } + reload() { console.log("reload logbook tree"); this.fetch(this.props.location.search); @@ -148,6 +152,10 @@ class LogbookTree extends React.Component {
+ + this.hide()}/> + +   {logbookId !== this.state.id ? ( Date: Tue, 19 Mar 2019 13:46:28 +0100 Subject: [PATCH 2/4] remove log --- frontend/src/app.js | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/app.js b/frontend/src/app.js index d8c19a2..648193b 100644 --- a/frontend/src/app.js +++ b/frontend/src/app.js @@ -104,7 +104,6 @@ class Elogy extends React.Component { } _hideLogbook(hide) { - console.log("called"); this.setState({hideLogbook: hide}); } From d683ec4ad8b9463a51e5c6e6427db391885ffd7f Mon Sep 17 00:00:00 2001 From: Fredrik Bolmsten Date: Tue, 19 Mar 2019 15:47:19 +0100 Subject: [PATCH 3/4] Added button to noentry for showing logbooktree and logbook --- frontend/src/app.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/frontend/src/app.js b/frontend/src/app.js index 648193b..a90cf49 100644 --- a/frontend/src/app.js +++ b/frontend/src/app.js @@ -58,8 +58,22 @@ class NoEntry extends React.Component { console.log(this.props.match.location); return (
- Select an entry to read it - {logbookId ? ( +
+ {this.props.hideLogbookTree && + + this.props.eventbus.publish("logbooktree.hide", false)}>Show logbooks + + + } + {this.props.hideLogbookTree && this.props.hideLogbook &&  |  } + {this.props.hideLogbook && + + this.props.eventbus.publish("logbook.hide", false)}>Show logbook + + } +
+ {!this.props.hideLogbook && Select an entry to read it } + {logbookId && !this.props.hideLogbook ? (
{" "} or{" "} @@ -72,6 +86,7 @@ class NoEntry extends React.Component { click here to make a new entry.
+ ) : null}
); @@ -109,6 +124,7 @@ class Elogy extends React.Component { render() { const EntryWithEventbus = withProps(Entry, { "eventbus": eventbus, "hideLogbookTree": this.state.hideLogbookTree, "hideLogbook": this.state.hideLogbook }); + const NoEntryWithEventbus = withProps(NoEntry, { "eventbus": eventbus, "hideLogbookTree": this.state.hideLogbookTree, "hideLogbook": this.state.hideLogbook }); return ( /* Set up a browser router that will render the correct component @@ -172,7 +188,7 @@ class Elogy extends React.Component { component={LogbookEditorWithEventbus} /> - +
From ab6b7b41a986677d06f0f3415b286999d804ba30 Mon Sep 17 00:00:00 2001 From: Fredrik Bolmsten Date: Tue, 19 Mar 2019 15:47:45 +0100 Subject: [PATCH 4/4] fix indent and clean uo --- frontend/src/app.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/frontend/src/app.js b/frontend/src/app.js index a90cf49..d165a01 100644 --- a/frontend/src/app.js +++ b/frontend/src/app.js @@ -55,25 +55,26 @@ class NoEntry extends React.Component { render() { const logbookId = parseInt(this.props.match.params.logbookId); + const {hideLogbook, hideLogbookTree, eventbus} = this.props; console.log(this.props.match.location); return (
- {this.props.hideLogbookTree && - - this.props.eventbus.publish("logbooktree.hide", false)}>Show logbooks - - - } - {this.props.hideLogbookTree && this.props.hideLogbook &&  |  } - {this.props.hideLogbook && - - this.props.eventbus.publish("logbook.hide", false)}>Show logbook - - } + {hideLogbookTree && + + eventbus.publish("logbooktree.hide", false)}>Show logbooks + + + } + {hideLogbookTree && hideLogbook &&  |  } + {hideLogbook && + + eventbus.publish("logbook.hide", false)}>Show logbook + + }
- {!this.props.hideLogbook && Select an entry to read it } - {logbookId && !this.props.hideLogbook ? ( + {!hideLogbook && Select an entry to read it } + {logbookId && !hideLogbook ? (
{" "} or{" "}