Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Reminders fields and Notifications #1925

Draft
wants to merge 97 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
61eb448
System Notifications
Erik-Handeland Apr 11, 2023
24047ba
Update .gitignore
Erik-Handeland Apr 11, 2023
6fbcf75
obsidian modal
Erik-Handeland Apr 12, 2023
c609564
switched from interface to class
Erik-Handeland Apr 13, 2023
cd1819b
Reminder parsing and queries + model field
Erik-Handeland Apr 16, 2023
836bd1e
reminders watcher
Erik-Handeland Apr 17, 2023
a29ad68
hooked up tasks to notification modals
Erik-Handeland Apr 19, 2023
b51b204
Time support
Erik-Handeland Apr 20, 2023
d759ba5
Delete .vscode directory
Erik-Handeland Apr 20, 2023
528fc5b
Update .gitignore
Erik-Handeland Apr 20, 2023
edd333c
Delete src/Query/.vscode directory
Erik-Handeland Apr 20, 2023
71736c9
todos
Erik-Handeland Apr 21, 2023
fa7152b
Merge branch 'reminders' of https://github.com/Erik-Handeland/obsidia…
Erik-Handeland Apr 21, 2023
a4c1945
clean up
Erik-Handeland Apr 21, 2023
d91b4b3
hide reminder date
Erik-Handeland Apr 21, 2023
101b398
added back callback functions
Erik-Handeland Apr 21, 2023
7560b6b
Recurrences now support reminders
Erik-Handeland Apr 24, 2023
ccf8e87
Update Recurrence.ts
Erik-Handeland Apr 24, 2023
7da073f
migrated last reminderDate to reminder[]
Erik-Handeland Apr 26, 2023
7dee6c5
Update Recurrence.ts
Erik-Handeland Apr 26, 2023
8ba4542
cleanup
Erik-Handeland Apr 26, 2023
c596d5c
move from array of Reminder to single Reminders that holds an array o…
Erik-Handeland Apr 29, 2023
be6bfc3
merge main
Erik-Handeland Apr 29, 2023
e88f2cd
openFile callback added
Erik-Handeland Apr 29, 2023
e8aac99
starter documentation
Erik-Handeland Apr 29, 2023
fe065c5
Update Reminders.ts
Erik-Handeland Apr 29, 2023
01e37ca
basic tests
Erik-Handeland Apr 30, 2023
44a1486
Update ReminderList.ts
Erik-Handeland Apr 30, 2023
9565076
refactored ReminderList
Erik-Handeland Apr 30, 2023
110381e
Update Query.test.ts
Erik-Handeland Apr 30, 2023
0f285bd
reminders now uses settings panel
Erik-Handeland Apr 30, 2023
01e0bc5
clean up
Erik-Handeland Apr 30, 2023
44fdfcc
fix recurrence bug & serializer bug
Erik-Handeland Apr 30, 2023
d0e8550
cleaned up notifications
Erik-Handeland Apr 30, 2023
bb6b711
notifications trigger more accurately
Erik-Handeland Apr 30, 2023
9068c75
more tests
Erik-Handeland Apr 30, 2023
c8a755a
Clean up based on git comments
Erik-Handeland May 2, 2023
a21c7b1
Rename notification.ts to Notification.ts
Erik-Handeland May 3, 2023
2e5ea71
Rename Notification.ts to Notification.ts
Erik-Handeland May 3, 2023
187d6e7
Rename Reminder.ts to Reminder.ts
Erik-Handeland May 3, 2023
e770b95
Rename Icon.svelte to Icon.svelte
Erik-Handeland May 3, 2023
378638f
Rename Markdown.svelte to Markdown.svelte
Erik-Handeland May 3, 2023
3731393
Rename Reminder.svelte to Reminder.svelte
Erik-Handeland May 3, 2023
10fa48a
Rename folders and remove main.css
Erik-Handeland May 3, 2023
807a584
Fixed testing issue
Erik-Handeland May 6, 2023
d08fdef
fixed regex and added tests from claremacrae
Erik-Handeland May 6, 2023
24af196
more serialize tests
Erik-Handeland May 6, 2023
a227f0b
query reminder tests
Erik-Handeland May 7, 2023
06482ec
added Recurrence reminder tests
Erik-Handeland May 7, 2023
0a938b3
refactor: Rename reminders to remind in Task and Recurrence
claremacrae May 16, 2023
cee10e5
refactor: Rename reminder field in RecurrenceBuilder.ts to singular
claremacrae May 16, 2023
7a7708b
test: Remove the tests of multi-reminder capability
claremacrae May 16, 2023
d4bd23d
refactor!: Reinstate earlier regex for single date + time
claremacrae May 16, 2023
9c8bba8
refactor: ReminderList constructor now only takes at most one Moment
claremacrae May 16, 2023
b9ea9d8
refactor!: Simplify emoji-date parsing as regex only matches 1 value
claremacrae May 16, 2023
41398f1
refactor: RecurrenceBuilder.reminders() now takes only 1 date
claremacrae May 16, 2023
76e90fa
refactor: TaskBuilder.reminders() now takes only 1 date
claremacrae May 16, 2023
93cb3f2
refactor: Remove parseDateTimes() - no longer used.
claremacrae May 16, 2023
1810893
test: Move 'differing only in reminder' test to correct section
claremacrae May 16, 2023
0c009d5
test: Add some more checks in Recurrence.test.ts
claremacrae May 16, 2023
eb53efb
refactor: Rework Recurrence.next() for single reminder
claremacrae May 16, 2023
a874a49
refactor!: Now only support a single reminder
claremacrae May 16, 2023
6eff445
refactor: Remove ReminderList class as no longer used
claremacrae May 16, 2023
38ce5b6
comment: Add some TODOs of things to check
claremacrae May 16, 2023
160007b
comment: Add more TODOs of things to check
claremacrae May 16, 2023
52ae155
docs: Minor updates to Task-Reminders.md
claremacrae May 16, 2023
d65a0bb
docs: Add Reminder to Dates page
claremacrae May 17, 2023
0c764f9
docs: Page about Reminders plugin links to the Tasks reminders page
claremacrae May 17, 2023
b562031
test: Add tests that show that sorting by reminders honours the time
claremacrae May 17, 2023
16eef03
docs: Note the release version of Reminders facility
claremacrae May 17, 2023
96e9af3
docs: Document 'sort by reminder'
claremacrae May 17, 2023
4c7067e
test: Remove a TODO that I have now done.
claremacrae May 17, 2023
56c04be
test: Remove tests that use twelveHour format
claremacrae May 17, 2023
2fa9f9e
feat!: Make the default reminder format use 24-hour clock
claremacrae May 17, 2023
e12f881
feat!: Remove the 'Reminder Format' from settings UI
claremacrae May 17, 2023
561a40c
test: Remove test helper setDateTimeFormat() as only 1 format now
claremacrae May 17, 2023
dac37cc
refactor: Get TIME_FORMATS.twentyFourHour directly instead of via set…
claremacrae May 17, 2023
752ab37
refactor: Get TIME_FORMATS.twentyFourHour directly instead of via set…
claremacrae May 17, 2023
b79f497
refactor: Remove unused setting dateTimeFormat
claremacrae May 17, 2023
41d1b12
refactor: Simplify emoji-based reminderRegex, to only match 24 hour t…
claremacrae May 17, 2023
abb5d20
docs: Update docs now times are always 24-hour clock.
claremacrae May 17, 2023
1d18976
feat!: Use ⏰ for reminders for eventual consistency with Reminders
claremacrae May 17, 2023
a599230
fix: Use consistent & unique reminder shortcut in modal
claremacrae May 17, 2023
19ec47d
test: Rename TaskBuilder.reminders()
claremacrae May 17, 2023
223e3f6
test: Make TaskBuilder.reminder() consistent with date methods
claremacrae May 17, 2023
129e64b
test: Reimplement testTaskFilter() using custom matchers
claremacrae May 17, 2023
13fc7cc
test: When custom filter toMatchTask() fails, display instruction
claremacrae May 17, 2023
bf6075f
test: Show issues with times in reminder filters & tasks
claremacrae May 17, 2023
c90236f
fix: Filtering of task reminders strips off time, so that searches work.
claremacrae May 17, 2023
638575b
test: Show that times on reminder filters are ignored
claremacrae May 17, 2023
34e928a
refactor: Remove unused TIME_FORMATS.twelveHour
claremacrae May 17, 2023
6315caf
test: Sort new instructions in Query.test.ts
claremacrae May 28, 2023
c43d594
test: Move some tests from Query.test.ts to ReminderDateField.test.ts
claremacrae May 28, 2023
8efadf6
fix!!: Remove 'show/hide reminders' option
claremacrae May 28, 2023
be9ad29
refactor: Rename reminder Layout Option to hideReminderDate
claremacrae May 28, 2023
9297016
Merge branch 'main' into user-Erik-Handeland-reminders
claremacrae May 28, 2023
0497244
Merge branch 'main' into user-Erik-Handeland-reminders
claremacrae May 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
hooked up tasks to notification modals
  • Loading branch information
