Skip to content

Commit

Permalink
update after merge and handle localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
wcastand committed Apr 5, 2017
1 parent 013b0dc commit c14a6fa
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/modules/ui/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ const onDragEnd = function () {
document.body.classList.remove('dragging');
};

const saveHeightPanel = h => {
try {
localStorage.setItem('splitPos', h);
return true;
} catch (e) {
return false;
}
};

const getSavedHeight = h => {
try {
return localStorage.getItem('splitPos');
} catch (e) {
return h;
}
};

class Layout extends React.Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -124,12 +141,8 @@ class Layout extends React.Component {
downPanelDefaultSize = downPanelInRight ? 400 : 200;
}

if(typeof localStorage !== 'undefined') {
const savedSize = localStorage.getItem('splitPos');
if(typeof savedSize !== 'undefined') {
downPanelDefaultSize = savedSize;
}
}
// Get the value from localStorage or user downPanelDefaultSize
downPanelDefaultSize = getSavedHeight(downPanelDefaultSize);

return (
<div style={rootStyle}>
Expand All @@ -154,7 +167,12 @@ class Layout extends React.Component {
resizerChildren={downPanelInRight ? vsplit : hsplit}
onDragStarted={onDragStart}
onDragFinished={onDragEnd}
onChange={this.onResize}
onChange={
size => {
saveHeightPanel(size);
this.onResize();
}
}
>
<div style={contentPanelStyle}>
<div
Expand Down

0 comments on commit c14a6fa

Please sign in to comment.