2020-11-13 17:09:28 +00:00
|
|
|
import { CommandContext, CommandDeclaration, CommandRuntime } from '@joplin/lib/services/CommandService';
|
2020-11-07 15:59:37 +00:00
|
|
|
import { _ } from '@joplin/lib/locale';
|
2020-11-13 17:09:28 +00:00
|
|
|
import setLayoutItemProps from '../../ResizableLayout/utils/setLayoutItemProps';
|
|
|
|
import layoutItemProp from '../../ResizableLayout/utils/layoutItemProp';
|
|
|
|
import { AppState } from '../../../app';
|
2020-07-03 22:32:39 +01:00
|
|
|
|
2020-11-12 19:13:28 +00:00
|
|
|
export const declaration: CommandDeclaration = {
|
2020-10-18 21:52:10 +01:00
|
|
|
name: 'toggleSideBar',
|
2020-07-03 22:32:39 +01:00
|
|
|
label: () => _('Toggle sidebar'),
|
2020-10-13 13:01:02 +01:00
|
|
|
iconName: 'fas fa-bars',
|
2020-07-03 22:32:39 +01:00
|
|
|
};
|
|
|
|
|
2020-11-13 17:09:28 +00:00
|
|
|
export const runtime = (): CommandRuntime => {
|
2020-07-03 22:32:39 +01:00
|
|
|
return {
|
2020-11-13 17:09:28 +00:00
|
|
|
execute: async (context: CommandContext) => {
|
|
|
|
const layout = (context.state as AppState).mainLayout;
|
|
|
|
|
|
|
|
const newLayout = setLayoutItemProps(layout, 'sideBar', {
|
|
|
|
visible: !layoutItemProp(layout, 'sideBar', 'visible'),
|
|
|
|
});
|
|
|
|
|
|
|
|
context.dispatch({
|
|
|
|
type: 'MAIN_LAYOUT_SET',
|
|
|
|
value: newLayout,
|
2020-07-03 22:32:39 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|