Erik-Handeland committed Apr 19, 2023
commit a29ad68b13edb11b43430b86a0af9ec3b3c205e0
64 changes: 63 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,65 @@
{
"npm.packageManager": "yarn"
"npm.packageManager": "yarn",
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"docs": true,
".github": true,
"contributing": true,
"docs-snippets": true,
"node_modules": true,
"resources": true,
".eslintrc.js": true,
".editorconfig": true,
".eslintignore": true,
".gitattributes": true,
".gitignore": true,
".markdownlint.jsonc": true,
".prettierrc.js": true,
"CODE_OF_CONDUCT.md": true,
"CONTRIBUTING.md": true,
"esbuild.config.mjs": true,
"jest.config.js": true,
"lefthook.yml": true,
"LICENSE": true,
"yarn.lock": true,
"versions.json": true,
"styles.css": true,
"release.sh": true,
"manifest.json": true,
"mdsnippets.json": true,
"package.json": true
},
"hide-files.files": [
"docs",
".github",
"contributing",
"docs-snippets",
"node_modules",
"resources",
".eslintrc.js",
".editorconfig",
".eslintignore",
".gitattributes",
".gitignore",
".markdownlint.jsonc",
".prettierrc.js",
"CODE_OF_CONDUCT.md",
"CONTRIBUTING.md",
"esbuild.config.mjs",
"jest.config.js",
"lefthook.yml",
"LICENSE",
"yarn.lock",
"versions.json",
"styles.css",
"release.sh",
"manifest.json",
"mdsnippets.json",
"package.json",
]
}
12 changes: 6 additions & 6 deletions main.css
Erik-Handeland marked this conversation as resolved.
Show resolved Hide resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Plugin } from 'obsidian';

