Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

save height of down panel in local storage #62 #74

Merged
merged 4 commits into from
Apr 5, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions dist/modules/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ exports.default = {
defaultState: {
uiOptions: {
name: 'REACT STORYBOOK',
url: 'https://github.com/storybooks/react-storybook'
url: 'https://github.com/storybooks/react-storybook',
sortStoriesByKind: false
}
},
load: function load(_ref, _actions) {
Expand All @@ -28,4 +29,4 @@ exports.default = {

(0, _init_api2.default)(provider, clientStore, _actions);
}
};
};
14 changes: 13 additions & 1 deletion dist/modules/ui/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ var Layout = function (_React$Component) {
downPanelDefaultSize = downPanelInRight ? 400 : 200;
}

if (typeof localStorage !== 'undefined') {
var savedSize = localStorage.getItem('splitPos');
if (typeof savedSize !== 'undefined') {
downPanelDefaultSize = savedSize;
}
}

return _react2.default.createElement(
'div',
{ style: rootStyle },
Expand Down Expand Up @@ -164,7 +171,12 @@ var Layout = function (_React$Component) {
defaultSize: downPanelDefaultSize,
resizerChildren: downPanelInRight ? vsplit : hsplit,
onDragStarted: onDragStart,
onDragFinished: onDragEnd
onDragFinished: onDragEnd,
onChange: function onChange(size) {
if (typeof localStorage !== 'undefined') {
localStorage.setItem('splitPos', size);
}
}
},
_react2.default.createElement(
'div',
Expand Down
2 changes: 1 addition & 1 deletion dist/modules/ui/components/left_panel/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var Header = function Header(_ref) {
),
_react2.default.createElement(
'a',
{ style: linkStyle, href: url, target: '_blank' },
{ style: linkStyle, href: url, target: '_blank', rel: 'noopener noreferrer' },
_react2.default.createElement(
'h3',
{ style: headingStyle },
Expand Down
9 changes: 6 additions & 3 deletions dist/modules/ui/containers/left_panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ var mapper = exports.mapper = function mapper(state, props, _ref) {
selectedStory = state.selectedStory,
uiOptions = state.uiOptions,
storyFilter = state.storyFilter;
var name = uiOptions.name,
url = uiOptions.url,
sortStoriesByKind = uiOptions.sortStoriesByKind;


var data = {
stories: filters.storyFilter(stories, storyFilter, selectedKind, selectedStory),
stories: filters.storyFilter(stories, storyFilter, selectedKind, sortStoriesByKind),
selectedKind: selectedKind,
selectedStory: selectedStory,
onSelectStory: actionMap.api.selectStory,
Expand All @@ -46,8 +49,8 @@ var mapper = exports.mapper = function mapper(state, props, _ref) {
onStoryFilter: actionMap.ui.setStoryFilter,

openShortcutsHelp: actionMap.ui.toggleShortcutsHelp,
name: uiOptions.name,
url: uiOptions.url
name: name,
url: url
};

return data;
Expand Down
17 changes: 14 additions & 3 deletions dist/modules/ui/libs/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@ var _fuzzysearch = require('fuzzysearch');

var _fuzzysearch2 = _interopRequireDefault(_fuzzysearch);

var _lodash = require('lodash.sortby');

var _lodash2 = _interopRequireDefault(_lodash);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function storyFilter(stories, filter, selectedKind) {
function sort(stories, sortStoriesByKind) {
if (!sortStoriesByKind) return stories;

return (0, _lodash2.default)(stories, ['kind']);
}

function storyFilter(stories, filter, selectedKind, sortStoriesByKind) {
if (!stories) return null;
if (!filter) return stories;
var sorted = sort(stories, sortStoriesByKind);
if (!filter) return sorted;

return stories.filter(function (kindInfo) {
return sorted.filter(function (kindInfo) {
if (kindInfo.kind === selectedKind) return true;
var needle = filter.toLocaleLowerCase();
var hstack = kindInfo.kind.toLocaleLowerCase();
Expand Down
14 changes: 14 additions & 0 deletions src/modules/ui/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ class Layout extends React.Component {
downPanelDefaultSize = downPanelInRight ? 400 : 200;
}

if(typeof localStorage !== 'undefined') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not enough to make sure localStorage is usable. When using Safari in private mode, you'll run into issues because localStorage is defined, but the quota is set to 0, meaning that if you try to setItem, the browser will throw an error.

Pretty simple to get around though, could do something like this:

const hasLocalStorage = () => {
  try {
      localStorage.setItem('yo', 'yo')
      localStorage.removeItem('yo')
      return true
  } catch(e) {
      return false
  }
}

const savedSize = localStorage.getItem('splitPos');
if(typeof savedSize !== 'undefined') {
downPanelDefaultSize = savedSize;
}
}

return (
<div style={rootStyle}>
<SplitPane
Expand All @@ -108,6 +115,13 @@ class Layout extends React.Component {
resizerChildren={downPanelInRight ? vsplit : hsplit}
onDragStarted={onDragStart}
onDragFinished={onDragEnd}
onChange={
Copy link
Contributor

@benediktvaldez benediktvaldez Apr 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh and also this, @wcastand check out the conflict that came up due to another PR getting merged, make sure to it plays along :)

size => {
if (typeof localStorage !== 'undefined') {
localStorage.setItem('splitPos', size);
}
}
}
>
<div style={contentPanelStyle}>
<div style={previewStyle}>
Expand Down
2 changes: 1 addition & 1 deletion src/modules/ui/components/shortcuts_help.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const ShortcutsHelp = ({ isOpen, onClose, platform }) => (
isOpen = {isOpen}
onRequestClose = {onClose}
style = {modalStyles}
contentLabel = 'Shortcuts'
contentLabel = "Shortcuts"
>
<Shortcuts appShortcuts = {getShortcuts(platform)} />
</ReactModal>
Expand Down
Loading