mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-20 15:36:18 +00:00
Fix badge notification: single bubble, working Wear button
Block NotificationDialogMessageEvent badge types to prevent duplicate bubbles. Wrap bubble content in stopPropagation div so button clicks don't close the notification before toggleBadge runs. Request badge data on mount so Wear works even if inventory was never opened.
This commit is contained in:
+27
-7
@@ -1,5 +1,6 @@
|
|||||||
import { FC } from 'react';
|
import { RequestBadgesComposer } from '@nitrots/nitro-renderer';
|
||||||
import { LocalizeText, NotificationBubbleItem } from '../../../../api';
|
import { FC, useEffect } from 'react';
|
||||||
|
import { LocalizeText, NotificationBubbleItem, SendMessageComposer } from '../../../../api';
|
||||||
import { Flex, LayoutNotificationBubbleView, LayoutNotificationBubbleViewProps, Text } from '../../../../common';
|
import { Flex, LayoutNotificationBubbleView, LayoutNotificationBubbleViewProps, Text } from '../../../../common';
|
||||||
import { useInventoryBadges } from '../../../../hooks';
|
import { useInventoryBadges } from '../../../../hooks';
|
||||||
|
|
||||||
@@ -11,16 +12,34 @@ export interface NotificationBadgeReceivedBubbleViewProps extends LayoutNotifica
|
|||||||
export const NotificationBadgeReceivedBubbleView: FC<NotificationBadgeReceivedBubbleViewProps> = props =>
|
export const NotificationBadgeReceivedBubbleView: FC<NotificationBadgeReceivedBubbleViewProps> = props =>
|
||||||
{
|
{
|
||||||
const { item = null, onClose = null, ...rest } = props;
|
const { item = null, onClose = null, ...rest } = props;
|
||||||
const { toggleBadge = null } = useInventoryBadges();
|
const { badgeCodes = [], toggleBadge = null } = useInventoryBadges();
|
||||||
|
|
||||||
const handleWear = () =>
|
useEffect(() =>
|
||||||
{
|
{
|
||||||
if(item.linkUrl) toggleBadge(item.linkUrl);
|
if(badgeCodes.length === 0) SendMessageComposer(new RequestBadgesComposer());
|
||||||
onClose();
|
}, []);
|
||||||
|
|
||||||
|
const handleWear = (event: React.MouseEvent) =>
|
||||||
|
{
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
|
if(item.linkUrl)
|
||||||
|
{
|
||||||
|
toggleBadge(item.linkUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(onClose) onClose();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDismiss = (event: React.MouseEvent) =>
|
||||||
|
{
|
||||||
|
event.stopPropagation();
|
||||||
|
if(onClose) onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LayoutNotificationBubbleView className="flex-col" onClose={ onClose } { ...rest }>
|
<LayoutNotificationBubbleView className="flex-col" onClose={ onClose } { ...rest }>
|
||||||
|
<div onClick={ (e) => e.stopPropagation() }>
|
||||||
<Flex alignItems="center" gap={ 2 } className="mb-2">
|
<Flex alignItems="center" gap={ 2 } className="mb-2">
|
||||||
<Flex center className="w-[50px] h-[50px] shrink-0">
|
<Flex center className="w-[50px] h-[50px] shrink-0">
|
||||||
{ item.iconUrl && <img alt="" className="no-select" src={ item.iconUrl } /> }
|
{ item.iconUrl && <img alt="" className="no-select" src={ item.iconUrl } /> }
|
||||||
@@ -37,10 +56,11 @@ export const NotificationBadgeReceivedBubbleView: FC<NotificationBadgeReceivedBu
|
|||||||
onClick={ handleWear }>
|
onClick={ handleWear }>
|
||||||
{ LocalizeText('inventory.badges.wearbadge') }
|
{ LocalizeText('inventory.badges.wearbadge') }
|
||||||
</button>
|
</button>
|
||||||
<span className="underline cursor-pointer text-nowrap" onClick={ onClose }>
|
<span className="underline cursor-pointer text-nowrap" onClick={ handleDismiss }>
|
||||||
{ LocalizeText('notifications.button.later') }
|
{ LocalizeText('notifications.button.later') }
|
||||||
</span>
|
</span>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
</div>
|
||||||
</LayoutNotificationBubbleView>
|
</LayoutNotificationBubbleView>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -356,6 +356,9 @@ const useNotificationState = () =>
|
|||||||
{
|
{
|
||||||
const parser = event.getParser();
|
const parser = event.getParser();
|
||||||
|
|
||||||
|
// Skip badge notifications — handled by BadgeReceivedEvent with "Wear" button
|
||||||
|
if(parser.type === 'badge_received' || parser.type === 'badges' || parser.type.includes('badge')) return;
|
||||||
|
|
||||||
showNotification(parser.type, parser.parameters);
|
showNotification(parser.type, parser.parameters);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user