53 lines
1.7 KiB
JavaScript
53 lines
1.7 KiB
JavaScript
(function (root, factory) {
|
|
if (typeof module === 'object' && module.exports) module.exports = factory;
|
|
else root.createMobileQueueLauncher = factory;
|
|
})(typeof self !== 'undefined' ? self : this, function createMobileQueueLauncher(options) {
|
|
const emptyMessages = {
|
|
attention: 'No items need attention.',
|
|
update: 'No unread updates are ready to open.',
|
|
later: 'No deferred work is ready to open.',
|
|
draft: 'No drafts are ready to open.',
|
|
};
|
|
const continuation = [
|
|
['attention', 'Start Attention'],
|
|
['today', 'Continue Today'],
|
|
['agenda', 'Open Agenda'],
|
|
['later', 'Start Later'],
|
|
['draft', 'Open Drafts'],
|
|
];
|
|
|
|
function recommend() {
|
|
const counts = options.getCounts ? options.getCounts() : {};
|
|
const match = continuation.find(([name]) => Number(counts[name]) > 0);
|
|
if (!match) return {name: 'find', count: 0, label: 'Find Work'};
|
|
const [name, label] = match;
|
|
const count = Math.max(0, Number(counts[name]) || 0);
|
|
return {name, count, label: label + ' (' + count + ')'};
|
|
}
|
|
|
|
function open(name) {
|
|
if (name === 'today') return options.openToday();
|
|
if (name === 'agenda') return options.openAgenda();
|
|
if (name === 'update' && options.openUpdates) return options.openUpdates();
|
|
options.selectFilter(name);
|
|
const action = options.firstAction(name);
|
|
if (!action) {
|
|
options.announce(emptyMessages[name] || 'No work is ready to open.');
|
|
return 'empty';
|
|
}
|
|
action.click();
|
|
return 'opened';
|
|
}
|
|
|
|
function continueWork() {
|
|
const next = recommend();
|
|
if (next.name === 'find') {
|
|
options.openFindWork();
|
|
return 'find';
|
|
}
|
|
return open(next.name);
|
|
}
|
|
|
|
return { open, recommend, continueWork };
|
|
});
|