feat: Add "Plan task" action for notifications created from task

This commit is contained in:
2024-02-01 22:42:12 +01:00
parent cfc0f0ed5e
commit ad43bf3c86
4 changed files with 243 additions and 36 deletions

View File

@@ -62,20 +62,25 @@ export function NotificationActions({ notification, detailsTarget, mutate }: Not
);
}
async function deleteNotification(notification: Notification, mutate: MutatePromise<Page<Notification> | undefined>) {
export async function deleteNotification(
notification: Notification,
mutate: MutatePromise<Page<Notification> | undefined>,
) {
const preferences = getPreferenceValues<UniversalInboxPreferences>();
const toast = await showToast({ style: Toast.Style.Animated, title: "Deleting notification" });
try {
if (isNotificationBuiltFromTask(notification) && notification.task) {
await mutate(
fetch(`${preferences.universalInboxBaseUrl}/api/tasks/${notification.task.id}`, {
method: "PATCH",
body: JSON.stringify({ status: TaskStatus.Deleted }),
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${preferences.apiKey}`,
},
}),
handleErrors(
fetch(`${preferences.universalInboxBaseUrl}/api/tasks/${notification.task.id}`, {
method: "PATCH",
body: JSON.stringify({ status: TaskStatus.Deleted }),
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${preferences.apiKey}`,
},
}),
),
{
optimisticUpdate(page) {
if (page) {
@@ -118,7 +123,7 @@ async function deleteNotification(notification: Notification, mutate: MutateProm
}
}
async function unsubscribeFromNotification(
export async function unsubscribeFromNotification(
notification: Notification,
mutate: MutatePromise<Page<Notification> | undefined>,
) {
@@ -156,7 +161,10 @@ async function unsubscribeFromNotification(
}
}
async function snoozeNotification(notification: Notification, mutate: MutatePromise<Page<Notification> | undefined>) {
export async function snoozeNotification(
notification: Notification,
mutate: MutatePromise<Page<Notification> | undefined>,
) {
const preferences = getPreferenceValues<UniversalInboxPreferences>();
const toast = await showToast({ style: Toast.Style.Animated, title: "Snoozing notification" });
try {