Skip to content

Commit

Permalink
UI: Store layout state in sessionStorage (#8786)
Browse files Browse the repository at this point in the history
UI: Store layout state in sessionStorage
  • Loading branch information
shilman authored Nov 12, 2019
2 parents 6455fc9 + 7841383 commit 3531f4f
Showing 1 changed file with 82 additions and 61 deletions.
143 changes: 82 additions & 61 deletions lib/api/src/modules/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,86 +157,107 @@ let hasSetOptions = false;
export default function({ store, provider }: { store: Store; provider: Provider }) {
const api = {
toggleFullscreen(toggled?: boolean) {
return store.setState((state: State) => {
const value = typeof toggled === 'boolean' ? toggled : !state.layout.isFullscreen;

return {
layout: {
...state.layout,
isFullscreen: value,
},
};
});
return store.setState(
(state: State) => {
const value = typeof toggled === 'boolean' ? toggled : !state.layout.isFullscreen;

return {
layout: {
...state.layout,
isFullscreen: value,
},
};
},
{ persistence: 'session' }
);
},

togglePanel(toggled?: boolean) {
return store.setState((state: State) => {
const value = typeof toggled !== 'undefined' ? toggled : !state.layout.showPanel;

return {
layout: {
...state.layout,
showPanel: value,
},
};
});
return store.setState(
(state: State) => {
const value = typeof toggled !== 'undefined' ? toggled : !state.layout.showPanel;

return {
layout: {
...state.layout,
showPanel: value,
},
};
},
{ persistence: 'session' }
);
},

togglePanelPosition(position?: 'bottom' | 'right') {
if (typeof position !== 'undefined') {
return store.setState((state: State) => ({
return store.setState(
(state: State) => ({
layout: {
...state.layout,
panelPosition: position,
},
}),
{ persistence: 'session' }
);
}

return store.setState(
(state: State) => ({
layout: {
...state.layout,
panelPosition: position,
panelPosition: state.layout.panelPosition === 'right' ? 'bottom' : 'right',
},
}));
}

return store.setState((state: State) => ({
layout: {
...state.layout,
panelPosition: state.layout.panelPosition === 'right' ? 'bottom' : 'right',
},
}));
}),
{ persistence: 'session' }
);
},

toggleNav(toggled?: boolean) {
return store.setState((state: State) => {
const value = typeof toggled !== 'undefined' ? toggled : !state.layout.showNav;

return {
layout: {
...state.layout,
showNav: value,
},
};
});
return store.setState(
(state: State) => {
const value = typeof toggled !== 'undefined' ? toggled : !state.layout.showNav;

return {
layout: {
...state.layout,
showNav: value,
},
};
},
{ persistence: 'session' }
);
},

toggleToolbar(toggled?: boolean) {
return store.setState((state: State) => {
const value = typeof toggled !== 'undefined' ? toggled : !state.layout.isToolshown;

return {
layout: {
...state.layout,
isToolshown: value,
},
};
});
return store.setState(
(state: State) => {
const value = typeof toggled !== 'undefined' ? toggled : !state.layout.isToolshown;

return {
layout: {
...state.layout,
isToolshown: value,
},
};
},
{ persistence: 'session' }
);
},

resetLayout() {
return store.setState((state: State) => {
return {
layout: {
...state.layout,
showNav: false,
showPanel: false,
isFullscreen: false,
},
};
});
return store.setState(
(state: State) => {
return {
layout: {
...state.layout,
showNav: false,
showPanel: false,
isFullscreen: false,
},
};
},
{ persistence: 'session' }
);
},

focusOnUIElement(elementId?: string) {
Expand Down

1 comment on commit 3531f4f

@vercel
Copy link

@vercel vercel bot commented on 3531f4f Nov 12, 2019

Choose a reason for hiding this comment

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

Please sign in to comment.