diff --git a/src/assets/images/help/help_index.png b/src/assets/images/help/help_index.png new file mode 100644 index 00000000..2844f41e Binary files /dev/null and b/src/assets/images/help/help_index.png differ diff --git a/src/events/help/HelpEvent.ts b/src/events/help/HelpEvent.ts new file mode 100644 index 00000000..1403f20f --- /dev/null +++ b/src/events/help/HelpEvent.ts @@ -0,0 +1,8 @@ +import { NitroEvent } from '@nitrots/nitro-renderer'; + +export class HelpEvent extends NitroEvent +{ + public static SHOW_HELP_CENTER: string = 'HCE_SHOW_HELP_CENTER'; + public static HIDE_HELP_CENTER: string = 'HCE_HIDE_HELP_CENTER'; + public static TOGGLE_HELP_CENTER: string = 'HCE_TOGGLE_HELP_CENTER'; +} diff --git a/src/events/help/HelpReportUserEvent.ts b/src/events/help/HelpReportUserEvent.ts new file mode 100644 index 00000000..4af418af --- /dev/null +++ b/src/events/help/HelpReportUserEvent.ts @@ -0,0 +1,27 @@ +import { HelpEvent } from './HelpEvent'; + +export class HelpReportUserEvent extends HelpEvent +{ + public static REPORT_USER: string = 'HCE_HELP_CENTER_REPORT_USER'; + + private _reportedUserId: number; + private _reportedUsername: string; + + constructor(userId: number, username: string) + { + super(HelpReportUserEvent.REPORT_USER); + + this._reportedUserId = userId; + this._reportedUsername = username; + } + + public get reportedUserId(): number + { + return this._reportedUserId; + } + + public get reportedUsername(): string + { + return this._reportedUsername; + } +} diff --git a/src/views/Styles.scss b/src/views/Styles.scss index f66d2a1a..77dc121f 100644 --- a/src/views/Styles.scss +++ b/src/views/Styles.scss @@ -21,3 +21,4 @@ @import './user-settings/UserSettingsView'; @import './user-profile/UserProfileVew'; @import './chat-history/ChatHistoryView'; +@import './help/HelpView'; diff --git a/src/views/chat-history/ChatHistoryMessageHandler.tsx b/src/views/chat-history/ChatHistoryMessageHandler.tsx index f56702a4..d1165d39 100644 --- a/src/views/chat-history/ChatHistoryMessageHandler.tsx +++ b/src/views/chat-history/ChatHistoryMessageHandler.tsx @@ -54,7 +54,7 @@ export const ChatHistoryMessageHandler: FC<{}> = props => const timeString = currentDate(); - const entry: IChatEntry = { id: -1, entityId: userData.webID, name: userData.name, look: userData.figure, message: event.message, timestamp: timeString, type: ChatEntryType.TYPE_CHAT }; + const entry: IChatEntry = { id: -1, entityId: userData.webID, name: userData.name, look: userData.figure, entityType: userData.type, message: event.message, timestamp: timeString, type: ChatEntryType.TYPE_CHAT, roomId: roomSession.roomId }; addChatEntry(entry); }, [addChatEntry]); @@ -89,7 +89,7 @@ export const ChatHistoryMessageHandler: FC<{}> = props => if(needsRoomInsert) { - const chatEntry: IChatEntry = { id: -1, entityId: parser.data.roomId, name: parser.data.roomName, timestamp: currentDate(), type: ChatEntryType.TYPE_ROOM_INFO }; + const chatEntry: IChatEntry = { id: -1, entityId: parser.data.roomId, name: parser.data.roomName, timestamp: currentDate(), type: ChatEntryType.TYPE_ROOM_INFO, roomId: parser.data.roomId }; addChatEntry(chatEntry); diff --git a/src/views/chat-history/ChatHistoryView.tsx b/src/views/chat-history/ChatHistoryView.tsx index d1121e9e..2a29cdd8 100644 --- a/src/views/chat-history/ChatHistoryView.tsx +++ b/src/views/chat-history/ChatHistoryView.tsx @@ -5,10 +5,13 @@ import { ChatHistoryEvent } from '../../events/chat-history/ChatHistoryEvent'; import { useUiEvent } from '../../hooks'; import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../layout'; import { ChatHistoryMessageHandler } from './ChatHistoryMessageHandler'; +import { ChatHistoryState } from './common/ChatHistoryState'; +import { SetChatHistory } from './common/GetChatHistory'; +import { RoomHistoryState } from './common/RoomHistoryState'; import { ChatHistoryContextProvider } from './context/ChatHistoryContext'; import { ChatEntryType } from './context/ChatHistoryContext.types'; -import { ChatHistoryState } from './utils/ChatHistoryState'; -import { RoomHistoryState } from './utils/RoomHistoryState'; + + export const ChatHistoryView: FC<{}> = props => { @@ -25,6 +28,8 @@ export const ChatHistoryView: FC<{}> = props => const chatState = new ChatHistoryState(); const roomState = new RoomHistoryState(); + SetChatHistory(chatState); + chatState.notifier = () => setChatHistoryUpdateId(prevValue => (prevValue + 1)); roomState.notifier = () => setRoomHistoryUpdateId(prevValue => (prevValue + 1)); diff --git a/src/views/chat-history/utils/ChatHistoryState.ts b/src/views/chat-history/common/ChatHistoryState.ts similarity index 100% rename from src/views/chat-history/utils/ChatHistoryState.ts rename to src/views/chat-history/common/ChatHistoryState.ts diff --git a/src/views/chat-history/common/GetChatHistory.ts b/src/views/chat-history/common/GetChatHistory.ts new file mode 100644 index 00000000..d39ef584 --- /dev/null +++ b/src/views/chat-history/common/GetChatHistory.ts @@ -0,0 +1,7 @@ +import { IChatHistoryState } from '../context/ChatHistoryContext.types'; + +let GLOBAL_CHATS: IChatHistoryState = null; + +export const SetChatHistory = (chatHistory: IChatHistoryState) => (GLOBAL_CHATS = chatHistory); + +export const GetChatHistory = () => GLOBAL_CHATS; diff --git a/src/views/chat-history/utils/RoomHistoryState.ts b/src/views/chat-history/common/RoomHistoryState.ts similarity index 100% rename from src/views/chat-history/utils/RoomHistoryState.ts rename to src/views/chat-history/common/RoomHistoryState.ts diff --git a/src/views/chat-history/context/ChatHistoryContext.types.ts b/src/views/chat-history/context/ChatHistoryContext.types.ts index e691d471..51cd19cf 100644 --- a/src/views/chat-history/context/ChatHistoryContext.types.ts +++ b/src/views/chat-history/context/ChatHistoryContext.types.ts @@ -24,6 +24,8 @@ export interface IChatEntry { name: string; look?: string; message?: string; + entityType?: number; + roomId: number; timestamp: string; type: number; } diff --git a/src/views/help/HelpMessageHandler.tsx b/src/views/help/HelpMessageHandler.tsx index f71634b7..959abdb9 100644 --- a/src/views/help/HelpMessageHandler.tsx +++ b/src/views/help/HelpMessageHandler.tsx @@ -1,12 +1,10 @@ -import { CallForHelpResultMessageEvent, FurnitureListItemParser, PetData } from '@nitrots/nitro-renderer'; +import { CallForHelpResultMessageEvent } from '@nitrots/nitro-renderer'; import { FC, useCallback } from 'react'; import { LocalizeText } from '../../api'; import { CreateMessageHook } from '../../hooks/messages/message-event'; import { NotificationAlertType } from '../notification-center/common/NotificationAlertType'; import { NotificationUtilities } from '../notification-center/common/NotificationUtilities'; import { GetCloseReasonKey } from './common/GetCloseReasonKey'; -let furniMsgFragments: Map[] = null; -let petMsgFragments: Map[] = null; export const HelpMessageHandler: FC<{}> = props => { diff --git a/src/views/help/HelpView.scss b/src/views/help/HelpView.scss new file mode 100644 index 00000000..927c1cdc --- /dev/null +++ b/src/views/help/HelpView.scss @@ -0,0 +1,10 @@ +.nitro-help { + height: 400px; + width: 300px; + + .index-image { + background: url('../../assets/images/help/help_index.png'); + width: 126px; + height: 105px; + } +} diff --git a/src/views/help/HelpView.tsx b/src/views/help/HelpView.tsx index 4917c713..630d41d1 100644 --- a/src/views/help/HelpView.tsx +++ b/src/views/help/HelpView.tsx @@ -1,11 +1,79 @@ -import { FC } from 'react'; +import { FC, useCallback, useState } from 'react'; +import { LocalizeText } from '../../api'; +import { HelpEvent } from '../../events/help/HelpEvent'; +import { HelpReportUserEvent } from '../../events/help/HelpReportUserEvent'; +import { useUiEvent } from '../../hooks'; +import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../layout'; +import { HelpContextProvider } from './context/HelpContext'; +import { IHelpReportState, initialReportState } from './context/HelpContext.types'; import { HelpMessageHandler } from './HelpMessageHandler'; +import { DescribeReportView } from './views/DescribeReportView'; +import { HelpIndexView } from './views/HelpIndexView'; +import { SelectReportedChatsView } from './views/SelectReportedChatsView'; +import { SelectReportedUserView } from './views/SelectReportedUserView'; +import { SelectTopicView } from './views/SelectTopicView'; export const HelpView: FC<{}> = props => { + const [isVisible, setIsVisible] = useState(false); + const [ helpReportState, setHelpReportState ] = useState(initialReportState); + + const onHelpEvent = useCallback((event: HelpEvent) => + { + setHelpReportState(initialReportState); + + switch(event.type) + { + case HelpEvent.SHOW_HELP_CENTER: + setIsVisible(true); + break; + case HelpEvent.HIDE_HELP_CENTER: + setIsVisible(false); + break; + case HelpEvent.TOGGLE_HELP_CENTER: + setIsVisible(!isVisible); + break; + case HelpReportUserEvent.REPORT_USER: + const reportEvent = event as HelpReportUserEvent; + const reportState = Object.assign({}, helpReportState ); + reportState.reportedUserId = reportEvent.reportedUserId; + reportState.currentStep = 2; + setHelpReportState(reportState); + setIsVisible(true); + break; + } + }, [helpReportState, isVisible]); + + useUiEvent(HelpEvent.TOGGLE_HELP_CENTER, onHelpEvent); + useUiEvent(HelpEvent.SHOW_HELP_CENTER, onHelpEvent); + useUiEvent(HelpEvent.HIDE_HELP_CENTER, onHelpEvent); + useUiEvent(HelpReportUserEvent.REPORT_USER, onHelpEvent); + + const CurrentStepView = useCallback(() => + { + switch(helpReportState.currentStep) + { + case 0: return + case 1: return + case 2: return + case 3: return + case 4: return + } + + return null; + }, [helpReportState.currentStep]); + return ( - <> + - + {isVisible && + + setIsVisible(false)} /> + + + + + } + ); } diff --git a/src/views/help/common/IUser.ts b/src/views/help/common/IUser.ts new file mode 100644 index 00000000..bd3852ab --- /dev/null +++ b/src/views/help/common/IUser.ts @@ -0,0 +1,5 @@ +export interface IUser +{ + id: number; + username: string; +} diff --git a/src/views/help/context/HelpContext.tsx b/src/views/help/context/HelpContext.tsx new file mode 100644 index 00000000..2cad4a52 --- /dev/null +++ b/src/views/help/context/HelpContext.tsx @@ -0,0 +1,14 @@ +import { createContext, FC, useContext } from 'react'; +import { HelpContextProps, IHelpContext } from './HelpContext.types'; + +const HelpContext = createContext({ + helpReportState: null, + setHelpReportState: null +}); + +export const HelpContextProvider: FC = props => +{ + return { props.children } +} + +export const useHelpContext = () => useContext(HelpContext); diff --git a/src/views/help/context/HelpContext.types.ts b/src/views/help/context/HelpContext.types.ts new file mode 100644 index 00000000..9368308b --- /dev/null +++ b/src/views/help/context/HelpContext.types.ts @@ -0,0 +1,33 @@ +import { ProviderProps } from 'react'; +import { IChatEntry } from '../../chat-history/context/ChatHistoryContext.types'; + +export interface IHelpContext +{ + helpReportState: IHelpReportState; + setHelpReportState: React.Dispatch>; +} + +export interface IHelpReportState { + reportedUserId: number; + reportedChats: IChatEntry[]; + cfhCategory: number; + cfhTopic: number; + roomId: number; + message: string; + currentStep: number; +} + +export const initialReportState: IHelpReportState = { + reportedUserId: -1, + reportedChats: [], + cfhCategory: -1, + cfhTopic: -1, + roomId: -1, + message: '', + currentStep: 0 +} + +export interface HelpContextProps extends ProviderProps +{ + +} diff --git a/src/views/help/views/DescribeReportView.tsx b/src/views/help/views/DescribeReportView.tsx new file mode 100644 index 00000000..f936d225 --- /dev/null +++ b/src/views/help/views/DescribeReportView.tsx @@ -0,0 +1,50 @@ +import { CallForHelpMessageComposer } from '@nitrots/nitro-renderer'; +import { FC, useCallback, useState } from 'react'; +import { LocalizeText } from '../../../api'; +import { HelpEvent } from '../../../events/help/HelpEvent'; +import { dispatchUiEvent, SendMessageHook } from '../../../hooks'; +import { useHelpContext } from '../context/HelpContext'; + +export const DescribeReportView: FC<{}> = props => +{ + const { helpReportState = null, setHelpReportState = null } = useHelpContext(); + const [message, setMessage] = useState(''); + + const submitReport = useCallback(() => + { + if(message.length < 15) return; + + const reportState = Object.assign({}, helpReportState); + + reportState.message = message; + + setHelpReportState(reportState); + + const roomId = reportState.reportedChats[0].roomId; + const chats: (string | number )[] = []; + reportState.reportedChats.forEach(entry => + { + chats.push(entry.entityId); + chats.push(entry.message); + }); + + SendMessageHook(new CallForHelpMessageComposer(message, reportState.cfhTopic, reportState.reportedUserId, roomId, chats)); + + dispatchUiEvent(new HelpEvent(HelpEvent.HIDE_HELP_CENTER)); + }, [helpReportState, message, setHelpReportState]); + + return ( + <> +
+

{LocalizeText('help.emergency.chat_report.subtitle')}

+
{LocalizeText('help.cfh.input.text')}
+
+ +
+