From b70e828659a3a3c5734f86469c3f8e41b270984f Mon Sep 17 00:00:00 2001 From: dank074 Date: Sat, 13 Nov 2021 19:11:26 -0600 Subject: [PATCH] add my sanction status view --- src/views/help/HelpView.scss | 4 + src/views/help/HelpView.tsx | 2 + src/views/help/views/HelpIndexView.tsx | 13 +++- src/views/help/views/SanctionStatusView.tsx | 85 +++++++++++++++++++++ 4 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 src/views/help/views/SanctionStatusView.tsx diff --git a/src/views/help/HelpView.scss b/src/views/help/HelpView.scss index f7f513f8..b6ba7d76 100644 --- a/src/views/help/HelpView.scss +++ b/src/views/help/HelpView.scss @@ -8,3 +8,7 @@ height: 105px; } } + +.nitro-cfh-sanction-status { + width: 400px; +} diff --git a/src/views/help/HelpView.tsx b/src/views/help/HelpView.tsx index 630d41d1..9ebea6eb 100644 --- a/src/views/help/HelpView.tsx +++ b/src/views/help/HelpView.tsx @@ -9,6 +9,7 @@ import { IHelpReportState, initialReportState } from './context/HelpContext.type import { HelpMessageHandler } from './HelpMessageHandler'; import { DescribeReportView } from './views/DescribeReportView'; import { HelpIndexView } from './views/HelpIndexView'; +import { SanctionSatusView } from './views/SanctionStatusView'; import { SelectReportedChatsView } from './views/SelectReportedChatsView'; import { SelectReportedUserView } from './views/SelectReportedUserView'; import { SelectTopicView } from './views/SelectTopicView'; @@ -74,6 +75,7 @@ export const HelpView: FC<{}> = props => } + ); } diff --git a/src/views/help/views/HelpIndexView.tsx b/src/views/help/views/HelpIndexView.tsx index 35d85270..3f067047 100644 --- a/src/views/help/views/HelpIndexView.tsx +++ b/src/views/help/views/HelpIndexView.tsx @@ -1,5 +1,7 @@ +import { GetCfhStatusMessageComposer } from '@nitrots/nitro-renderer'; import { FC, useCallback } from 'react'; import { LocalizeText } from '../../../api'; +import { SendMessageHook } from '../../../hooks'; import { useHelpContext } from '../context/HelpContext'; export const HelpIndexView: FC<{}> = props => @@ -13,6 +15,11 @@ export const HelpIndexView: FC<{}> = props => setHelpReportState(reportState); },[helpReportState, setHelpReportState]); + const onRequestMySanctionStatusClick = useCallback(() => + { + SendMessageHook(new GetCfhStatusMessageComposer(false)); + }, []); + return ( <>
@@ -23,12 +30,12 @@ export const HelpIndexView: FC<{}> = props =>
- - + +
- +
diff --git a/src/views/help/views/SanctionStatusView.tsx b/src/views/help/views/SanctionStatusView.tsx new file mode 100644 index 00000000..d3ad0a70 --- /dev/null +++ b/src/views/help/views/SanctionStatusView.tsx @@ -0,0 +1,85 @@ +import { SanctionStatusEvent, SanctionStatusMessageParser } from '@nitrots/nitro-renderer'; +import { FC, useCallback, useState } from 'react'; +import { LocalizeText } from '../../../api'; +import { CreateMessageHook } from '../../../hooks'; +import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../../layout'; + +export const SanctionSatusView:FC<{}> = props => +{ + const [ sanctionInfo, setSanctionInfo ] = useState(null); + + const onSanctionStatusEvent = useCallback((event: SanctionStatusEvent) => + { + const parser = event.getParser(); + + if(!parser) return; + + setSanctionInfo(parser); + }, []); + + CreateMessageHook(SanctionStatusEvent, onSanctionStatusEvent); + + const sanctionLocalization = useCallback((param: string, sanctionName: string, length?: number) => + { + let localizationName = `help.sanction.${param}`; + + switch(sanctionName) + { + case 'ALERT': + localizationName = (localizationName + '.alert'); + break; + case 'MUTE': + localizationName = (localizationName + '.mute'); + break; + case 'BAN_PERMANENT': + localizationName = (localizationName + '.permban'); + break; + default: + localizationName = (localizationName + '.ban'); + if(length > 24) + { + localizationName = (localizationName + '.days'); + return LocalizeText(localizationName, ['days'], [(length / 24).toString()]); + } + } + + return LocalizeText(localizationName, ['hours'], [length.toString()]); + }, []); + + if(!sanctionInfo) return null; + + return ( + + setSanctionInfo(null)} /> + +
+ {(sanctionInfo.sanctionReason === 'cfh.reason.EMPTY') + ?
{LocalizeText('help.sanction.current.none')}
+ : <> + {((sanctionInfo.probationHoursLeft > 0) || (sanctionInfo.isSanctionActive)) && +
{LocalizeText('help.sanction.probation.reminder')}
+ } +
+ {LocalizeText('help.sanction.last.sanction')} {sanctionLocalization('current', sanctionInfo.sanctionName, sanctionInfo.sanctionLengthHours)} +
+
{LocalizeText('generic.start.time')} {sanctionInfo.sanctionCreationTime}
+
{LocalizeText('generic.reason')} {sanctionInfo.sanctionReason}
+
{LocalizeText('help.sanction.probation.days.left')} {Math.trunc((sanctionInfo.probationHoursLeft / 24)) + 1}
+ + } + { ((sanctionInfo.hasCustomMute) && (!(sanctionInfo.isSanctionActive))) && +
{LocalizeText('help.sanction.custom.mute')}
+ } + { (sanctionInfo.tradeLockExpiryTime && sanctionInfo.tradeLockExpiryTime.length > 0) && +
{LocalizeText('trade.locked.until')} {sanctionInfo.tradeLockExpiryTime}
+ } + +
{sanctionLocalization('next', sanctionInfo.nextSanctionName, sanctionInfo.nextSanctionLengthHours)}
+
+
+ +
+
+
+ ) +}