feat: Add notification actions
This commit is contained in:
@@ -1,20 +1,21 @@
|
||||
import { Action, ActionPanel, Detail, List, getPreferenceValues, openExtensionPreferences } from "@raycast/api";
|
||||
import { useFetch } from "@raycast/utils";
|
||||
import { NotificationActions } from "./NotificationActions";
|
||||
import { GithubNotificationListItem } from "./integrations/github/GithubNotificationListItem";
|
||||
import { GoogleMailNotificationListItem } from "./integrations/google-mail/GoogleMailNotificationListItem";
|
||||
import { LinearNotificationListItem } from "./integrations/linear/LinearNotificationListItem";
|
||||
import { GithubNotificationListItem } from "./integrations/github/listitem/GithubNotificationListItem";
|
||||
import { TodoistNotificationListItem } from "./integrations/todoist/TodoistNotificationListItem";
|
||||
import { Notification, NotificationListItemProps, Page, UniversalInboxPreferences } from "./types";
|
||||
import { LinearNotificationListItem } from "./integrations/linear/LinearNotificationListItem";
|
||||
import { Notification, NotificationListItemProps } from "./notification";
|
||||
import { NotificationActions } from "./action/NotificationActions";
|
||||
import { Page, UniversalInboxPreferences } from "./types";
|
||||
import { useFetch } from "@raycast/utils";
|
||||
|
||||
export default function Command() {
|
||||
const preferences = getPreferenceValues<UniversalInboxPreferences>();
|
||||
|
||||
if (
|
||||
preferences.apiKey === undefined ||
|
||||
preferences.apiKey === ""
|
||||
/* preferences.universalInboxBaseUrl === undefined ||
|
||||
* preferences.universalInboxBaseUrl === "" */
|
||||
preferences.apiKey === "" ||
|
||||
preferences.universalInboxBaseUrl === undefined ||
|
||||
preferences.universalInboxBaseUrl === ""
|
||||
) {
|
||||
return (
|
||||
<Detail
|
||||
@@ -28,7 +29,7 @@ export default function Command() {
|
||||
);
|
||||
}
|
||||
|
||||
const { isLoading, data } = useFetch<Page<Notification>>(
|
||||
const { isLoading, data, mutate } = useFetch<Page<Notification>>(
|
||||
`${preferences.universalInboxBaseUrl}/api/notifications?status=Unread,Read&with_tasks=true`,
|
||||
{
|
||||
headers: {
|
||||
@@ -40,35 +41,39 @@ export default function Command() {
|
||||
return (
|
||||
<List isLoading={isLoading}>
|
||||
{data?.content.map((notification: Notification) => {
|
||||
return <NotificationListItem key={notification.id} notification={notification} />;
|
||||
return <NotificationListItem key={notification.id} notification={notification} mutate={mutate} />;
|
||||
})}
|
||||
</List>
|
||||
);
|
||||
}
|
||||
|
||||
function NotificationListItem({ notification }: NotificationListItemProps) {
|
||||
function NotificationListItem({ notification, mutate }: NotificationListItemProps) {
|
||||
switch (notification.metadata.type) {
|
||||
case "Github":
|
||||
return <GithubNotificationListItem notification={notification} />;
|
||||
return <GithubNotificationListItem notification={notification} mutate={mutate} />;
|
||||
case "Linear":
|
||||
return <LinearNotificationListItem notification={notification} />;
|
||||
return <LinearNotificationListItem notification={notification} mutate={mutate} />;
|
||||
case "GoogleMail":
|
||||
return <GoogleMailNotificationListItem notification={notification} />;
|
||||
return <GoogleMailNotificationListItem notification={notification} mutate={mutate} />;
|
||||
case "Todoist":
|
||||
return <TodoistNotificationListItem notification={notification} />;
|
||||
return <TodoistNotificationListItem notification={notification} mutate={mutate} />;
|
||||
default:
|
||||
return <DefaultNotificationListItem notification={notification} />;
|
||||
return <DefaultNotificationListItem notification={notification} mutate={mutate} />;
|
||||
}
|
||||
}
|
||||
|
||||
function DefaultNotificationListItem({ notification }: NotificationListItemProps) {
|
||||
function DefaultNotificationListItem({ notification, mutate }: NotificationListItemProps) {
|
||||
return (
|
||||
<List.Item
|
||||
key={notification.id}
|
||||
title={notification.title}
|
||||
subtitle={`#${notification.source_id}`}
|
||||
actions={
|
||||
<NotificationActions notification={notification} detailsTarget={<Detail markdown="# To be implemented 👋" />} />
|
||||
<NotificationActions
|
||||
notification={notification}
|
||||
detailsTarget={<Detail markdown="# To be implemented 👋" />}
|
||||
mutate={mutate}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user