Skip to content

Commit fb3988a

Browse files
committed
fix(Todos): Fix Todos layout issues when Todos should be hidden
1 parent 41957e1 commit fb3988a

File tree

2 files changed

+45
-20
lines changed

2 files changed

+45
-20
lines changed

src/features/todos/components/TodosWebview.js

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,12 @@ class TodosWebview extends Component {
103103
intl: intlShape,
104104
};
105105

106-
resizeObserver = new window.ResizeObserver(([element]) => {
107-
const bounds = element.target.getBoundingClientRect();
108-
109-
ipcRenderer.send(RESIZE_TODO_VIEW, {
110-
width: bounds.width,
111-
height: bounds.height,
112-
x: bounds.x,
113-
y: element.target.offsetTop,
114-
});
106+
resizeObserver = new window.ResizeObserver(() => {
107+
this.resizeBrowserView();
115108
});
116109

110+
todosContainerRef = React.createRef()
111+
117112
componentWillMount() {
118113
const { width } = this.props;
119114

@@ -123,19 +118,21 @@ class TodosWebview extends Component {
123118
}
124119

125120
componentDidMount() {
126-
this.node.addEventListener('mousemove', this.resizePanel.bind(this));
127-
this.node.addEventListener('mouseup', this.stopResize.bind(this));
128-
this.node.addEventListener('mouseleave', this.stopResize.bind(this));
121+
this.todosContainerRef.current.addEventListener('mousemove', this.resizePanel.bind(this));
122+
this.todosContainerRef.current.addEventListener('mouseup', this.stopResize.bind(this));
123+
this.todosContainerRef.current.addEventListener('mouseleave', this.stopResize.bind(this));
129124

130-
this.resizeObserver.observe(this.node);
125+
this.resizeObserver.observe(this.todosContainerRef.current);
131126

132-
const bounds = this.node.getBoundingClientRect();
127+
this.resizeBrowserView();
128+
}
133129

130+
componentWillUnmount() {
134131
ipcRenderer.send(RESIZE_TODO_VIEW, {
135-
width: bounds.width,
136-
height: bounds.height,
137-
x: bounds.x,
138-
y: bounds.y,
132+
width: 0,
133+
height: 0,
134+
x: 0,
135+
y: 0,
139136
});
140137
}
141138

@@ -193,6 +190,20 @@ class TodosWebview extends Component {
193190
}
194191
}
195192

193+
resizeBrowserView() {
194+
if (this.todosContainerRef.current) {
195+
const bounds = this.todosContainerRef.current.getBoundingClientRect();
196+
197+
ipcRenderer.send(RESIZE_TODO_VIEW, {
198+
width: bounds.width,
199+
height: bounds.height,
200+
x: bounds.x,
201+
y: this.todosContainerRef.current.offsetTop,
202+
});
203+
}
204+
}
205+
206+
196207
render() {
197208
const {
198209
classes,
@@ -224,7 +235,7 @@ class TodosWebview extends Component {
224235
})}
225236
style={{ width: displayedWidth }}
226237
onMouseUp={() => this.stopResize()}
227-
ref={(node) => { this.node = node; }}
238+
ref={this.todosContainerRef}
228239
id="todos-panel"
229240
>
230241
<div

src/features/todos/store.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import {
1818
} from '.';
1919
import { IPC } from './constants';
2020
import { state as delayAppState } from '../delayApp';
21-
import { TODOS_FETCH_WEB_CONTENTS_ID, TODOS_TOGGLE_DRAWER, TODOS_TOGGLE_ENABLE_TODOS } from '../../ipcChannels';
21+
import {
22+
RESIZE_TODO_VIEW, TODOS_FETCH_WEB_CONTENTS_ID, TODOS_TOGGLE_DRAWER, TODOS_TOGGLE_ENABLE_TODOS,
23+
} from '../../ipcChannels';
2224
import { sleep } from '../../helpers/async-helpers';
2325

2426
const debug = require('debug')('Franz:feature:todos:store');
@@ -101,6 +103,7 @@ export default class TodoStore extends FeatureStore {
101103
this._updateTodosConfig,
102104
this._firstLaunchReaction,
103105
this._routeCheckReaction,
106+
this._hideTodosBrowserView,
104107
]);
105108

106109
this._registerReactions(this._allReactions);
@@ -284,4 +287,15 @@ export default class TodoStore extends FeatureStore {
284287
}
285288
}
286289
}
290+
291+
_hideTodosBrowserView = () => {
292+
if (this.isTodosPanelForceHidden) {
293+
ipcRenderer.send(RESIZE_TODO_VIEW, {
294+
width: 0,
295+
height: 0,
296+
x: 0,
297+
y: 0,
298+
});
299+
}
300+
}
287301
}

0 commit comments

Comments
 (0)