import { TaskNotification } from './reminders/notification';
import { TaskNotification } from './reminders/Notification';
import { Cache } from './Cache';
import { Commands } from './Commands';
import { TasksEvents } from './TasksEvents';
Expand Down Expand Up @@ -51,6 +51,7 @@ export default class TasksPlugin extends Plugin {
vault: this.app.vault,
events,
});
console.log('cache', this.cache);
this.inlineRenderer = new InlineRenderer({ plugin: this });
this.queryRenderer = new QueryRenderer({ plugin: this, events });

Expand Down
20 changes: 3 additions & 17 deletions src/reminders/Reminder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Moment } from 'moment';

export class Reminder {
public date: Moment | null;
public date: Moment;
private isAck: boolean;

constructor(date: Moment) {
Expand All @@ -10,10 +10,10 @@ export class Reminder {
}

public toString(): string {
return `${this.date?.format('YYYY-MM-DD')}`;
return `${this.date.format('YYYY-MM-DD')}`;
}

public getDate(): Moment | null {
public getDate(): Moment {
return this.date;
}

Expand All @@ -24,18 +24,4 @@ export class Reminder {
public complete(): void {
this.isAck = true;
}

// public getExpiredReminders(defaultTime: Time): Array<Reminder> {
// const now = new Date().getTime();
// const result: Array<Reminder> = [];
// for (let i = 0; i < this.reminders.length; i++) {
// const reminder = this.reminders[i]!;
// if (reminder.time.getTimeInMillis(defaultTime) <= now) {
// result.push(reminder);
// } else {
// break;
// }
// }
// return result;
// }
}
19 changes: 10 additions & 9 deletions src/reminders/components/Reminder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import type { Component } from "obsidian";
import Icon from "./Icon.svelte";
import Markdown from "./Markdown.svelte";
import type { Task } from "../../Task";

export let reminder: any;
export let task: Task;
export let component: Component;
export let onRemindMeLater: (time: any) => void;
export let onDone: () => void;
Expand All @@ -26,16 +27,16 @@
<main>
<h1>
<Markdown
markdown={reminder.title}
sourcePath={reminder.file}
markdown={task.description}
sourcePath={task.filename ?? "NO FILE"}
{component}
/>
</h1>
<span class="reminder-file" on:click={onOpenFile}>
<span class="task-file" on:click={onOpenFile}>
<Icon icon="link" />
{reminder.file}
{"task.file"}
</span>
<div class="reminder-actions">
<div class="task-actions">
<button class="mod-cta" on:click={onDone}>
<Icon icon="check-small" /> Mark as Done
</button>
Expand Down Expand Up @@ -63,18 +64,18 @@
margin: 0 auto;
}

.reminder-actions {
.task-actions {
margin-top: 1rem;
display: flex;
gap: 0.5rem;
}

.reminder-file {
.task-file {
color: var(--text-muted);
cursor: pointer;
}

.reminder-file:hover {
.task-file:hover {
color: var(--text-normal);
text-decoration: underline;
}
Expand Down
50 changes: 25 additions & 25 deletions src/reminders/notification.ts
Erik-Handeland marked this conversation as resolved.
Show resolved Hide resolved
Erik-Handeland marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,23 @@ const Notification = electron.remote.Notification;
// Platform.isDesktopApp, // Platform.isMobileApp,
// import { Platform } from 'obsidian';

const notificationTitle = 'Task Reminder'; //TODO constant for language localization, is there a file for these already?

export class TaskNotification {
constructor(private app: App) {} //private app: App

public show() {
const reminder = {
title: 'Reminder Title',
file: 'path/to/file.md',
time: new Date(),
rowNumber: 1,
done: false,
};

public show(task: Task) {
// if election notification is supported, aka desktop app
if (Notification.isSupported()) {
// Show system notification
const n = new Notification({
title: 'Obsidian Reminder',
body: "Hello World, You've got mail!",
title: notificationTitle, // todo set to constant for language localization
body: task.description,
});
n.on('click', () => {
console.log('Notification clicked');
n.close();
this.showBuiltinReminder(reminder);
this.showBuiltinReminder(task);
});
n.on('close', () => {
console.log('Notification closed');
Expand All @@ -56,7 +50,7 @@ export class TaskNotification {
} else {
// Show obsidian modal notification for mobile users
// Must be in app for this to trigger
this.showBuiltinReminder(reminder);
this.showBuiltinReminder(task);
}
}

Expand All @@ -77,7 +71,7 @@ export class TaskNotification {
this.reminderEvent(tasks).finally(() => {
intervalTaskRunning = false;
});
}, 1000);
}, 1000000);
}

private async reminderEvent(tasks: Task[]): Promise<void> {
Expand All @@ -93,16 +87,22 @@ export class TaskNotification {
reminderTasks = reminderTasks.filter(filter.filterFunction);
});

for (const rTask of reminderTasks) {
const now = window.moment();
const daily = window.moment().startOf('day'); // match on moments that have no time set
// Might want to adjust this offset to be based on the setInterval + ~1 second
if (rTask.reminders[0].date?.isBetween(now.subtract(30, 'seconds'), now.add(30, 'seconds'))) {
for (const task of reminderTasks) {
const now = window.moment(); // current date + time
const alertTime = window.moment('09:00', 'hh:mm'); // time to show daily reminders
const daily = window.moment().startOf('day'); // today with a blank time

// Check if reminder is within 30 seconds of now
// need .clone() to avoid mutating original date todo: is there a better way to do this?
if (task.reminders[0].date.isBetween(now, now.clone().add(30, 'seconds'))) {
console.log('Show Notification');
} else if (rTask.reminders[0].date?.isSame(daily)) {
// Add check for if {{9am}}
console.log('Daily Notification');
//this.show();
this.show(task);
// else check for daily reminder
} else if (
task.reminders[0].date.isSame(daily) &&
now.isBetween(alertTime, alertTime.clone().add(30, 'minutes'))
) {
this.show(task);
}
}
}
Expand Down Expand Up @@ -131,7 +131,7 @@ class ObsidianNotificationModal extends Modal {
constructor(
app: App,
private laters: Array<Number>,
private reminder: any, // callbacks // private onRemindMeLater: (time: any) => void, // private onDone: () => void, // private onCancel: () => void, // private onOpenFile: () => void,
private task: Task, // callbacks // private onRemindMeLater: (time: any) => void, // private onDone: () => void, // private onCancel: () => void, // private onOpenFile: () => void,
) {
super(app);
}
Expand All @@ -141,7 +141,7 @@ class ObsidianNotificationModal extends Modal {
new ReminderView({
target: contentEl,
props: {
reminder: this.reminder,
task: this.task,
laters: this.laters,
component: this,
onRemindMeLater: () => {
Expand Down