diff --git a/components/mod-event/EventItem.tsx b/components/mod-event/EventItem.tsx index 25d3230..eddee3d 100644 --- a/components/mod-event/EventItem.tsx +++ b/components/mod-event/EventItem.tsx @@ -11,6 +11,7 @@ import { ReasonBadge } from '@/reports/ReasonBadge' import { useConfigurationContext } from '@/shell/ConfigurationContext' import { ItemTitle } from './ItemTitle' import { PreviewCard } from '@/common/PreviewCard' +import { ModEventViewWithDetails } from './useModEventList' const LinkToAuthor = ({ creatorHandle, @@ -33,7 +34,7 @@ const LinkToAuthor = ({ const Comment = ({ modEvent, }: { - modEvent: ToolsOzoneModerationDefs.ModEventView & { + modEvent: ModEventViewWithDetails & { event: | ToolsOzoneModerationDefs.ModEventEscalate | ToolsOzoneModerationDefs.ModEventAcknowledge @@ -102,12 +103,19 @@ function isMessageSubject( return subject.messageId !== undefined } +type ModEventType = { event: T } & ToolsOzoneModerationDefs.ModEventView + +function isModEventType( + e: ToolsOzoneModerationDefs.ModEventView, + predicate: (event: unknown) => event is T, +): e is ModEventType { + return predicate(e.event) +} + const Report = ({ modEvent, }: { - modEvent: { - event: ToolsOzoneModerationDefs.ModEventReport - } & ToolsOzoneModerationDefs.ModEventView + modEvent: ModEventType }) => { const isAppeal = modEvent.event.reportType === ComAtprotoModerationDefs.REASONAPPEAL @@ -208,7 +216,7 @@ const EventLabels = ({ if (!labels?.length) return null return ( - + {header} {labels.map((label) => { if (isTag) { @@ -235,9 +243,7 @@ const EventLabels = ({ const Label = ({ modEvent, }: { - modEvent: { - event: ToolsOzoneModerationDefs.ModEventLabel - } & ToolsOzoneModerationDefs.ModEventView + modEvent: ModEventType }) => { return ( <> @@ -306,7 +312,7 @@ export const ModEventItem = ({ showContentAuthor, showContentPreview, }: { - modEvent: ToolsOzoneModerationDefs.ModEventView + modEvent: ModEventViewWithDetails showContentDetails: boolean showContentAuthor: boolean showContentPreview: boolean @@ -331,20 +337,16 @@ export const ModEventItem = ({ ) { eventItem = } - if (ToolsOzoneModerationDefs.isModEventReport(modEvent.event)) { - // @ts-ignore + if (isModEventType(modEvent, ToolsOzoneModerationDefs.isModEventReport)) { eventItem = } - if (ToolsOzoneModerationDefs.isModEventLabel(modEvent.event)) { - //@ts-ignore + if (isModEventType(modEvent, ToolsOzoneModerationDefs.isModEventLabel)) { eventItem =