Skip to content

Commit

Permalink
Merge pull request #132 from uphy/feature/drag-reminder
Browse files Browse the repository at this point in the history
Add feature to drag reminder
  • Loading branch information
uphy authored Dec 2, 2022
2 parents 341091f + 32b05a1 commit 31bf6cb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/ui/components/ReminderList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
export let groups: Array<GroupedReminder>;
export let component: Component;
export let onOpenReminder: (reminder: Reminder) => void;
export let generateLink: (reminder: Reminder) => string;
</script>

<main>
Expand All @@ -19,6 +20,7 @@
{component}
{onOpenReminder}
timeToString={(time) => group.timeToString(time)}
{generateLink}
/>
{/each}
</div>
Expand Down
7 changes: 6 additions & 1 deletion src/ui/components/ReminderListByDate.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
export let component: Component;
export let onOpenReminder: (reminder: Reminder) => void = () => {};
export let timeToString = (time: DateTime) => time.format("HH:MM");
export let generateLink: (reminder: Reminder) => string;
</script>

<div class="reminder-group">
Expand All @@ -20,7 +21,11 @@
class="reminder-list-item"
aria-label={`[${reminder.time.toString()}] ${
reminder.title
} - ${reminder.getFileName()}`}
} - ${reminder.getFileName()}`},
draggable="true"
on:dragstart={(e)=>{
e.dataTransfer?.setData("text/plain", generateLink(reminder));
}}
on:click={() => {
onOpenReminder(reminder);
}}
Expand Down
11 changes: 11 additions & 0 deletions src/ui/reminder-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ class ReminderListItemView extends ItemView {
groups: this.remindersForView(),
onOpenReminder: this.onOpenReminder,
component: this,
generateLink: (reminder: Reminder): string => {
const aFile = this.app.vault.getAbstractFileByPath(reminder.file);
const destinationFile = this.app.workspace.getActiveFile();
let linkMd: string;
if (!(aFile instanceof TFile) || destinationFile == null) {
linkMd = `[[${reminder.getFileName()}]]`;
} else {
linkMd = this.app.fileManager.generateMarkdownLink(aFile, destinationFile.path);
}
return `${linkMd} - ${reminder.title}`;
},
},
});
}
Expand Down

0 comments on commit 31bf6cb

Please sign in to comment.