Skip to content

Commit

Permalink
add collection vote notification
Browse files Browse the repository at this point in the history
  • Loading branch information
olexh committed Mar 31, 2024
1 parent d5ed8cb commit 137b0b7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
21 changes: 13 additions & 8 deletions types/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ declare global {
| 'edit_updated'
| 'hikka_update'
| 'schedule_anime'
| 'follow';
| 'follow'
| 'collection_vote';

type NotificationFollowData = {
username: string;
Expand All @@ -323,19 +324,22 @@ declare global {
avatar: string;
};

type NotificationCommentVoteData = {
type NotificationVoteData = {
slug: string;
content_type: ContentType;
comment_reference: string;
comment_depth: number;
comment_text: string;
base_comment_reference: string;
user_score: number;
old_score: number;
new_score: number;
username: string;
avatar: string;
};
}

type NotificationCommentVoteData = {
content_type: ContentType;
comment_reference: string;
comment_depth: number;
comment_text: string;
base_comment_reference: string;
} & NotificationVoteData;

type NotificationEditData = {
description: string;
Expand Down Expand Up @@ -371,6 +375,7 @@ declare global {
| NotificationEditData
| NotificationHikkaData
| NotificationScheduleAnimeData
| NotificationVoteData
| NotificationFollowData = NotificationCommentData,
> = {
notification_type: NotificationType;
Expand Down
28 changes: 28 additions & 0 deletions utils/convertNotification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const TITLES: Record<API.NotificationType, string> = {
hikka_update: 'Hikka',
schedule_anime: 'Новий епізод',
follow: 'Нова підписка',
collection_vote: 'Нова оцінка у колекції',
};

const DESCRIPTIONS: Record<
Expand Down Expand Up @@ -72,6 +73,11 @@ const DESCRIPTIONS: Record<
профіль
</>
),
collection_vote: (username: string) => (
<>
Користувач <span className="font-bold">@{username}</span> оцінив Вашу колекцію
</>
),
};

const ICONS: Record<API.NotificationType, ReactNode> = {
Expand All @@ -86,6 +92,7 @@ const ICONS: Record<API.NotificationType, ReactNode> = {
hikka_update: <MaterialSymbolsInfoRounded />,
schedule_anime: <MaterialSymbolsLiveTvRounded />,
follow: <MaterialSymbolsPersonAddRounded />,
collection_vote: <MaterialSymbolsFavoriteRounded />,
};

const getInitialData = (
Expand Down Expand Up @@ -236,6 +243,22 @@ const follow = (
};
};

const collectionVote = (
notification: API.Notification<API.NotificationVoteData>,
): Hikka.TextNotification => {
const { slug, username, avatar } =
notification.data;

return {
...getInitialData(notification),
description: DESCRIPTIONS[notification.notification_type](username),
href: `collections/${slug}`,
poster: (
<EntryCard containerRatio={1} className="w-10" poster={avatar} />
),
};
};

export const convertNotification = (
notification: API.Notification<
| API.NotificationCommentVoteData
Expand All @@ -244,6 +267,7 @@ export const convertNotification = (
| API.NotificationHikkaData
| API.NotificationScheduleAnimeData
| API.NotificationFollowData
| API.NotificationVoteData
>,
): Hikka.TextNotification => {
switch (notification.notification_type) {
Expand All @@ -255,6 +279,10 @@ export const convertNotification = (
return commentVote(
notification as API.Notification<API.NotificationCommentVoteData>,
);
case 'collection_vote':
return collectionVote(
notification as API.Notification<API.NotificationVoteData>,
);
case 'comment_tag':
return commentTag(
notification as API.Notification<API.NotificationCommentData>,
Expand Down

0 comments on commit 137b0b7

Please sign in to comment.