2020-11-13 19:09:28 +02:00
|
|
|
import { CommandContext, CommandDeclaration, CommandRuntime } from '@joplin/lib/services/CommandService';
|
2020-11-07 17:59:37 +02:00
|
|
|
import { _ } from '@joplin/lib/locale';
|
2020-11-13 19:09:28 +02:00
|
|
|
import setLayoutItemProps from '../../ResizableLayout/utils/setLayoutItemProps';
|
|
|
|
import layoutItemProp from '../../ResizableLayout/utils/layoutItemProp';
|
2021-09-04 19:11:29 +02:00
|
|
|
import { AppState } from '../../../app.reducer';
|
2020-07-03 23:32:39 +02:00
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
export const declaration: CommandDeclaration = {
|
2020-10-18 22:52:10 +02:00
|
|
|
name: 'toggleSideBar',
|
2020-07-03 23:32:39 +02:00
|
|
|
label: () => _('Toggle sidebar'),
|
2020-10-13 14:01:02 +02:00
|
|
|
iconName: 'fas fa-bars',
|
2020-07-03 23:32:39 +02:00
|
|
|
};
|
|
|
|
|
2020-11-13 19:09:28 +02:00
|
|
|
export const runtime = (): CommandRuntime => {
|
2020-07-03 23:32:39 +02:00
|
|
|
return {
|
2020-11-13 19:09:28 +02:00
|
|
|
execute: async (context: CommandContext) => {
|
|
|
|
const layout = (context.state as AppState).mainLayout;
|
|
|
|
|
|
|
|
const newLayout = setLayoutItemProps(layout, 'sideBar', {
|
|
|
|
visible: !layoutItemProp(layout, 'sideBar', 'visible'),
|
|
|
|
});
|
|
|
|
|
2021-09-19 12:36:23 +02:00
|
|
|
// Toggling the sidebar will affect the size of most other on-screen components.
|
|
|
|
// Dispatching a window resize event is a bit of a hack, but it ensures that any
|
|
|
|
// component that watches for resizes will be accurately notified
|
|
|
|
window.dispatchEvent(new Event('resize'));
|
|
|
|
|
2020-11-13 19:09:28 +02:00
|
|
|
context.dispatch({
|
|
|
|
type: 'MAIN_LAYOUT_SET',
|
|
|
|
value: newLayout,
|
2020-07-03 23:32:39 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|