From 909f996dd8504db4451727a2c8999bcd7c788de0 Mon Sep 17 00:00:00 2001 From: Bill Date: Thu, 28 Jul 2022 01:23:22 -0400 Subject: [PATCH] Mod tool changes --- src/api/index.ts | 1 + .../mod-tools/GetIssueCategoryName.ts} | 6 +- .../common => api/mod-tools}/ISelectedUser.ts | 3 +- .../common => api/mod-tools}/IUserInfo.ts | 0 src/api/mod-tools/ModActionDefinition.ts | 49 ++++ src/api/mod-tools/index.ts | 4 + src/components/help/views/SelectTopicView.tsx | 8 +- src/components/mod-tools/ModToolsContext.tsx | 20 -- .../mod-tools/ModToolsMessageHandler.tsx | 258 ----------------- src/components/mod-tools/ModToolsView.tsx | 261 ++++++------------ .../mod-tools/common/GetCFHCategories.ts | 7 - .../mod-tools/common/ModActionDefinition.ts | 49 ---- .../mod-tools/reducers/ModToolsReducer.tsx | 105 ------- .../mod-tools/views/chatlog/ChatlogView.tsx | 12 +- .../views/room/ModToolsChatlogView.tsx | 8 +- .../mod-tools/views/room/ModToolsRoomView.tsx | 45 ++- .../views/tickets/CfhChatlogView.tsx | 22 +- .../views/tickets/ModToolsIssueInfoView.tsx | 23 +- .../views/tickets/ModToolsMyIssuesTabView.tsx | 10 +- .../tickets/ModToolsOpenIssuesTabView.tsx | 4 +- .../views/tickets/ModToolsTicketsView.tsx | 89 +++--- .../views/user/ModToolsUserChatlogView.tsx | 10 +- .../views/user/ModToolsUserModActionView.tsx | 21 +- .../views/user/ModToolsUserRoomVisitsView.tsx | 20 +- .../user/ModToolsUserSendMessageView.tsx | 13 +- .../mod-tools/views/user/ModToolsUserView.tsx | 27 +- src/components/toolbar/ToolbarView.tsx | 5 +- src/events/index.ts | 1 - src/events/mod-tools/ModToolsEvent.ts | 12 - .../mod-tools/ModToolsOpenRoomChatlogEvent.ts | 18 -- .../mod-tools/ModToolsOpenRoomInfoEvent.ts | 18 -- .../mod-tools/ModToolsOpenUserChatlogEvent.ts | 18 -- .../mod-tools/ModToolsOpenUserInfoEvent.ts | 18 -- src/events/mod-tools/index.ts | 5 - src/hooks/index.ts | 1 + src/hooks/mod-tools/index.ts | 1 + src/hooks/mod-tools/useModTools.ts | 207 ++++++++++++++ 37 files changed, 490 insertions(+), 889 deletions(-) rename src/{components/mod-tools/common/IssueCategoryNames.ts => api/mod-tools/GetIssueCategoryName.ts} (86%) rename src/{components/mod-tools/common => api/mod-tools}/ISelectedUser.ts (57%) rename src/{components/mod-tools/common => api/mod-tools}/IUserInfo.ts (100%) create mode 100644 src/api/mod-tools/ModActionDefinition.ts create mode 100644 src/api/mod-tools/index.ts delete mode 100644 src/components/mod-tools/ModToolsContext.tsx delete mode 100644 src/components/mod-tools/ModToolsMessageHandler.tsx delete mode 100644 src/components/mod-tools/common/GetCFHCategories.ts delete mode 100644 src/components/mod-tools/common/ModActionDefinition.ts delete mode 100644 src/components/mod-tools/reducers/ModToolsReducer.tsx delete mode 100644 src/events/mod-tools/ModToolsEvent.ts delete mode 100644 src/events/mod-tools/ModToolsOpenRoomChatlogEvent.ts delete mode 100644 src/events/mod-tools/ModToolsOpenRoomInfoEvent.ts delete mode 100644 src/events/mod-tools/ModToolsOpenUserChatlogEvent.ts delete mode 100644 src/events/mod-tools/ModToolsOpenUserInfoEvent.ts delete mode 100644 src/events/mod-tools/index.ts create mode 100644 src/hooks/mod-tools/index.ts create mode 100644 src/hooks/mod-tools/useModTools.ts diff --git a/src/api/index.ts b/src/api/index.ts index 58e6f4ca..af964444 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -13,6 +13,7 @@ export * from './guide-tool'; export * from './hc-center'; export * from './help'; export * from './inventory'; +export * from './mod-tools'; export * from './navigator'; export * from './nitro'; export * from './nitro/avatar'; diff --git a/src/components/mod-tools/common/IssueCategoryNames.ts b/src/api/mod-tools/GetIssueCategoryName.ts similarity index 86% rename from src/components/mod-tools/common/IssueCategoryNames.ts rename to src/api/mod-tools/GetIssueCategoryName.ts index bb1ca2c5..81a3f862 100644 --- a/src/components/mod-tools/common/IssueCategoryNames.ts +++ b/src/api/mod-tools/GetIssueCategoryName.ts @@ -1,4 +1,4 @@ -export const getSourceName = (categoryId: number): string => +export const GetIssueCategoryName = (categoryId: number) => { switch(categoryId) { @@ -29,7 +29,7 @@ export const getSourceName = (categoryId: number): string => return 'Photo'; case 15: return 'Ambassador'; - default: - return 'Unknown'; } + + return 'Unknown'; } diff --git a/src/components/mod-tools/common/ISelectedUser.ts b/src/api/mod-tools/ISelectedUser.ts similarity index 57% rename from src/components/mod-tools/common/ISelectedUser.ts rename to src/api/mod-tools/ISelectedUser.ts index c5a657a9..4f6e76b8 100644 --- a/src/components/mod-tools/common/ISelectedUser.ts +++ b/src/api/mod-tools/ISelectedUser.ts @@ -1,4 +1,5 @@ -export interface ISelectedUser { +export interface ISelectedUser +{ userId: number; username: string; } diff --git a/src/components/mod-tools/common/IUserInfo.ts b/src/api/mod-tools/IUserInfo.ts similarity index 100% rename from src/components/mod-tools/common/IUserInfo.ts rename to src/api/mod-tools/IUserInfo.ts diff --git a/src/api/mod-tools/ModActionDefinition.ts b/src/api/mod-tools/ModActionDefinition.ts new file mode 100644 index 00000000..b28aa9ce --- /dev/null +++ b/src/api/mod-tools/ModActionDefinition.ts @@ -0,0 +1,49 @@ +export class ModActionDefinition +{ + public static ALERT: number = 1; + public static MUTE: number = 2; + public static BAN: number = 3; + public static KICK: number = 4; + public static TRADE_LOCK: number = 5; + public static MESSAGE: number = 6; + + private readonly _actionId: number; + private readonly _name: string; + private readonly _actionType: number; + private readonly _sanctionTypeId: number; + private readonly _actionLengthHours: number; + + constructor(actionId: number, actionName: string, actionType: number, sanctionTypeId: number, actionLengthHours:number) + { + this._actionId = actionId; + this._name = actionName; + this._actionType = actionType; + this._sanctionTypeId = sanctionTypeId; + this._actionLengthHours = actionLengthHours; + } + + public get actionId(): number + { + return this._actionId; + } + + public get name(): string + { + return this._name; + } + + public get actionType(): number + { + return this._actionType; + } + + public get sanctionTypeId(): number + { + return this._sanctionTypeId; + } + + public get actionLengthHours(): number + { + return this._actionLengthHours; + } +} diff --git a/src/api/mod-tools/index.ts b/src/api/mod-tools/index.ts new file mode 100644 index 00000000..004bbaa3 --- /dev/null +++ b/src/api/mod-tools/index.ts @@ -0,0 +1,4 @@ +export * from './GetIssueCategoryName'; +export * from './ISelectedUser'; +export * from './IUserInfo'; +export * from './ModActionDefinition'; diff --git a/src/components/help/views/SelectTopicView.tsx b/src/components/help/views/SelectTopicView.tsx index f658f5cd..5dde522e 100644 --- a/src/components/help/views/SelectTopicView.tsx +++ b/src/components/help/views/SelectTopicView.tsx @@ -1,16 +1,14 @@ -import { FC, useMemo, useState } from 'react'; +import { FC, useState } from 'react'; import { LocalizeText, ReportState } from '../../../api'; import { Button, Column, Flex, Text } from '../../../common'; -import { useHelp } from '../../../hooks'; -import { GetCfhCategories } from '../../mod-tools/common/GetCFHCategories'; +import { useHelp, useModTools } from '../../../hooks'; export const SelectTopicView: FC<{}> = props => { const [ selectedCategory, setSelectedCategory ] = useState(-1); const [ selectedTopic, setSelectedTopic ] = useState(-1); const { setActiveReport = null } = useHelp(); - - const cfhCategories = useMemo(() => GetCfhCategories(), []); + const { cfhCategories = [] } = useModTools(); const submitTopic = () => { diff --git a/src/components/mod-tools/ModToolsContext.tsx b/src/components/mod-tools/ModToolsContext.tsx deleted file mode 100644 index 1ab06b4c..00000000 --- a/src/components/mod-tools/ModToolsContext.tsx +++ /dev/null @@ -1,20 +0,0 @@ -import { createContext, Dispatch, FC, ProviderProps, useContext } from 'react'; -import { IModToolsAction, IModToolsState } from './reducers/ModToolsReducer'; - -export interface IModToolsContext -{ - modToolsState: IModToolsState; - dispatchModToolsState: Dispatch; -} - -const ModToolsContext = createContext({ - modToolsState: null, - dispatchModToolsState: null -}); - -export const ModToolsContextProvider: FC> = props => -{ - return { props.children } -} - -export const useModToolsContext = () => useContext(ModToolsContext); diff --git a/src/components/mod-tools/ModToolsMessageHandler.tsx b/src/components/mod-tools/ModToolsMessageHandler.tsx deleted file mode 100644 index d9e76485..00000000 --- a/src/components/mod-tools/ModToolsMessageHandler.tsx +++ /dev/null @@ -1,258 +0,0 @@ -import { CfhSanctionMessageEvent, CfhTopicsInitEvent, IssueDeletedMessageEvent, IssueInfoMessageEvent, IssuePickFailedMessageEvent, ModeratorActionResultMessageEvent, ModeratorInitMessageEvent, ModeratorToolPreferencesEvent, RoomEngineEvent } from '@nitrots/nitro-renderer'; -import { FC, useCallback } from 'react'; -import { NotificationAlertType, PlaySound, SoundNames } from '../../api'; -import { ModToolsEvent, ModToolsOpenRoomChatlogEvent, ModToolsOpenRoomInfoEvent, ModToolsOpenUserChatlogEvent, ModToolsOpenUserInfoEvent } from '../../events'; -import { useMessageEvent, useNotification, useRoomEngineEvent, useUiEvent } from '../../hooks'; -import { SetCfhCategories } from './common/GetCFHCategories'; -import { useModToolsContext } from './ModToolsContext'; -import { ModToolsActions } from './reducers/ModToolsReducer'; - -export const ModToolsMessageHandler: FC<{}> = props => -{ - const { modToolsState = null, dispatchModToolsState = null } = useModToolsContext(); - const { openRooms = null, openRoomChatlogs = null, openUserChatlogs = null, openUserInfo = null, tickets= null } = modToolsState; - const { simpleAlert = null } = useNotification(); - - const onModeratorInitMessageEvent = useCallback((event: ModeratorInitMessageEvent) => - { - const parser = event.getParser(); - - if(!parser) return; - - const data = parser.data; - - dispatchModToolsState({ - type: ModToolsActions.SET_INIT_DATA, - payload: { - settings: data - } - }); - - dispatchModToolsState({ - type: ModToolsActions.SET_TICKETS, - payload: { - tickets: data.issues - } - }); - - }, [ dispatchModToolsState ]); - - const onIssueInfoMessageEvent = useCallback((event: IssueInfoMessageEvent) => - { - const parser = event.getParser(); - - if(!parser) return; - - const newTickets = tickets ? Array.from(tickets) : []; - const existingIndex = newTickets.findIndex( entry => entry.issueId === parser.issueData.issueId) - - if(existingIndex > -1) - { - newTickets[existingIndex] = parser.issueData; - } - else - { - newTickets.push(parser.issueData); - PlaySound(SoundNames.MODTOOLS_NEW_TICKET); - } - - dispatchModToolsState({ - type: ModToolsActions.SET_TICKETS, - payload: { - tickets: newTickets - } - }); - - }, [ dispatchModToolsState, tickets ]); - - const onModeratorToolPreferencesEvent = useCallback((event: ModeratorToolPreferencesEvent) => - { - const parser = event.getParser(); - - if(!parser) return; - - }, []); - - const onIssuePickFailedMessageEvent = useCallback((event: IssuePickFailedMessageEvent) => - { - const parser = event.getParser(); - - if(!parser) return; - - simpleAlert('Failed to pick issue', NotificationAlertType.DEFAULT, null, null, 'Error') - }, [ simpleAlert ]); - - const onIssueDeletedMessageEvent = useCallback((event: IssueDeletedMessageEvent) => - { - const parser = event.getParser(); - - if(!parser) return; - - const newTickets = tickets ? Array.from(tickets) : []; - const existingIndex = newTickets.findIndex( entry => entry.issueId === parser.issueId); - - if(existingIndex === -1) return; - - newTickets.splice(existingIndex, 1); - - dispatchModToolsState({ - type: ModToolsActions.SET_TICKETS, - payload: { - tickets: newTickets - } - }); - }, [ dispatchModToolsState, tickets ]); - - const onModeratorActionResultMessageEvent = useCallback((event: ModeratorActionResultMessageEvent) => - { - const parser = event.getParser(); - - if(!parser) return; - - if(parser.success) - { - simpleAlert('Moderation action was successfull', NotificationAlertType.MODERATION, null, null, 'Success'); - } - else - { - simpleAlert('There was a problem applying tht moderation action', NotificationAlertType.MODERATION, null, null, 'Error'); - } - }, [ simpleAlert ]); - - const onCfhTopicsInitEvent = useCallback((event: CfhTopicsInitEvent) => - { - const parser = event.getParser(); - - if(!parser) return; - - const categories = parser.callForHelpCategories; - - dispatchModToolsState({ - type: ModToolsActions.SET_CFH_CATEGORIES, - payload: { - cfhCategories: categories - } - }); - - SetCfhCategories(categories); - - }, [ dispatchModToolsState ]); - - const onCfhSanctionMessageEvent = useCallback((event: CfhSanctionMessageEvent) => - { - const parser = event.getParser(); - - if(!parser) return; - - // todo: update sanction data - }, []); - - useMessageEvent(ModeratorInitMessageEvent, onModeratorInitMessageEvent); - useMessageEvent(IssueInfoMessageEvent, onIssueInfoMessageEvent); - useMessageEvent(ModeratorToolPreferencesEvent, onModeratorToolPreferencesEvent); - useMessageEvent(IssuePickFailedMessageEvent, onIssuePickFailedMessageEvent); - useMessageEvent(IssueDeletedMessageEvent, onIssueDeletedMessageEvent); - useMessageEvent(ModeratorActionResultMessageEvent, onModeratorActionResultMessageEvent); - useMessageEvent(CfhTopicsInitEvent, onCfhTopicsInitEvent); - useMessageEvent(CfhSanctionMessageEvent, onCfhSanctionMessageEvent); - - const onRoomEngineEvent = useCallback((event: RoomEngineEvent) => - { - switch(event.type) - { - case RoomEngineEvent.INITIALIZED: - dispatchModToolsState({ - type: ModToolsActions.SET_CURRENT_ROOM_ID, - payload: { - currentRoomId: event.roomId - } - }); - return; - case RoomEngineEvent.DISPOSED: - dispatchModToolsState({ - type: ModToolsActions.SET_CURRENT_ROOM_ID, - payload: { - currentRoomId: null - } - }); - return; - } - }, [ dispatchModToolsState ]); - - useRoomEngineEvent(RoomEngineEvent.INITIALIZED, onRoomEngineEvent); - useRoomEngineEvent(RoomEngineEvent.DISPOSED, onRoomEngineEvent); - - const onModToolsEvent = useCallback((event: ModToolsEvent) => - { - switch(event.type) - { - case ModToolsEvent.OPEN_ROOM_INFO: { - const castedEvent = (event as ModToolsOpenRoomInfoEvent); - - if(openRooms && openRooms.includes(castedEvent.roomId)) return; - - const rooms = openRooms || []; - - dispatchModToolsState({ - type: ModToolsActions.SET_OPEN_ROOMS, - payload: { - openRooms: [ ...rooms, castedEvent.roomId ] - } - }); - return; - } - case ModToolsEvent.OPEN_ROOM_CHATLOG: { - const castedEvent = (event as ModToolsOpenRoomChatlogEvent); - - if(openRoomChatlogs && openRoomChatlogs.includes(castedEvent.roomId)) return; - - const chatlogs = openRoomChatlogs || []; - - dispatchModToolsState({ - type: ModToolsActions.SET_OPEN_ROOM_CHATLOGS, - payload: { - openRoomChatlogs: [ ...chatlogs, castedEvent.roomId ] - } - }); - return; - } - case ModToolsEvent.OPEN_USER_INFO: { - const castedEvent = (event as ModToolsOpenUserInfoEvent); - - if(openUserInfo && openUserInfo.includes(castedEvent.userId)) return; - - const userInfo = openUserInfo || []; - - dispatchModToolsState({ - type: ModToolsActions.SET_OPEN_USERINFO, - payload: { - openUserInfo: [ ...userInfo, castedEvent.userId ] - } - }); - return; - } - case ModToolsEvent.OPEN_USER_CHATLOG: { - const castedEvent = (event as ModToolsOpenUserChatlogEvent); - - if(openUserChatlogs && openUserChatlogs.includes(castedEvent.userId)) return; - - const userChatlog = openUserChatlogs || []; - - dispatchModToolsState({ - type: ModToolsActions.SET_OPEN_USER_CHATLOGS, - payload: { - openUserChatlogs: [ ...userChatlog, castedEvent.userId ] - } - }); - return; - } - } - }, [ openRooms, dispatchModToolsState, openRoomChatlogs, openUserInfo, openUserChatlogs ]); - - useUiEvent(ModToolsEvent.OPEN_ROOM_INFO, onModToolsEvent); - useUiEvent(ModToolsEvent.OPEN_ROOM_CHATLOG, onModToolsEvent); - useUiEvent(ModToolsEvent.OPEN_USER_INFO, onModToolsEvent); - useUiEvent(ModToolsEvent.OPEN_USER_CHATLOG, onModToolsEvent); - - return null; -} diff --git a/src/components/mod-tools/ModToolsView.tsx b/src/components/mod-tools/ModToolsView.tsx index e1d15b21..cfb9d35a 100644 --- a/src/components/mod-tools/ModToolsView.tsx +++ b/src/components/mod-tools/ModToolsView.tsx @@ -1,13 +1,8 @@ -import { RoomEngineObjectEvent, RoomObjectCategory, RoomObjectType } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useReducer, useRef, useState } from 'react'; -import { DispatchUiEvent, GetRoomSession } from '../../api'; +import { ILinkEventTracker, RoomEngineEvent, RoomId, RoomObjectCategory, RoomObjectType } from '@nitrots/nitro-renderer'; +import { FC, useEffect, useRef, useState } from 'react'; +import { AddEventLinkTracker, CreateLinkEvent, GetRoomSession, ISelectedUser, RemoveLinkEventTracker } from '../../api'; import { Base, Button, DraggableWindowPosition, NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../common'; -import { ModToolsEvent, ModToolsOpenRoomChatlogEvent, ModToolsOpenRoomInfoEvent, ModToolsOpenUserInfoEvent } from '../../events'; -import { useRoomEngineEvent, useUiEvent } from '../../hooks'; -import { ISelectedUser } from './common/ISelectedUser'; -import { ModToolsContextProvider } from './ModToolsContext'; -import { ModToolsMessageHandler } from './ModToolsMessageHandler'; -import { initialModTools, ModToolsActions, ModToolsReducer } from './reducers/ModToolsReducer'; +import { useModTools, useObjectSelectedEvent, useRoomEngineEvent } from '../../hooks'; import { ModToolsChatlogView } from './views/room/ModToolsChatlogView'; import { ModToolsRoomView } from './views/room/ModToolsRoomView'; import { ModToolsTicketsView } from './views/tickets/ModToolsTicketsView'; @@ -17,33 +12,31 @@ import { ModToolsUserView } from './views/user/ModToolsUserView'; export const ModToolsView: FC<{}> = props => { const [ isVisible, setIsVisible ] = useState(false); + const [ currentRoomId, setCurrentRoomId ] = useState(-1); const [ selectedUser, setSelectedUser ] = useState(null); const [ isTicketsVisible, setIsTicketsVisible ] = useState(false); - const [ modToolsState, dispatchModToolsState ] = useReducer(ModToolsReducer, initialModTools); - const { currentRoomId = null, openRooms = null, openRoomChatlogs = null, openUserChatlogs = null, openUserInfo = null } = modToolsState; + const { openRooms = [], openRoomChatlogs = [], openUserChatlogs = [], openUserInfos = [], openRoomInfo = null, closeRoomInfo = null, toggleRoomInfo = null, openRoomChatlog = null, closeRoomChatlog = null, toggleRoomChatlog = null, openUserInfo = null, closeUserInfo = null, toggleUserInfo = null, openUserChatlog = null, closeUserChatlog = null, toggleUserChatlog = null } = useModTools(); const elementRef = useRef(null); - const onModToolsEvent = useCallback((event: ModToolsEvent) => + useRoomEngineEvent([ + RoomEngineEvent.INITIALIZED, + RoomEngineEvent.DISPOSED + ], event => { + if(RoomId.isRoomPreviewerId(event.roomId)) return; + switch(event.type) { - case ModToolsEvent.SHOW_MOD_TOOLS: - setIsVisible(true); + case RoomEngineEvent.INITIALIZED: + setCurrentRoomId(event.roomId); return; - case ModToolsEvent.HIDE_MOD_TOOLS: - setIsVisible(false); - return; - case ModToolsEvent.TOGGLE_MOD_TOOLS: - setIsVisible(value => !value); + case RoomEngineEvent.DISPOSED: + setCurrentRoomId(-1); return; } - }, []); + }); - useUiEvent(ModToolsEvent.SHOW_MOD_TOOLS, onModToolsEvent); - useUiEvent(ModToolsEvent.HIDE_MOD_TOOLS, onModToolsEvent); - useUiEvent(ModToolsEvent.TOGGLE_MOD_TOOLS, onModToolsEvent); - - const onRoomEngineObjectEvent = useCallback((event: RoomEngineObjectEvent) => + useObjectSelectedEvent(event => { if(event.category !== RoomObjectCategory.UNIT) return; @@ -51,178 +44,104 @@ export const ModToolsView: FC<{}> = props => if(!roomSession) return; - const userData = roomSession.userDataManager.getUserDataByIndex(event.objectId); + const userData = roomSession.userDataManager.getUserDataByIndex(event.id); if(!userData || userData.type !== RoomObjectType.USER) return; setSelectedUser({ userId: userData.webID, username: userData.name }); - }, []); - - useRoomEngineEvent(RoomEngineObjectEvent.SELECTED, onRoomEngineObjectEvent); + }); - const handleClick = useCallback((action: string, value?: string) => + useEffect(() => { - if(!action) return; - - switch(action) - { - case 'toggle_room': { - if(!openRooms) + const linkTracker: ILinkEventTracker = { + linkReceived: (url: string) => + { + const parts = url.split('/'); + + if(parts.length < 2) return; + + switch(parts[1]) { - DispatchUiEvent(new ModToolsOpenRoomInfoEvent(currentRoomId)); - return; + case 'show': + setIsVisible(true); + return; + case 'hide': + setIsVisible(false); + return; + case 'toggle': + setIsVisible(prevValue => !prevValue); + return; + case 'open-room-info': + openRoomInfo(Number(parts[2])); + return; + case 'close-room-info': + closeRoomInfo(Number(parts[2])); + return; + case 'toggle-room-info': + toggleRoomInfo(Number(parts[2])); + return; + case 'open-room-chatlog': + openRoomChatlog(Number(parts[2])); + return; + case 'close-room-chatlog': + closeRoomChatlog(Number(parts[2])); + return; + case 'toggle-room-chatlog': + toggleRoomChatlog(Number(parts[2])); + return; + case 'open-user-info': + openUserInfo(Number(parts[2])); + return; + case 'close-user-info': + closeUserInfo(Number(parts[2])); + return; + case 'toggle-user-info': + toggleUserInfo(Number(parts[2])); + return; + case 'open-user-chatlog': + openUserChatlog(Number(parts[2])); + return; + case 'close-user-chatlog': + closeUserChatlog(Number(parts[2])); + return; + case 'toggle-user-chatlog': + toggleUserChatlog(Number(parts[2])); + return; } + }, + eventUrlPrefix: 'mod-tools/' + }; - if(openRooms.indexOf(currentRoomId) > -1) - { - handleClick('close_room', currentRoomId.toString()); - } - else - { - DispatchUiEvent(new ModToolsOpenRoomInfoEvent(currentRoomId)); - } - return; - } - case 'close_room': { - const itemIndex = openRooms.indexOf(Number(value)); + AddEventLinkTracker(linkTracker); - const clone = Array.from(openRooms); - clone.splice(itemIndex, 1); - - dispatchModToolsState({ - type: ModToolsActions.SET_OPEN_ROOMS, - payload: { - openRooms: clone - } - }); - return; - } - case 'toggle_room_chatlog': { - if(!openRoomChatlogs) - { - DispatchUiEvent(new ModToolsOpenRoomChatlogEvent(currentRoomId)); - return; - } - - if(openRoomChatlogs.indexOf(currentRoomId) > -1) - { - handleClick('close_room_chatlog', currentRoomId.toString()); - } - else - { - DispatchUiEvent(new ModToolsOpenRoomChatlogEvent(currentRoomId)); - } - return; - } - case 'close_room_chatlog': { - const itemIndex = openRoomChatlogs.indexOf(Number(value)); - - const clone = Array.from(openRoomChatlogs); - clone.splice(itemIndex, 1); - - dispatchModToolsState({ - type: ModToolsActions.SET_OPEN_ROOM_CHATLOGS, - payload: { - openRoomChatlogs: clone - } - }); - return; - } - case 'toggle_user_info': { - - if(!selectedUser) return; - - const userId = selectedUser.userId; - - if(!openUserInfo) - { - DispatchUiEvent(new ModToolsOpenUserInfoEvent(userId)); - return; - } - - if(openUserInfo.indexOf(userId) > -1) - { - handleClick('close_user_info', userId.toString()); - } - else - { - DispatchUiEvent(new ModToolsOpenUserInfoEvent(userId)); - } - return; - } - case 'close_user_info': { - const itemIndex = openUserInfo.indexOf(Number(value)); - - const clone = Array.from(openUserInfo); - clone.splice(itemIndex, 1); - - dispatchModToolsState({ - type: ModToolsActions.SET_OPEN_USERINFO, - payload: { - openUserInfo: clone - } - }); - return; - } - case 'close_user_chatlog': { - const itemIndex = openUserChatlogs.indexOf(Number(value)); - - const clone = Array.from(openUserChatlogs); - clone.splice(itemIndex, 1); - - dispatchModToolsState({ - type: ModToolsActions.SET_OPEN_USER_CHATLOGS, - payload: { - openUserChatlogs: clone - } - }); - return; - } - } - }, [ openRooms, currentRoomId, openRoomChatlogs, selectedUser, openUserInfo, openUserChatlogs ]); + return () => RemoveLinkEventTracker(linkTracker); + }, [ openRoomInfo, closeRoomInfo, toggleRoomInfo, openRoomChatlog, closeRoomChatlog, toggleRoomChatlog, openUserInfo, closeUserInfo, toggleUserInfo, openUserChatlog, closeUserChatlog, toggleUserChatlog ]); return ( - - + <> { isVisible && setIsVisible(false) } /> - - - - } - { openRooms && openRooms.map(roomId => - { - return handleClick('close_room', roomId.toString()) } />; - }) - } - { openRoomChatlogs && openRoomChatlogs.map(roomId => - { - return handleClick('close_room_chatlog', roomId.toString()) } />; - }) - } - { openUserInfo && openUserInfo.map(userId => - { - return handleClick('close_user_info', userId.toString()) }/> - }) - } - { openUserChatlogs && openUserChatlogs.map(userId => - { - return handleClick('close_user_chatlog', userId.toString()) }/> - }) - } + { (openRooms.length > 0) && openRooms.map(roomId => CreateLinkEvent(`mod-tools/close-room-info/${ roomId }`) } />) } + { (openRoomChatlogs.length > 0) && openRoomChatlogs.map(roomId => CreateLinkEvent(`mod-tools/close-room-chatlog/${ roomId }`) } />) } + { (openUserInfos.length > 0) && openUserInfos.map(userId => CreateLinkEvent(`mod-tools/close-user-info/${ userId }`) }/>) } + { (openUserChatlogs.length > 0) && openUserChatlogs.map(userId => CreateLinkEvent(`mod-tools/close-user-chatlog/${ userId }`) }/>) } { isTicketsVisible && setIsTicketsVisible(false) } /> } - + ); } diff --git a/src/components/mod-tools/common/GetCFHCategories.ts b/src/components/mod-tools/common/GetCFHCategories.ts deleted file mode 100644 index a9e8a57f..00000000 --- a/src/components/mod-tools/common/GetCFHCategories.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { CallForHelpCategoryData } from '@nitrots/nitro-renderer'; - -let cfhCategories: CallForHelpCategoryData[] = []; - -export const SetCfhCategories = (categories: CallForHelpCategoryData[]) => (cfhCategories = categories); - -export const GetCfhCategories = () => cfhCategories; diff --git a/src/components/mod-tools/common/ModActionDefinition.ts b/src/components/mod-tools/common/ModActionDefinition.ts deleted file mode 100644 index b8318afa..00000000 --- a/src/components/mod-tools/common/ModActionDefinition.ts +++ /dev/null @@ -1,49 +0,0 @@ -export class ModActionDefinition -{ - public static ALERT:number = 1; - public static MUTE:number = 2; - public static BAN:number = 3; - public static KICK:number = 4; - public static TRADE_LOCK:number = 5; - public static MESSAGE:number = 6; - - private readonly _actionId:number; - private readonly _name:string; - private readonly _actionType:number; - private readonly _sanctionTypeId:number; - private readonly _actionLengthHours:number; - - constructor(actionId:number, actionName:string, actionType:number, sanctionTypeId:number, actionLengthHours:number) - { - this._actionId = actionId; - this._name = actionName; - this._actionType = actionType; - this._sanctionTypeId = sanctionTypeId; - this._actionLengthHours = actionLengthHours; - } - - public get actionId():number - { - return this._actionId; - } - - public get name():string - { - return this._name; - } - - public get actionType():number - { - return this._actionType; - } - - public get sanctionTypeId():number - { - return this._sanctionTypeId; - } - - public get actionLengthHours():number - { - return this._actionLengthHours; - } -} diff --git a/src/components/mod-tools/reducers/ModToolsReducer.tsx b/src/components/mod-tools/reducers/ModToolsReducer.tsx deleted file mode 100644 index b6fcf343..00000000 --- a/src/components/mod-tools/reducers/ModToolsReducer.tsx +++ /dev/null @@ -1,105 +0,0 @@ -import { CallForHelpCategoryData, IssueMessageData, ModeratorInitData } from '@nitrots/nitro-renderer'; -import { Reducer } from 'react'; - -export interface IModToolsState -{ - settings: ModeratorInitData; - currentRoomId: number; - openRooms: number[]; - openRoomChatlogs: number[]; - openUserInfo: number[]; - openUserChatlogs: number[]; - tickets: IssueMessageData[] - cfhCategories: CallForHelpCategoryData[]; -} - -export interface IModToolsAction -{ - type: string; - payload: { - settings?: ModeratorInitData; - currentRoomId?: number; - openRooms?: number[]; - openRoomChatlogs?: number[]; - openUserInfo?: number[]; - openUserChatlogs?: number[]; - tickets?: IssueMessageData[]; - cfhCategories?: CallForHelpCategoryData[]; - } -} - -export class ModToolsActions -{ - public static SET_INIT_DATA: string = 'MTA_SET_INIT_DATA'; - public static SET_CURRENT_ROOM_ID: string = 'MTA_SET_CURRENT_ROOM_ID'; - public static SET_OPEN_ROOMS: string = 'MTA_SET_OPEN_ROOMS'; - public static SET_OPEN_USERINFO: string = 'MTA_SET_OPEN_USERINFO'; - public static SET_OPEN_ROOM_CHATLOGS: string = 'MTA_SET_OPEN_CHATLOGS'; - public static SET_OPEN_USER_CHATLOGS: string = 'MTA_SET_OPEN_USER_CHATLOGS'; - public static SET_TICKETS: string = 'MTA_SET_TICKETS'; - public static SET_CFH_CATEGORIES: string = 'MTA_SET_CFH_CATEGORIES'; - public static RESET_STATE: string = 'MTA_RESET_STATE'; -} - -export const initialModTools: IModToolsState = { - settings: null, - currentRoomId: null, - openRooms: null, - openRoomChatlogs: null, - openUserChatlogs: null, - openUserInfo: null, - tickets: null, - cfhCategories: null -}; - -export const ModToolsReducer: Reducer = (state, action) => -{ - switch(action.type) - { - case ModToolsActions.SET_INIT_DATA: { - const settings = (action.payload.settings || state.settings || null); - - return { ...state, settings }; - } - case ModToolsActions.SET_CURRENT_ROOM_ID: { - const currentRoomId = (action.payload.currentRoomId || state.currentRoomId || null); - - return { ...state, currentRoomId }; - } - case ModToolsActions.SET_OPEN_ROOMS: { - const openRooms = (action.payload.openRooms || state.openRooms || null); - - return { ...state, openRooms }; - } - case ModToolsActions.SET_OPEN_USERINFO: { - const openUserInfo = (action.payload.openUserInfo || state.openUserInfo || null); - - return { ...state, openUserInfo }; - } - case ModToolsActions.SET_OPEN_ROOM_CHATLOGS: { - const openRoomChatlogs = (action.payload.openRoomChatlogs || state.openRoomChatlogs || null); - - return { ...state, openRoomChatlogs }; - } - case ModToolsActions.SET_OPEN_USER_CHATLOGS: { - const openUserChatlogs = (action.payload.openUserChatlogs || state.openUserChatlogs || null); - - return { ...state, openUserChatlogs }; - } - case ModToolsActions.SET_TICKETS: { - const tickets = (action.payload.tickets || state.tickets || null); - - return { ...state, tickets }; - } - case ModToolsActions.SET_CFH_CATEGORIES: { - const cfhCategories = (action.payload.cfhCategories || state.cfhCategories || null); - - return { ...state, cfhCategories }; - } - case ModToolsActions.RESET_STATE: { - return { ...initialModTools }; - } - default: - return state; - } -} diff --git a/src/components/mod-tools/views/chatlog/ChatlogView.tsx b/src/components/mod-tools/views/chatlog/ChatlogView.tsx index 114c0da5..58a57c6d 100644 --- a/src/components/mod-tools/views/chatlog/ChatlogView.tsx +++ b/src/components/mod-tools/views/chatlog/ChatlogView.tsx @@ -1,10 +1,9 @@ import { ChatRecordData } from '@nitrots/nitro-renderer'; import { CSSProperties, FC, Key, useCallback } from 'react'; import { AutoSizer, CellMeasurer, CellMeasurerCache, List, ListRowProps } from 'react-virtualized'; -import { DispatchUiEvent, TryVisitRoom } from '../../../../api'; +import { CreateLinkEvent, TryVisitRoom } from '../../../../api'; import { Base, Button, Column, Flex, Grid, Text } from '../../../../common'; -import { ModToolsOpenUserInfoEvent } from '../../../../events'; -import { ModToolsOpenRoomInfoEvent } from '../../../../events/mod-tools/ModToolsOpenRoomInfoEvent'; +import { useModTools } from '../../../../hooks'; interface ChatlogViewProps { @@ -14,6 +13,7 @@ interface ChatlogViewProps export const ChatlogView: FC = props => { const { records = null } = props; + const { openRoomInfo = null } = useModTools(); const rowRenderer = (props: ListRowProps) => { @@ -29,7 +29,7 @@ export const ChatlogView: FC = props => > { chatlogEntry.timestamp } - DispatchUiEvent(new ModToolsOpenUserInfoEvent(chatlogEntry.userId)) }>{ chatlogEntry.userName } + CreateLinkEvent(`mod-tools/open-user-info/${ chatlogEntry.userId }`) }>{ chatlogEntry.userName } { chatlogEntry.message } @@ -79,7 +79,7 @@ export const ChatlogView: FC = props => { !isRoomInfo && { chatlogEntry.timestamp } - DispatchUiEvent(new ModToolsOpenUserInfoEvent(chatlogEntry.userId)) }>{ chatlogEntry.userName } + CreateLinkEvent(`mod-tools/open-user-info/${ chatlogEntry.userId }`) }>{ chatlogEntry.userName } { chatlogEntry.message } } @@ -109,7 +109,7 @@ export const ChatlogView: FC = props => - + ); diff --git a/src/components/mod-tools/views/room/ModToolsChatlogView.tsx b/src/components/mod-tools/views/room/ModToolsChatlogView.tsx index e85528a9..f9ea05e1 100644 --- a/src/components/mod-tools/views/room/ModToolsChatlogView.tsx +++ b/src/components/mod-tools/views/room/ModToolsChatlogView.tsx @@ -1,5 +1,5 @@ import { ChatRecordData, GetRoomChatlogMessageComposer, RoomChatlogEvent } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useState } from 'react'; +import { FC, useEffect, useState } from 'react'; import { SendMessageComposer } from '../../../../api'; import { DraggableWindowPosition, NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../../../common'; import { useMessageEvent } from '../../../../hooks'; @@ -16,16 +16,14 @@ export const ModToolsChatlogView: FC = props => const { roomId = null, onCloseClick = null } = props; const [ roomChatlog, setRoomChatlog ] = useState(null); - const onModtoolRoomChatlogEvent = useCallback((event: RoomChatlogEvent) => + useMessageEvent(RoomChatlogEvent, event => { const parser = event.getParser(); if(!parser || parser.data.roomId !== roomId) return; setRoomChatlog(parser.data); - }, [ roomId ]); - - useMessageEvent(RoomChatlogEvent, onModtoolRoomChatlogEvent); + }); useEffect(() => { diff --git a/src/components/mod-tools/views/room/ModToolsRoomView.tsx b/src/components/mod-tools/views/room/ModToolsRoomView.tsx index d7b6e607..f5c86dc2 100644 --- a/src/components/mod-tools/views/room/ModToolsRoomView.tsx +++ b/src/components/mod-tools/views/room/ModToolsRoomView.tsx @@ -1,8 +1,7 @@ import { GetModeratorRoomInfoMessageComposer, ModerateRoomMessageComposer, ModeratorActionMessageComposer, ModeratorRoomInfoEvent } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useState } from 'react'; -import { DispatchUiEvent, SendMessageComposer, TryVisitRoom } from '../../../../api'; +import { FC, useEffect, useState } from 'react'; +import { CreateLinkEvent, SendMessageComposer, TryVisitRoom } from '../../../../api'; import { Button, Column, DraggableWindowPosition, Flex, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../../common'; -import { ModToolsOpenRoomChatlogEvent } from '../../../../events/mod-tools/ModToolsOpenRoomChatlogEvent'; import { useMessageEvent } from '../../../../hooks'; interface ModToolsRoomViewProps @@ -14,39 +13,19 @@ interface ModToolsRoomViewProps export const ModToolsRoomView: FC = props => { const { roomId = null, onCloseClick = null } = props; - const [ infoRequested, setInfoRequested ] = useState(false); const [ loadedRoomId, setLoadedRoomId ] = useState(null); - const [ name, setName ] = useState(null); const [ ownerId, setOwnerId ] = useState(null); const [ ownerName, setOwnerName ] = useState(null); const [ ownerInRoom, setOwnerInRoom ] = useState(false); const [ usersInRoom, setUsersInRoom ] = useState(0); - - //form data const [ kickUsers, setKickUsers ] = useState(false); const [ lockRoom, setLockRoom ] = useState(false); const [ changeRoomName, setChangeRoomName ] = useState(false); const [ message, setMessage ] = useState(''); - const onModtoolRoomInfoEvent = useCallback((event: ModeratorRoomInfoEvent) => - { - const parser = event.getParser(); - - if(!parser || parser.data.flatId !== roomId) return; - - setLoadedRoomId(parser.data.flatId); - setName(parser.data.room.name); - setOwnerId(parser.data.ownerId); - setOwnerName(parser.data.ownerName); - setOwnerInRoom(parser.data.ownerInRoom); - setUsersInRoom(parser.data.userCount); - }, [ roomId ]); - - useMessageEvent(ModeratorRoomInfoEvent, onModtoolRoomInfoEvent); - - const handleClick = useCallback((action: string, value?: string) => + const handleClick = (action: string, value?: string) => { if(!action) return; @@ -65,7 +44,21 @@ export const ModToolsRoomView: FC = props => SendMessageComposer(new ModerateRoomMessageComposer(roomId, lockRoom ? 1 : 0, changeRoomName ? 1 : 0, kickUsers ? 1 : 0)); return; } - }, [ changeRoomName, kickUsers, lockRoom, message, roomId ]); + } + + useMessageEvent(ModeratorRoomInfoEvent, event => + { + const parser = event.getParser(); + + if(!parser || parser.data.flatId !== roomId) return; + + setLoadedRoomId(parser.data.flatId); + setName(parser.data.room.name); + setOwnerId(parser.data.ownerId); + setOwnerName(parser.data.ownerName); + setOwnerInRoom(parser.data.ownerInRoom); + setUsersInRoom(parser.data.userCount); + }); useEffect(() => { @@ -96,7 +89,7 @@ export const ModToolsRoomView: FC = props => - + diff --git a/src/components/mod-tools/views/tickets/CfhChatlogView.tsx b/src/components/mod-tools/views/tickets/CfhChatlogView.tsx index 0409f059..c8bdd7b1 100644 --- a/src/components/mod-tools/views/tickets/CfhChatlogView.tsx +++ b/src/components/mod-tools/views/tickets/CfhChatlogView.tsx @@ -1,5 +1,5 @@ import { CfhChatlogData, CfhChatlogEvent, GetCfhChatlogMessageComposer } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useState } from 'react'; +import { FC, useEffect, useState } from 'react'; import { SendMessageComposer } from '../../../../api'; import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../../../common'; import { useMessageEvent } from '../../../../hooks'; @@ -16,22 +16,20 @@ export const CfhChatlogView: FC = props => const { onCloseClick = null, issueId = null } = props; const [ chatlogData, setChatlogData ] = useState(null); + useMessageEvent(CfhChatlogEvent, event => + { + const parser = event.getParser(); + + if(!parser || parser.data.issueId !== issueId) return; + + setChatlogData(parser.data); + }); + useEffect(() => { SendMessageComposer(new GetCfhChatlogMessageComposer(issueId)); }, [ issueId ]); - const onCfhChatlogEvent = useCallback((event: CfhChatlogEvent) => - { - const parser = event.getParser(); - - if(!parser || parser.data.issueId !== issueId) return; - - setChatlogData(parser.data); - }, [ issueId ]); - - useMessageEvent(CfhChatlogEvent, onCfhChatlogEvent); - return ( diff --git a/src/components/mod-tools/views/tickets/ModToolsIssueInfoView.tsx b/src/components/mod-tools/views/tickets/ModToolsIssueInfoView.tsx index 21dfbd13..1179d417 100644 --- a/src/components/mod-tools/views/tickets/ModToolsIssueInfoView.tsx +++ b/src/components/mod-tools/views/tickets/ModToolsIssueInfoView.tsx @@ -1,10 +1,8 @@ import { CloseIssuesMessageComposer, ReleaseIssuesMessageComposer } from '@nitrots/nitro-renderer'; -import { FC, useMemo, useState } from 'react'; -import { DispatchUiEvent, LocalizeText, SendMessageComposer } from '../../../../api'; +import { FC, useState } from 'react'; +import { GetIssueCategoryName, LocalizeText, SendMessageComposer } from '../../../../api'; import { Button, Column, Grid, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../../common'; -import { ModToolsOpenUserInfoEvent } from '../../../../events'; -import { getSourceName } from '../../common/IssueCategoryNames'; -import { useModToolsContext } from '../../ModToolsContext'; +import { useModTools } from '../../../../hooks'; import { CfhChatlogView } from './CfhChatlogView'; interface IssueInfoViewProps @@ -16,16 +14,9 @@ interface IssueInfoViewProps export const ModToolsIssueInfoView: FC = props => { const { issueId = null, onIssueInfoClosed = null } = props; - const { modToolsState = null } = useModToolsContext(); - const { tickets = null } = modToolsState; const [ cfhChatlogOpen, setcfhChatlogOpen ] = useState(false); - - const ticket = useMemo(() => - { - if(!tickets || !tickets.length) return null; - - return tickets.find(issue => issue.issueId === issueId); - }, [ issueId, tickets ]); + const { tickets = [], openUserInfo = null } = useModTools(); + const ticket = tickets.find(issue => (issue.issueId === issueId)); const releaseIssue = (issueId: number) => { @@ -40,8 +31,6 @@ export const ModToolsIssueInfoView: FC = props => onIssueInfoClosed(issueId) } - - const openUserInfo = (userId: number) => DispatchUiEvent(new ModToolsOpenUserInfoEvent(userId)); return ( <> @@ -55,7 +44,7 @@ export const ModToolsIssueInfoView: FC = props => Source - { getSourceName(ticket.categoryId) } + { GetIssueCategoryName(ticket.categoryId) } Category diff --git a/src/components/mod-tools/views/tickets/ModToolsMyIssuesTabView.tsx b/src/components/mod-tools/views/tickets/ModToolsMyIssuesTabView.tsx index 2db159b8..2e1827a4 100644 --- a/src/components/mod-tools/views/tickets/ModToolsMyIssuesTabView.tsx +++ b/src/components/mod-tools/views/tickets/ModToolsMyIssuesTabView.tsx @@ -6,14 +6,12 @@ import { Base, Button, Column, Grid } from '../../../../common'; interface ModToolsMyIssuesTabViewProps { myIssues: IssueMessageData[]; - onIssueHandleClick(issueId: number): void; + handleIssue: (issueId: number) => void; } export const ModToolsMyIssuesTabView: FC = props => { - const { myIssues = null, onIssueHandleClick = null } = props; - - const onReleaseIssue = (issueId: number) => SendMessageComposer(new ReleaseIssuesMessageComposer([ issueId ])); + const { myIssues = null, handleIssue = null } = props; return ( @@ -35,10 +33,10 @@ export const ModToolsMyIssuesTabView: FC = props = { issue.reportedUserName } { new Date(Date.now() - issue.issueAgeInMilliseconds).toLocaleTimeString() } - + - + ); diff --git a/src/components/mod-tools/views/tickets/ModToolsOpenIssuesTabView.tsx b/src/components/mod-tools/views/tickets/ModToolsOpenIssuesTabView.tsx index c328025b..6ee23cd5 100644 --- a/src/components/mod-tools/views/tickets/ModToolsOpenIssuesTabView.tsx +++ b/src/components/mod-tools/views/tickets/ModToolsOpenIssuesTabView.tsx @@ -12,8 +12,6 @@ export const ModToolsOpenIssuesTabView: FC = pro { const { openIssues = null } = props; - const onPickIssue = (issueId: number) => SendMessageComposer(new PickIssuesMessageComposer([ issueId ], false, 0, 'pick issue button')); - return ( @@ -33,7 +31,7 @@ export const ModToolsOpenIssuesTabView: FC = pro { issue.reportedUserName } { new Date(Date.now() - issue.issueAgeInMilliseconds).toLocaleTimeString() } - + ); diff --git a/src/components/mod-tools/views/tickets/ModToolsTicketsView.tsx b/src/components/mod-tools/views/tickets/ModToolsTicketsView.tsx index b7c00967..d6597dad 100644 --- a/src/components/mod-tools/views/tickets/ModToolsTicketsView.tsx +++ b/src/components/mod-tools/views/tickets/ModToolsTicketsView.tsx @@ -1,8 +1,8 @@ import { IssueMessageData } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useMemo, useState } from 'react'; +import { FC, useState } from 'react'; import { GetSessionDataManager } from '../../../../api'; import { NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../../../common'; -import { useModToolsContext } from '../../ModToolsContext'; +import { useModTools } from '../../../../hooks'; import { ModToolsIssueInfoView } from './ModToolsIssueInfoView'; import { ModToolsMyIssuesTabView } from './ModToolsMyIssuesTabView'; import { ModToolsOpenIssuesTabView } from './ModToolsOpenIssuesTabView'; @@ -22,67 +22,52 @@ const TABS: string[] = [ export const ModToolsTicketsView: FC = props => { const { onCloseClick = null } = props; - const { modToolsState = null } = useModToolsContext(); - const { tickets= null } = modToolsState; const [ currentTab, setCurrentTab ] = useState(0); const [ issueInfoWindows, setIssueInfoWindows ] = useState([]); + const { tickets = [] } = useModTools(); - const openIssues = useMemo(() => + const openIssues = tickets.filter(issue => issue.state === IssueMessageData.STATE_OPEN); + const myIssues = tickets.filter(issue => (issue.state === IssueMessageData.STATE_PICKED) && (issue.pickerUserId === GetSessionDataManager().userId)); + const pickedIssues = tickets.filter(issue => issue.state === IssueMessageData.STATE_PICKED); + + const closeIssue = (issueId: number) => { - if(!tickets) return []; - - return tickets.filter(issue => issue.state === IssueMessageData.STATE_OPEN); - }, [ tickets ]); - - const myIssues = useMemo(() => - { - if(!tickets) return []; - - return tickets.filter(issue => (issue.state === IssueMessageData.STATE_PICKED) && (issue.pickerUserId === GetSessionDataManager().userId)); - }, [ tickets ]); - - const pickedIssues = useMemo(() => - { - if(!tickets) return []; - - return tickets.filter(issue => issue.state === IssueMessageData.STATE_PICKED); - }, [ tickets ]); - - const onIssueInfoClosed = useCallback((issueId: number) => - { - const indexOfValue = issueInfoWindows.indexOf(issueId); - - if(indexOfValue === -1) return; - - const newValues = Array.from(issueInfoWindows); - newValues.splice(indexOfValue, 1); - setIssueInfoWindows(newValues); - }, [ issueInfoWindows ]); - - const onIssueHandleClicked = useCallback((issueId: number) => - { - if(issueInfoWindows.indexOf(issueId) === -1) + setIssueInfoWindows(prevValue => { - const newValues = Array.from(issueInfoWindows); - newValues.push(issueId); - setIssueInfoWindows(newValues); - } - else - { - onIssueInfoClosed(issueId); - } - }, [ issueInfoWindows, onIssueInfoClosed ]); + const newValue = [ ...prevValue ]; + const existingIndex = newValue.indexOf(issueId); - const CurrentTabComponent = useCallback(() => + if(existingIndex >= 0) newValue.splice(existingIndex, 1); + + return newValue; + }); + } + + const handleIssue = (issueId: number) => + { + setIssueInfoWindows(prevValue => + { + const newValue = [ ...prevValue ]; + const existingIndex = newValue.indexOf(issueId); + + if(existingIndex === -1) newValue.push(issueId); + else newValue.splice(existingIndex, 1); + + return newValue; + }) + } + + const CurrentTabComponent = () => { switch(currentTab) { case 0: return ; - case 1: return ; + case 1: return ; case 2: return ; - default: return null; } - }, [ currentTab, myIssues, onIssueHandleClicked, openIssues, pickedIssues ]); + + return null; + } return ( <> @@ -100,7 +85,7 @@ export const ModToolsTicketsView: FC = props => - { issueInfoWindows && (issueInfoWindows.length > 0) && issueInfoWindows.map(issueId => ) } + { issueInfoWindows && (issueInfoWindows.length > 0) && issueInfoWindows.map(issueId => ) } ); } diff --git a/src/components/mod-tools/views/user/ModToolsUserChatlogView.tsx b/src/components/mod-tools/views/user/ModToolsUserChatlogView.tsx index f2ab66eb..7bfb2e10 100644 --- a/src/components/mod-tools/views/user/ModToolsUserChatlogView.tsx +++ b/src/components/mod-tools/views/user/ModToolsUserChatlogView.tsx @@ -1,5 +1,5 @@ import { ChatRecordData, GetUserChatlogMessageComposer, UserChatlogEvent } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useState } from 'react'; +import { FC, useEffect, useState } from 'react'; import { SendMessageComposer } from '../../../../api'; import { DraggableWindowPosition, NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../../../common'; import { useMessageEvent } from '../../../../hooks'; @@ -16,8 +16,8 @@ export const ModToolsUserChatlogView: FC = props = const { userId = null, onCloseClick = null } = props; const [ userChatlog, setUserChatlog ] = useState(null); const [ username, setUsername ] = useState(null); - - const onModtoolUserChatlogEvent = useCallback((event: UserChatlogEvent) => + + useMessageEvent(UserChatlogEvent, event => { const parser = event.getParser(); @@ -25,9 +25,7 @@ export const ModToolsUserChatlogView: FC = props = setUsername(parser.data.username); setUserChatlog(parser.data.roomChatlogs); - }, [ userId ]); - - useMessageEvent(UserChatlogEvent, onModtoolUserChatlogEvent); + }); useEffect(() => { diff --git a/src/components/mod-tools/views/user/ModToolsUserModActionView.tsx b/src/components/mod-tools/views/user/ModToolsUserModActionView.tsx index b8235709..bd4c2d5d 100644 --- a/src/components/mod-tools/views/user/ModToolsUserModActionView.tsx +++ b/src/components/mod-tools/views/user/ModToolsUserModActionView.tsx @@ -1,11 +1,8 @@ import { CallForHelpTopicData, DefaultSanctionMessageComposer, ModAlertMessageComposer, ModBanMessageComposer, ModKickMessageComposer, ModMessageMessageComposer, ModMuteMessageComposer, ModTradingLockMessageComposer } from '@nitrots/nitro-renderer'; import { FC, useMemo, useState } from 'react'; -import { LocalizeText, NotificationAlertType, SendMessageComposer } from '../../../../api'; +import { ISelectedUser, LocalizeText, ModActionDefinition, NotificationAlertType, SendMessageComposer } from '../../../../api'; import { Button, Column, DraggableWindowPosition, Flex, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../../common'; -import { useNotification } from '../../../../hooks'; -import { ISelectedUser } from '../../common/ISelectedUser'; -import { ModActionDefinition } from '../../common/ModActionDefinition'; -import { useModToolsContext } from '../../ModToolsContext'; +import { useModTools, useNotification } from '../../../../hooks'; interface ModToolsUserModActionViewProps { @@ -34,8 +31,7 @@ export const ModToolsUserModActionView: FC = pro const [ selectedTopic, setSelectedTopic ] = useState(-1); const [ selectedAction, setSelectedAction ] = useState(-1); const [ message, setMessage ] = useState(''); - const { modToolsState = null } = useModToolsContext(); - const { cfhCategories = null, settings = null } = modToolsState; + const { cfhCategories = null, settings = null } = useModTools(); const { simpleAlert = null } = useNotification(); const topics = useMemo(() => @@ -53,19 +49,22 @@ export const ModToolsUserModActionView: FC = pro return values; }, [ cfhCategories ]); - const sendAlert = (message: string) => - { - simpleAlert(message, NotificationAlertType.DEFAULT, null, null, 'Error'); - } + const sendAlert = (message: string) => simpleAlert(message, NotificationAlertType.DEFAULT, null, null, 'Error'); const sendDefaultSanction = () => { let errorMessage: string = null; + const category = topics[selectedTopic]; + if(selectedTopic === -1) errorMessage = 'You must select a CFH topic'; + if(errorMessage) return sendAlert(errorMessage); + const messageOrDefault = (message.trim().length === 0) ? LocalizeText(`help.cfh.topic.${ category.id }`) : message; + SendMessageComposer(new DefaultSanctionMessageComposer(user.userId, selectedTopic, messageOrDefault)); + onCloseClick(); } diff --git a/src/components/mod-tools/views/user/ModToolsUserRoomVisitsView.tsx b/src/components/mod-tools/views/user/ModToolsUserRoomVisitsView.tsx index e53c3997..f3d9ac80 100644 --- a/src/components/mod-tools/views/user/ModToolsUserRoomVisitsView.tsx +++ b/src/components/mod-tools/views/user/ModToolsUserRoomVisitsView.tsx @@ -1,5 +1,5 @@ import { GetRoomVisitsMessageComposer, RoomVisitsData, RoomVisitsEvent } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useState } from 'react'; +import { FC, useEffect, useState } from 'react'; import { AutoSizer, List, ListRowProps } from 'react-virtualized'; import { SendMessageComposer, TryVisitRoom } from '../../../../api'; import { Base, Column, DraggableWindowPosition, Grid, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../../common'; @@ -16,16 +16,21 @@ export const ModToolsUserRoomVisitsView: FC = p const { userId = null, onCloseClick = null } = props; const [ roomVisitData, setRoomVisitData ] = useState(null); - const onModtoolReceivedRoomsUserEvent = useCallback((event: RoomVisitsEvent) => + useMessageEvent(RoomVisitsEvent, event => { const parser = event.getParser(); - if(!parser || (parser.data.userId !== userId)) return; + if(parser.data.userId !== userId) return; setRoomVisitData(parser.data); + }); + + useEffect(() => + { + SendMessageComposer(new GetRoomVisitsMessageComposer(userId)); }, [ userId ]); - useMessageEvent(RoomVisitsEvent, onModtoolReceivedRoomsUserEvent); + if(!userId) return null; const RowRenderer = (props: ListRowProps) => { @@ -40,13 +45,6 @@ export const ModToolsUserRoomVisitsView: FC = p ); } - useEffect(() => - { - SendMessageComposer(new GetRoomVisitsMessageComposer(userId)); - }, [ userId ]); - - if(!userId) return null; - return ( diff --git a/src/components/mod-tools/views/user/ModToolsUserSendMessageView.tsx b/src/components/mod-tools/views/user/ModToolsUserSendMessageView.tsx index 8f2b8dea..963b5820 100644 --- a/src/components/mod-tools/views/user/ModToolsUserSendMessageView.tsx +++ b/src/components/mod-tools/views/user/ModToolsUserSendMessageView.tsx @@ -1,9 +1,8 @@ import { ModMessageMessageComposer } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useState } from 'react'; -import { SendMessageComposer } from '../../../../api'; +import { FC, useState } from 'react'; +import { ISelectedUser, SendMessageComposer } from '../../../../api'; import { Button, DraggableWindowPosition, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../../common'; import { useNotification } from '../../../../hooks'; -import { ISelectedUser } from '../../common/ISelectedUser'; interface ModToolsUserSendMessageViewProps { @@ -17,7 +16,9 @@ export const ModToolsUserSendMessageView: FC = const [ message, setMessage ] = useState(''); const { simpleAlert = null } = useNotification(); - const sendMessage = useCallback(() => + if(!user) return null; + + const sendMessage = () => { if(message.trim().length === 0) { @@ -29,9 +30,7 @@ export const ModToolsUserSendMessageView: FC = SendMessageComposer(new ModMessageMessageComposer(user.userId, message, -999)); onCloseClick(); - }, [ message, user, onCloseClick, simpleAlert ]); - - if(!user) return null; + } return ( diff --git a/src/components/mod-tools/views/user/ModToolsUserView.tsx b/src/components/mod-tools/views/user/ModToolsUserView.tsx index c4d82ba1..4454a0c9 100644 --- a/src/components/mod-tools/views/user/ModToolsUserView.tsx +++ b/src/components/mod-tools/views/user/ModToolsUserView.tsx @@ -1,8 +1,7 @@ import { FriendlyTime, GetModeratorUserInfoMessageComposer, ModeratorUserInfoData, ModeratorUserInfoEvent } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useMemo, useState } from 'react'; -import { DispatchUiEvent, LocalizeText, SendMessageComposer } from '../../../../api'; +import { FC, useEffect, useMemo, useState } from 'react'; +import { CreateLinkEvent, LocalizeText, SendMessageComposer } from '../../../../api'; import { Button, Column, DraggableWindowPosition, Grid, NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../../../common'; -import { ModToolsOpenUserChatlogEvent } from '../../../../events'; import { useMessageEvent } from '../../../../hooks'; import { ModToolsUserModActionView } from './ModToolsUserModActionView'; import { ModToolsUserRoomVisitsView } from './ModToolsUserRoomVisitsView'; @@ -22,17 +21,6 @@ export const ModToolsUserView: FC = props => const [ modActionVisible, setModActionVisible ] = useState(false); const [ roomVisitsVisible, setRoomVisitsVisible ] = useState(false); - const onModtoolUserInfoEvent = useCallback((event: ModeratorUserInfoEvent) => - { - const parser = event.getParser(); - - if(!parser || parser.data.userId !== userId) return; - - setUserInfo(parser.data); - }, [ userId ]); - - useMessageEvent(ModeratorUserInfoEvent, onModtoolUserInfoEvent); - const userProperties = useMemo(() => { if(!userInfo) return null; @@ -98,6 +86,15 @@ export const ModToolsUserView: FC = props => ]; }, [ userInfo ]); + useMessageEvent(ModeratorUserInfoEvent, event => + { + const parser = event.getParser(); + + if(!parser || parser.data.userId !== userId) return; + + setUserInfo(parser.data); + }); + useEffect(() => { SendMessageComposer(new GetModeratorUserInfoMessageComposer(userId)); @@ -132,7 +129,7 @@ export const ModToolsUserView: FC = props => -