Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

Promote Featured Streams to a top-level admin sidebar item

Gabe Kangas75b1de548588
diff --git a/web/components/admin/MainLayout.tsx b/web/components/admin/MainLayout.tsx
index ec73ee4bdf..3dbd1318a8 100644
--- a/web/components/admin/MainLayout.tsx
+++ b/web/components/admin/MainLayout.tsx
@@ -3,7 +3,7 @@ import Link from 'next/link';
import Head from 'next/head';
import { differenceInSeconds } from 'date-fns';
import { useRouter } from 'next/router';
-import { Layout, Menu, Alert, Button, Space, Tooltip } from 'antd';
+import { Layout, Menu, Alert, Button, Space, Tooltip, Badge } from 'antd';
import { useTranslation } from 'next-export-i18n';
import classNames from 'classnames';
@@ -21,6 +21,7 @@ import { AlertMessageContext } from '../../utils/alert-message-context';
import { TextFieldWithSubmit } from './TextFieldWithSubmit';
import { TEXTFIELD_PROPS_STREAM_TITLE } from '../../utils/config-constants';
import { ComposeFederatedPost } from './ComposeFederatedPost';
+import { usePendingFeatureRequestCount } from '../../hooks/useFeatureRequests';
import { UpdateArgs } from '../../types/config-section';
import { FatalErrorStateModal } from '../modals/FatalErrorStateModal/FatalErrorStateModal';
@@ -74,6 +75,10 @@ const DownloadOutlined = dynamic(() => import('@ant-design/icons/DownloadOutline
ssr: false,
});
+const StarOutlined = dynamic(() => import('@ant-design/icons/StarOutlined'), {
+ ssr: false,
+});
+
const FediverseOutlined = dynamic(() => import('../../assets/images/icons/fediverse.svg'), {
ssr: false,
});
@@ -89,6 +94,9 @@ export const MainLayout: FC<MainLayoutProps> = ({ children }) => {
const { instanceDetails, chatDisabled, federation } = serverConfig;
const { enabled: federationEnabled } = federation;
+ // Drives the badge on the Featured Streams sidebar item.
+ const pendingFeatureRequestCount = usePendingFeatureRequestCount(federationEnabled);
+
const [currentStreamTitle, setCurrentStreamTitle] = useState('');
const [postModalDisplayed, setPostModalDisplayed] = useState(false);
@@ -250,10 +258,6 @@ export const MainLayout: FC<MainLayoutProps> = ({ children }) => {
label: <Link href="/admin/config-federation">Social</Link>,
key: '/admin/config-federation',
},
- {
- label: <Link href="/admin/config-featured">Featured</Link>,
- key: '/admin/config-featured',
- },
{
label: <Link href="/admin/config-notify">Notifications</Link>,
key: '/admin/config-notify',
@@ -288,6 +292,22 @@ export const MainLayout: FC<MainLayoutProps> = ({ children }) => {
</span>
),
},
+ federationEnabled && {
+ key: '/admin/config-featured',
+ label: (
+ <Link href="/admin/config-featured">
+ Featured Streams
+ {pendingFeatureRequestCount > 0 && (
+ <Badge
+ count={pendingFeatureRequestCount}
+ size="small"
+ style={{ marginInlineStart: 8 }}
+ />
+ )}
+ </Link>
+ ),
+ icon: <StarOutlined />,
+ },
{
key: 'configuration',
label: 'Configuration',
diff --git a/web/hooks/useFeatureRequests.tsx b/web/hooks/useFeatureRequests.tsx
index 517003f91c..8b1e637a45 100644
--- a/web/hooks/useFeatureRequests.tsx
+++ b/web/hooks/useFeatureRequests.tsx
@@ -25,6 +25,9 @@ export interface UseFeatureRequestsResult {
const API_FEATURE_REQUESTS = '/api/admin/federation/feature-requests';
const API_APPROVE_FOLLOWER = '/api/admin/followers/approve';
+// How often the sidebar badge re-checks for pending requests.
+const PENDING_REQUESTS_POLL_INTERVAL = 60_000;
+
// useFeatureRequests fetches pending requests from other servers to feature
// this stream and lets the admin approve or reject them. Approval reuses the
// follower-approval endpoint, which records the approval and returns the
@@ -89,3 +92,45 @@ export function useFeatureRequests(): UseFeatureRequestsResult {
return { requests, loading, approve, reject, refetch: fetchRequests };
}
+
+// usePendingFeatureRequestCount returns how many feature requests are waiting
+// for the admin to approve, polling so the sidebar badge stays current. It is
+// deliberately silent: a transient failure should never raise a toast from the
+// layout, and it does nothing while federation is disabled (the endpoint
+// requires it). Pass federationEnabled so the count clears and the polling
+// stops when federation is off.
+export function usePendingFeatureRequestCount(enabled: boolean): number {
+ const [count, setCount] = useState(0);
+
+ useEffect(() => {
+ if (!enabled) {
+ setCount(0);
+ return undefined;
+ }
+
+ let cancelled = false;
+ const load = async () => {
+ try {
+ const response = await fetch(API_FEATURE_REQUESTS, { credentials: 'include' });
+ if (!response.ok) {
+ return;
+ }
+ const data = await response.json();
+ if (!cancelled) {
+ setCount((data.requests || []).length);
+ }
+ } catch {
+ // Silent: the badge is a hint, not a place to surface fetch errors.
+ }
+ };
+
+ load();
+ const intervalId = setInterval(load, PENDING_REQUESTS_POLL_INTERVAL);
+ return () => {
+ cancelled = true;
+ clearInterval(intervalId);
+ };
+ }, [enabled]);
+
+ return count;
+}