TelegramPWA/src/components/common/UnreadCounter.tsx
2025-06-04 20:41:58 +02:00

37 lines
1.0 KiB
TypeScript

import type { FC } from '../../lib/teact/teact';
import { memo, useEffect } from '../../lib/teact/teact';
import { updateAppBadge } from '../../util/appBadge';
import { getAllNotificationsCount } from '../../util/folderManager';
import { formatIntegerCompact } from '../../util/textFormat';
import { useFolderManagerForUnreadCounters } from '../../hooks/useFolderManager';
import useLang from '../../hooks/useLang';
interface OwnProps {
isForAppBadge?: boolean;
}
const UnreadCounter: FC<OwnProps> = ({ isForAppBadge }) => {
useFolderManagerForUnreadCounters();
const unreadNotificationsCount = getAllNotificationsCount();
const lang = useLang();
useEffect(() => {
if (isForAppBadge) {
updateAppBadge(unreadNotificationsCount);
}
}, [isForAppBadge, unreadNotificationsCount]);
if (isForAppBadge || !unreadNotificationsCount) {
return undefined;
}
return (
<div className="unread-count active">{formatIntegerCompact(lang, unreadNotificationsCount)}</div>
);
};
export default memo(UnreadCounter);