Skip to content

Commit

Permalink
chore: make timeStep modifiable
Browse files Browse the repository at this point in the history
  • Loading branch information
uphy committed Jan 1, 2025
1 parent bf8c8a8 commit d40069d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default class ReminderPlugin extends Plugin {
this.reminders
);
this.reminderModal = new ReminderModal(this.app, SETTINGS.useSystemNotification, SETTINGS.laters);
this.autoComplete = new AutoComplete(SETTINGS.autoCompleteTrigger);
this.autoComplete = new AutoComplete(SETTINGS.autoCompleteTrigger, SETTINGS.reminderTimeStep);
}

override async onload() {
Expand Down
9 changes: 9 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Settings {
settings: SettingTabModel = new SettingTabModel();

reminderTime: SettingModel<string, Time>;
reminderTimeStep: SettingModel<number, number>;
useSystemNotification: SettingModel<boolean, boolean>;
laters: SettingModel<string, Array<Later>>;
dateFormat: SettingModel<string, string>;
Expand All @@ -36,6 +37,13 @@ class Settings {
.placeHolder("Time (hh:mm)")
.build(new TimeSerde());

this.reminderTimeStep = this.settings.newSettingBuilder()
.key("reminderTimeStep")
.name("Reminder Time Step (minutes)")
.desc("Step of time for reminder time (minutes)")
.number(15)
.build(new RawSerde());

this.useSystemNotification = this.settings.newSettingBuilder()
.key("useSystemNotification")
.name("Use system notification")
Expand Down Expand Up @@ -152,6 +160,7 @@ class Settings {
.newGroup("Notification Settings")
.addSettings(
this.reminderTime,
this.reminderTimeStep,
this.laters,
this.useSystemNotification
);
Expand Down
7 changes: 4 additions & 3 deletions src/ui/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface AutoCompletableEditor {

export class AutoComplete {

constructor(private trigger: ReadOnlyReference<string>) { };
constructor(private trigger: ReadOnlyReference<string>, private timeStep: ReadOnlyReference<number>) { };

isTrigger(cmEditor: CodeMirror.Editor, changeObj: CodeMirror.EditorChange) {
const trigger = this.trigger.value;
Expand Down Expand Up @@ -51,10 +51,11 @@ export class AutoComplete {
result = v.show();
} catch (e) {
// Temporary workaround for Live preview mode
result = showDateTimeChooserModal(app, reminders);
console.error(e);
result = showDateTimeChooserModal(app, reminders, this.timeStep.value);
}
} else {
result = showDateTimeChooserModal(app, reminders);
result = showDateTimeChooserModal(app, reminders, this.timeStep.value);
}

result
Expand Down
5 changes: 3 additions & 2 deletions src/ui/components/DateTimeChooser.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
export let component: Component|undefined;
export let date = moment();
export let reminders: Reminders;
export let onSelect: (time: DateTime) => void;
export let onSelect: (time: DateTime) => void;
export let timeStep = 15;
let time = reminders.reminderTime?.value.toString() ?? "10:00";
let timeIsFocused = false;
Expand Down Expand Up @@ -42,7 +43,7 @@
<div class="dtchooser-wrapper">
<div class="dtchooser-time-picker">
<span>Time: </span>
<TimePicker bind:value={time} step={15} on:select={()=>{handleSelect()}} on:focus={()=>{timeIsFocused = true}} />
<TimePicker bind:value={time} step={timeStep} on:select={()=>{handleSelect()}} on:focus={()=>{timeIsFocused = true}} />
</div>
<button class="mod-cta" on:click={handleSelect}>OK</button>
</div>
Expand Down
10 changes: 6 additions & 4 deletions src/ui/date-chooser-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class DateTimeChooserModal extends Modal {
app: App,
private reminders: Reminders,
private onSelect: (value: DateTime) => void,
private onCancel: () => void
private onCancel: () => void,
private timeStep: number
) {
super(app);
}
Expand All @@ -35,7 +36,8 @@ class DateTimeChooserModal extends Modal {
this.select(time);
},
reminders: this.reminders,
component: undefined
component: undefined,
timeStep: this.timeStep
},
});
}
Expand All @@ -55,9 +57,9 @@ class DateTimeChooserModal extends Modal {

}

export function showDateTimeChooserModal(app: App, reminders: Reminders): Promise<DateTime> {
export function showDateTimeChooserModal(app: App, reminders: Reminders, timeStep: number = 15): Promise<DateTime> {
return new Promise((resolve, reject) => {
const modal = new DateTimeChooserModal(app, reminders, resolve, reject);
const modal = new DateTimeChooserModal(app, reminders, resolve, reject, timeStep);
modal.open();
});
}
3 changes: 2 additions & 1 deletion src/ui/editor-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ export function buildCodeMirrorPlugin(app: App, reminders: Reminders) {
return;
}
const trigger = SETTINGS.autoCompleteTrigger.value;
const timeStep = SETTINGS.reminderTimeStep.value;
if (trigger === text) {
showDateTimeChooserModal(app, reminders).then(value => {
showDateTimeChooserModal(app, reminders, timeStep).then(value => {
const format = SETTINGS.primaryFormat.value.format;
try {
const line = doc.lineAt(toB);
Expand Down

0 comments on commit d40069d

Please sign in to comment.