1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/ElectronClient/gui/KeymapConfig/utils/useCommandStatus.js
2020-08-30 20:42:09 +01:00

26 lines
2.5 KiB
JavaScript

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const react_1 = require('react');
const KeymapService_1 = require('../../../lib/services/KeymapService');
const keymapService = KeymapService_1.default.instance();
const useCommandStatus = () => {
const [status, setStatus] = react_1.useState(() => keymapService.getCommandNames().reduce((accumulator, command) => {
accumulator[command] = false;
return accumulator;
}, {}));
const disableStatus = (commandName) => setStatus(prevStatus => (Object.assign(Object.assign({}, prevStatus), { [commandName]: false })));
const enableStatus = (commandName) => setStatus(prevStatus => {
// Falsify all the commands; Only one command should be truthy at any given time
const newStatus = Object.keys(prevStatus).reduce((accumulator, command) => {
accumulator[command] = false;
return accumulator;
}, {});
// Make the appropriate command truthful
newStatus[commandName] = true;
return newStatus;
});
return [status, enableStatus, disableStatus];
};
exports.default = useCommandStatus;
// # sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXNlQ29tbWFuZFN0YXR1cy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInVzZUNvbW1hbmRTdGF0dXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxpQ0FBaUM7QUFDakMsdUVBQWdFO0FBRWhFLE1BQU0sYUFBYSxHQUFHLHVCQUFhLENBQUMsUUFBUSxFQUFFLENBQUM7QUFNL0MsTUFBTSxnQkFBZ0IsR0FBRyxHQUFrRixFQUFFO0lBQzVHLE1BQU0sQ0FBQyxNQUFNLEVBQUUsU0FBUyxDQUFDLEdBQUcsZ0JBQVEsQ0FBZ0IsR0FBRyxFQUFFLENBQ3hELGFBQWEsQ0FBQyxlQUFlLEVBQUUsQ0FBQyxNQUFNLENBQUMsQ0FBQyxXQUEwQixFQUFFLE9BQWUsRUFBRSxFQUFFO1FBQ3RGLFdBQ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