Skip to content

Commit

Permalink
feat(sidebar): show pending requests count in the sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
AkashRajpurohit committed Jan 6, 2025
1 parent f84d752 commit f3931da
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions server/interfaces/api/requestInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,14 @@ export type MediaRequestBody = {
userId?: number;
tags?: number[];
};

export type RequestCountResponse = {
total: number;
movie: number;
tv: number;
pending: number;
approved: number;
declined: number;
processing: number;
available: number;
};
24 changes: 24 additions & 0 deletions src/components/Layout/Sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Badge from '@app/components/Common/Badge';
import UserWarnings from '@app/components/Layout/UserWarnings';
import VersionStatus from '@app/components/Layout/VersionStatus';
import useClickOutside from '@app/hooks/useClickOutside';
Expand All @@ -15,11 +16,13 @@ import {
UsersIcon,
XMarkIcon,
} from '@heroicons/react/24/outline';
import type { RequestCountResponse } from '@server/interfaces/api/requestInterfaces';
import Image from 'next/image';
import Link from 'next/link';
import { useRouter } from 'next/router';
import { Fragment, useRef } from 'react';
import { useIntl } from 'react-intl';
import useSWR from 'swr';

export const menuMessages = defineMessages('components.Layout.Sidebar', {
dashboard: 'Discover',
Expand Down Expand Up @@ -119,6 +122,9 @@ const Sidebar = ({ open, setClosed }: SidebarProps) => {
const router = useRouter();
const intl = useIntl();
const { hasPermission } = useUser();
const { data: requests } = useSWR<RequestCountResponse>(
'/api/v1/request/count'
);
useClickOutside(navRef, () => setClosed());

return (
Expand Down Expand Up @@ -204,6 +210,15 @@ const Sidebar = ({ open, setClosed }: SidebarProps) => {
{intl.formatMessage(
menuMessages[sidebarLink.messagesKey]
)}
{sidebarLink.messagesKey === 'requests' &&
requests &&
requests.pending > 0 && (
<span className="ml-3">
<Badge badgeType="default">
{requests.pending}
</Badge>
</span>
)}
</Link>
);
})}
Expand Down Expand Up @@ -265,6 +280,15 @@ const Sidebar = ({ open, setClosed }: SidebarProps) => {
{intl.formatMessage(
menuMessages[sidebarLink.messagesKey]
)}
{sidebarLink.messagesKey === 'requests' &&
requests &&
requests.pending > 0 && (
<span className="ml-3">
<Badge badgeType="default">
{requests.pending}
</Badge>
</span>
)}
</Link>
);
})}
Expand Down

0 comments on commit f3931da

Please sign in to comment.