37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
function createCreateAndStart({ todayWork, todaySync, refresh, warm, start, announce }) {
|
|
const completed = new Set();
|
|
|
|
function available() {
|
|
return todayWork.read().length < todayWork.limit;
|
|
}
|
|
|
|
function complete(issue) {
|
|
const identity = todayWork.identity(issue);
|
|
if (!identity || completed.has(identity)) return 'exists';
|
|
const added = todayWork.add(issue);
|
|
if (added === 'full') {
|
|
announce('Created, but Today changed—remove an item, then add this issue.');
|
|
return 'full';
|
|
}
|
|
if (added !== 'added' && added !== 'exists') {
|
|
announce('Created, but Today could not be saved on this device.');
|
|
return 'unavailable';
|
|
}
|
|
if (!todaySync.enqueue('add', identity)) {
|
|
announce('Created and saved to Today on this device, but account sync is unavailable.');
|
|
return 'sync-unavailable';
|
|
}
|
|
completed.add(identity);
|
|
refresh();
|
|
todaySync.flush();
|
|
warm();
|
|
start(issue);
|
|
announce('Created, added to Today, and ready to work.');
|
|
return 'started';
|
|
}
|
|
|
|
return { available, complete };
|
|
}
|
|
|
|
if (typeof module !== 'undefined' && module.exports) module.exports = createCreateAndStart;
|