mirror of
https://github.com/prncc/obsidian-repeat-plugin.git
synced 2026-07-22 06:50:25 +00:00
* Add command to repeat: never * Add a default repeat value to the settings * Add comments to repeat types * Remove unused utility * Use the default repeat property when inferring values * Use a one day default default period after all * Update README to mention the new default interval setting * Reword new repeat property setting * Prepare release of version 1.8.0 * Add toggle to enqueue notes without repeat (for setup) * Show the Never button if non-repeating notes are enqueued * Fix merge conflict after adding the never repeat setting * Prepare release of version 1.9.0
67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
import { PeriodUnit, Repeat, Repetition } from './repeatTypes';
|
|
|
|
const SERIALIZED_TRUE = 'true';
|
|
export const SERIALIZED_FALSE = 'false';
|
|
|
|
function serializeRepeatPeriodUnit(
|
|
repeatPeriodUnit: PeriodUnit,
|
|
repeatPeriod: number,
|
|
): string {
|
|
const suffix = (repeatPeriod === 1) ? '' : 's';
|
|
return `${repeatPeriodUnit.toLowerCase()}${suffix}`;
|
|
}
|
|
|
|
export function serializeRepeat({
|
|
repeatStrategy,
|
|
repeatPeriod,
|
|
repeatPeriodUnit,
|
|
repeatTimeOfDay
|
|
}: Repeat | Repetition): string {
|
|
if (repeatStrategy === 'PERIODIC'
|
|
&& repeatPeriod === 1
|
|
&& repeatPeriodUnit !== 'HOUR'
|
|
&& repeatTimeOfDay === 'AM'
|
|
) {
|
|
switch (repeatPeriodUnit) {
|
|
case 'DAY':
|
|
return 'daily';
|
|
case 'WEEK':
|
|
return 'weekly';
|
|
case 'MONTH':
|
|
return 'monthly';
|
|
case 'YEAR':
|
|
return 'yearly';
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
return [
|
|
...(repeatStrategy === 'PERIODIC' ? [] : ['spaced']),
|
|
'every',
|
|
...(repeatPeriod === 1 ? [] : [`${repeatPeriod}`]),
|
|
serializeRepeatPeriodUnit(repeatPeriodUnit, repeatPeriod),
|
|
...(repeatTimeOfDay === 'AM' ? [] : ['in the evening']),
|
|
].join(' ');
|
|
}
|
|
|
|
export function serializeRepetition(repetition: Repetition | 'DISMISS' | 'NEVER') {
|
|
if (repetition === 'NEVER') {
|
|
return {
|
|
repeat: 'never',
|
|
due_at: undefined,
|
|
hidden: undefined,
|
|
}
|
|
} else if (repetition === 'DISMISS') {
|
|
return {
|
|
repeat: undefined,
|
|
due_at: undefined,
|
|
hidden: undefined,
|
|
}
|
|
} else {
|
|
return {
|
|
repeat: serializeRepeat(repetition),
|
|
due_at: repetition.repeatDueAt.toISO(),
|
|
hidden: repetition.hidden ? SERIALIZED_TRUE : SERIALIZED_FALSE,
|
|
}
|
|
}
|
|
}
|