From 5af64e539dfbcc5aaeb8ed8c175b9fa6c924d712 Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Fri, 14 Feb 2025 15:02:26 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F(frontend)=20refactor=20toast?= =?UTF-8?q?=20selection=20to=20use=20a=20switch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit More extensible design. Still a poor piece of code. Technical debt here. --- .../notifications/components/ToastRegion.tsx | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/frontend/src/features/notifications/components/ToastRegion.tsx b/src/frontend/src/features/notifications/components/ToastRegion.tsx index 8351ab36..09ea4dad 100644 --- a/src/frontend/src/features/notifications/components/ToastRegion.tsx +++ b/src/frontend/src/features/notifications/components/ToastRegion.tsx @@ -1,5 +1,5 @@ import { AriaToastRegionProps, useToastRegion } from '@react-aria/toast' -import type { ToastState } from '@react-stately/toast' +import type { QueuedToast, ToastState } from '@react-stately/toast' import { Toast } from './Toast' import { useRef } from 'react' import { NotificationType } from '../NotificationType' @@ -14,31 +14,39 @@ interface ToastRegionProps extends AriaToastRegionProps { state: ToastState } +const renderToast = ( + toast: QueuedToast, + state: ToastState +) => { + switch (toast.content?.type) { + case NotificationType.ParticipantJoined: + return + + case NotificationType.HandRaised: + return + + case NotificationType.ParticipantMuted: + return + + case NotificationType.MessageReceived: + return ( + + ) + + case NotificationType.LowerHand: + return + + default: + return + } +} + export function ToastRegion({ state, ...props }: ToastRegionProps) { const ref = useRef(null) const { regionProps } = useToastRegion(props, state, ref) return (
- {state.visibleToasts.map((toast) => { - if (toast.content?.type === NotificationType.ParticipantJoined) { - return - } - if (toast.content?.type === NotificationType.HandRaised) { - return - } - if (toast.content?.type === NotificationType.ParticipantMuted) { - return - } - if (toast.content?.type === NotificationType.MessageReceived) { - return ( - - ) - } - if (toast.content?.type === NotificationType.LowerHand) { - return - } - return - })} + {state.visibleToasts.map((toast) => renderToast(toast, state))}
) }