stackchain-dashboard/frontend/detail-defer.js
timmy 72c470b652
All checks were successful
CI / lint (pull_request) Successful in 48s
CI / build-release (pull_request) Successful in 5s
CI / release-candidate (pull_request) Has been skipped
feat: defer Today work and continue (#455)
2026-08-10 05:22:01 +00:00

40 lines
1.3 KiB
JavaScript

function createDetailDefer({
laterWork,
session,
continueSession = null,
close,
refresh,
focus,
announce,
formatTime = value => new Date(value).toLocaleString(),
}) {
return {
deferUntil(item, until, { closeSheet = true, restoreFocus = true } = {}) {
if (!item) return false;
const result = laterWork.defer(item, until);
if (result !== 'deferred') {
announce(result === 'invalid' ? 'Choose a valid future time.' : 'Could not save Later on this device.');
return false;
}
const inSession = session.active();
if (continueSession && session.checkpointed?.(item)) {
if (continueSession(item) === true) return true;
laterWork.restore(item);
refresh();
announce('Could not remove this item from Today, so it was restored from Later.');
return false;
}
if (!inSession && closeSheet) close();
refresh();
announce('Deferred until ' + formatTime(until) + '. It stays unread and unchanged in Gitea.');
if (!inSession && restoreFocus) focus();
return true;
},
defer(item, preset) {
return this.deferUntil(item, laterWork.presetUntil(preset));
},
};
}
if (typeof module !== 'undefined' && module.exports) module.exports = createDetailDefer;