feat: Add filter per notification kind

This commit is contained in:
2024-02-01 09:37:40 +01:00
parent 26f346f8b8
commit 9fb5af87ed
4 changed files with 52 additions and 6 deletions

View File

@@ -2,6 +2,12 @@
## [Unreleased]
## [0.1.1] - 2024-02-31
### Added
- Add filter per notification kind
## [0.1.0] - 2024-01-29
### Added

2
package-lock.json generated
View File

@@ -1,10 +1,12 @@
{
"name": "universal-inbox",
"version": "0.1.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "universal-inbox",
"version": "0.1.0",
"license": "MIT",
"dependencies": {
"@raycast/api": "^1.65.1",

View File

@@ -6,7 +6,8 @@
"icon": "ui-logo-transparent.png",
"author": "dax42",
"owner": "universal-inbox",
"version": "0.1.0",
"access": "public",
"version": "0.1.1",
"categories": [
"Productivity"
],

View File

@@ -7,6 +7,7 @@ import { Notification, NotificationListItemProps } from "./notification";
import { NotificationActions } from "./action/NotificationActions";
import { Page, UniversalInboxPreferences } from "./types";
import { useFetch } from "@raycast/utils";
import { useState } from "react";
export default function Command() {
const preferences = getPreferenceValues<UniversalInboxPreferences>();
@@ -29,8 +30,11 @@ export default function Command() {
);
}
const [notificationKind, setNotificationKind] = useState("");
const { isLoading, data, mutate } = useFetch<Page<Notification>>(
`${preferences.universalInboxBaseUrl}/api/notifications?status=Unread,Read&with_tasks=true`,
`${preferences.universalInboxBaseUrl}/api/notifications?status=Unread,Read&with_tasks=true${
notificationKind ? "&notification_kind=" + notificationKind : ""
}`,
{
headers: {
Authorization: `Bearer ${preferences.apiKey}`,
@@ -39,10 +43,24 @@ export default function Command() {
);
return (
<List isLoading={isLoading}>
{data?.content.map((notification: Notification) => {
return <NotificationListItem key={notification.id} notification={notification} mutate={mutate} />;
})}
<List
isLoading={isLoading}
searchBarPlaceholder="Filter notifications..."
searchBarAccessory={
<NotificationKindDropdown value={notificationKind} onNotificationKindChange={setNotificationKind} />
}
>
{data?.content.length === 0 ? (
<List.EmptyView
icon={{ source: "ui-logo-transparent.png" }}
title="Congrats! You have reach zero inbox 🎉"
description="You don't have any new notifications."
/>
) : (
data?.content.map((notification: Notification) => {
return <NotificationListItem key={notification.id} notification={notification} mutate={mutate} />;
})
)}
</List>
);
}
@@ -78,3 +96,22 @@ function DefaultNotificationListItem({ notification, mutate }: NotificationListI
/>
);
}
interface NotificationKindDropdownProps {
value: string;
onNotificationKindChange: (newValue: string) => void;
}
function NotificationKindDropdown({ value, onNotificationKindChange }: NotificationKindDropdownProps) {
return (
<List.Dropdown tooltip="Select Notification Kind" value={value} onChange={onNotificationKindChange}>
<List.Dropdown.Section title="Notification kind">
<List.Dropdown.Item key="0" title="" value="" />
<List.Dropdown.Item key="Github" title="Github" value="Github" />
<List.Dropdown.Item key="Linear" title="Linear" value="Linear" />
<List.Dropdown.Item key="GoogleMail" title="Google Mail" value="GoogleMail" />
<List.Dropdown.Item key="Todoist" title="Todoist" value="Todoist" />
</List.Dropdown.Section>
</List.Dropdown>
);
}