From 735b2f54813154a852f6c7df335ba5a3e6f4186f Mon Sep 17 00:00:00 2001 From: David Rousselie Date: Mon, 29 Apr 2024 17:29:37 +0200 Subject: [PATCH] fix: Trim trailing slash in Universal Inbox URL --- src/action/CreateTaskFromNotification.tsx | 4 ++-- src/action/LinkNotificationToTask.tsx | 4 ++-- src/action/NotificationActions.tsx | 8 ++++---- src/action/NotificationTaskActions.tsx | 2 +- src/action/PlanTask.tsx | 4 ++-- src/index.tsx | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/action/CreateTaskFromNotification.tsx b/src/action/CreateTaskFromNotification.tsx index 7a30eff..293835d 100644 --- a/src/action/CreateTaskFromNotification.tsx +++ b/src/action/CreateTaskFromNotification.tsx @@ -41,7 +41,7 @@ export function CreateTaskFromNotification({ notification, mutate }: CreateTaskF const [searchText, setSearchText] = useState(""); const { isLoading, data: projects } = useFetch>( - `${preferences.universalInboxBaseUrl}/api/tasks/projects/search?matches=${searchText}`, + `${preferences.universalInboxBaseUrl.replace(/\/$/, "")}/api/tasks/projects/search?matches=${searchText}`, { keepPreviousData: true, headers: { @@ -123,7 +123,7 @@ async function createTaskFromNotification( try { await mutate( handleErrors( - fetch(`${preferences.universalInboxBaseUrl}/api/notifications/${notification.id}/task`, { + fetch(`${preferences.universalInboxBaseUrl.replace(/\/$/, "")}/api/notifications/${notification.id}/task`, { method: "POST", body: JSON.stringify(taskCreation), headers: { diff --git a/src/action/LinkNotificationToTask.tsx b/src/action/LinkNotificationToTask.tsx index 42b5958..16648aa 100644 --- a/src/action/LinkNotificationToTask.tsx +++ b/src/action/LinkNotificationToTask.tsx @@ -22,7 +22,7 @@ export function LinkNotificationToTask({ notification, mutate }: LinkNotificatio const [searchText, setSearchText] = useState(""); const { isLoading, data: tasks } = useFetch>( - `${preferences.universalInboxBaseUrl}/api/tasks/search?matches=${searchText}`, + `${preferences.universalInboxBaseUrl.replace(/\/$/, "")}/api/tasks/search?matches=${searchText}`, { keepPreviousData: true, headers: { @@ -78,7 +78,7 @@ async function linkNotificationToTask( try { await mutate( handleErrors( - fetch(`${preferences.universalInboxBaseUrl}/api/notifications/${notification.id}`, { + fetch(`${preferences.universalInboxBaseUrl.replace(/\/$/, "")}/api/notifications/${notification.id}`, { method: "PATCH", body: JSON.stringify({ status: TaskStatus.Deleted, task_id: taskId }), headers: { diff --git a/src/action/NotificationActions.tsx b/src/action/NotificationActions.tsx index 249e35e..7cc99da 100644 --- a/src/action/NotificationActions.tsx +++ b/src/action/NotificationActions.tsx @@ -72,7 +72,7 @@ export async function deleteNotification( if (isNotificationBuiltFromTask(notification) && notification.task) { await mutate( handleErrors( - fetch(`${preferences.universalInboxBaseUrl}/api/tasks/${notification.task.id}`, { + fetch(`${preferences.universalInboxBaseUrl.replace(/\/$/, "")}/api/tasks/${notification.task.id}`, { method: "PATCH", body: JSON.stringify({ status: TaskStatus.Deleted }), headers: { @@ -93,7 +93,7 @@ export async function deleteNotification( } else { await mutate( handleErrors( - fetch(`${preferences.universalInboxBaseUrl}/api/notifications/${notification.id}`, { + fetch(`${preferences.universalInboxBaseUrl.replace(/\/$/, "")}/api/notifications/${notification.id}`, { method: "PATCH", body: JSON.stringify({ status: NotificationStatus.Deleted }), headers: { @@ -132,7 +132,7 @@ export async function unsubscribeFromNotification( try { await mutate( handleErrors( - fetch(`${preferences.universalInboxBaseUrl}/api/notifications/${notification.id}`, { + fetch(`${preferences.universalInboxBaseUrl.replace(/\/$/, "")}/api/notifications/${notification.id}`, { method: "PATCH", body: JSON.stringify({ status: NotificationStatus.Unsubscribed }), headers: { @@ -171,7 +171,7 @@ export async function snoozeNotification( const snoozeTime = computeSnoozedUntil(new Date(), 1, 6); await mutate( handleErrors( - fetch(`${preferences.universalInboxBaseUrl}/api/notifications/${notification.id}`, { + fetch(`${preferences.universalInboxBaseUrl.replace(/\/$/, "")}/api/notifications/${notification.id}`, { method: "PATCH", body: JSON.stringify({ snoozed_until: snoozeTime }), headers: { diff --git a/src/action/NotificationTaskActions.tsx b/src/action/NotificationTaskActions.tsx index 192375b..7edc57c 100644 --- a/src/action/NotificationTaskActions.tsx +++ b/src/action/NotificationTaskActions.tsx @@ -68,7 +68,7 @@ async function completeTask(notification: Notification, mutate: MutatePromise>( - `${preferences.universalInboxBaseUrl}/api/tasks/projects/search?matches=${searchText}`, + `${preferences.universalInboxBaseUrl.replace(/\/$/, "")}/api/tasks/projects/search?matches=${searchText}`, { keepPreviousData: true, headers: { @@ -122,7 +122,7 @@ async function planTask( try { await mutate( handleErrors( - fetch(`${preferences.universalInboxBaseUrl}/api/tasks/${notification.task.id}`, { + fetch(`${preferences.universalInboxBaseUrl.replace(/\/$/, "")}/api/tasks/${notification.task.id}`, { method: "PATCH", body: JSON.stringify({ project: taskPlanning.project.name, diff --git a/src/index.tsx b/src/index.tsx index ca713c2..1ab838a 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -33,7 +33,7 @@ export default function Command() { const [notificationKind, setNotificationKind] = useState(""); const { isLoading, data, mutate } = useFetch>( - `${preferences.universalInboxBaseUrl}/api/notifications?status=Unread,Read&with_tasks=true${ + `${preferences.universalInboxBaseUrl.replace(/\/$/, "")}/api/notifications?status=Unread,Read&with_tasks=true${ notificationKind ? "¬ification_kind=" + notificationKind : "" }`, {