Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(notify): reset circle animation on notification re-trigger with id #559

Merged
merged 3 commits into from
Apr 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions web/src/features/notifications/NotificationWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useNuiEvent } from '../../hooks/useNuiEvent';
import { toast, Toaster } from 'react-hot-toast';
import ReactMarkdown from 'react-markdown';
import { Box, Center, createStyles, Group, keyframes, RingProgress, Stack, Text, ThemeIcon } from '@mantine/core';
import React from 'react';
import React, { useRef } from 'react';
import tinycolor from 'tinycolor2';
import type { NotificationProps } from '../../typings';
import MarkdownComponents from '../../config/MarkdownComponents';
Expand Down Expand Up @@ -111,8 +111,13 @@ const durationCircle = keyframes({

const Notifications: React.FC = () => {
const { classes } = useStyles();
const toastKeyRef = useRef(0);

useNuiEvent<NotificationProps>('notify', (data) => {
const toastId = data.id?.toString();

if (toastId) toastKeyRef.current++;

if (!data.title && !data.description) return;

let iconColor: string;
Expand Down Expand Up @@ -190,6 +195,7 @@ const Notifications: React.FC = () => {
<>
{data.showDuration ? (
<RingProgress
key={toastKeyRef.current}
size={38}
thickness={2}
sections={[{ value: 100, color: iconColor }]}
Expand All @@ -201,7 +207,7 @@ const Notifications: React.FC = () => {
animationDuration: `${duration}ms`,
},
margin: -3,
}
},
}}
label={
<Center>
Expand All @@ -211,12 +217,7 @@ const Notifications: React.FC = () => {
size={32}
variant={tinycolor(iconColor).getAlpha() === 0 ? undefined : 'light'}
>
<LibIcon
icon={data.icon}
fixedWidth
color={iconColor}
animation={data.iconAnimation}
/>
<LibIcon icon={data.icon} fixedWidth color={iconColor} animation={data.iconAnimation} />
</ThemeIcon>
</Center>
}
Expand All @@ -229,12 +230,7 @@ const Notifications: React.FC = () => {
variant={tinycolor(iconColor).getAlpha() === 0 ? undefined : 'light'}
style={{ alignSelf: !data.alignIcon || data.alignIcon === 'center' ? 'center' : 'start' }}
>
<LibIcon
icon={data.icon}
fixedWidth
color={iconColor}
animation={data.iconAnimation}
/>
<LibIcon icon={data.icon} fixedWidth color={iconColor} animation={data.iconAnimation} />
</ThemeIcon>
)}
</>
Expand All @@ -254,7 +250,7 @@ const Notifications: React.FC = () => {
</Box>
),
{
id: data.id?.toString(),
id: toastId,
duration: duration,
position: position || 'top-right',
}
Expand Down