From fceabc0aaaa644c0d329825ebb8a9d4bbbbc7b24 Mon Sep 17 00:00:00 2001 From: Bill Date: Mon, 21 Feb 2022 11:52:11 -0500 Subject: [PATCH] Update chat history --- .../chat-history/ChatHistoryContext.tsx | 21 +++ .../ChatHistoryMessageHandler.tsx | 11 +- .../chat-history/ChatHistoryView.scss | 8 + .../chat-history/ChatHistoryView.tsx | 155 ++++++++++++++++ .../chat-history/common/ChatEntryType.ts | 5 + .../chat-history/common/ChatHistoryState.ts | 13 +- .../chat-history/common/GetChatHistory.ts | 2 +- .../chat-history/common/IChatEntry.ts | 12 ++ .../chat-history/common/IChatHistoryState.ts | 8 + .../chat-history/common/IRoomHistoryEntry.ts | 4 + .../chat-history/common/IRoomHistoryState.ts | 8 + .../chat-history/common/RoomHistoryState.ts | 3 +- .../chat-history/common}/Utilities.ts | 0 .../help/common/IHelpReportState.ts | 5 +- .../help/views/SelectReportedChatsView.tsx | 5 +- .../help/views/SelectReportedUserView.tsx | 4 +- src/components/index.scss | 1 + src/events/chat-history/ChatHistoryEvent.ts | 8 - src/views/Styles.scss | 1 - src/views/chat-history/ChatHistoryView.scss | 30 ---- src/views/chat-history/ChatHistoryView.tsx | 167 ------------------ .../context/ChatHistoryContext.tsx | 14 -- .../context/ChatHistoryContext.types.ts | 50 ------ src/views/main/MainView.tsx | 2 +- 24 files changed, 249 insertions(+), 288 deletions(-) create mode 100644 src/components/chat-history/ChatHistoryContext.tsx rename src/{views => components}/chat-history/ChatHistoryMessageHandler.tsx (91%) create mode 100644 src/components/chat-history/ChatHistoryView.scss create mode 100644 src/components/chat-history/ChatHistoryView.tsx create mode 100644 src/components/chat-history/common/ChatEntryType.ts rename src/{views => components}/chat-history/common/ChatHistoryState.ts (79%) rename src/{views => components}/chat-history/common/GetChatHistory.ts (72%) create mode 100644 src/components/chat-history/common/IChatEntry.ts create mode 100644 src/components/chat-history/common/IChatHistoryState.ts create mode 100644 src/components/chat-history/common/IRoomHistoryEntry.ts create mode 100644 src/components/chat-history/common/IRoomHistoryState.ts rename src/{views => components}/chat-history/common/RoomHistoryState.ts (83%) rename src/{views/chat-history/utils => components/chat-history/common}/Utilities.ts (100%) delete mode 100644 src/events/chat-history/ChatHistoryEvent.ts delete mode 100644 src/views/chat-history/ChatHistoryView.scss delete mode 100644 src/views/chat-history/ChatHistoryView.tsx delete mode 100644 src/views/chat-history/context/ChatHistoryContext.tsx delete mode 100644 src/views/chat-history/context/ChatHistoryContext.types.ts diff --git a/src/components/chat-history/ChatHistoryContext.tsx b/src/components/chat-history/ChatHistoryContext.tsx new file mode 100644 index 00000000..086fcfe5 --- /dev/null +++ b/src/components/chat-history/ChatHistoryContext.tsx @@ -0,0 +1,21 @@ +import { createContext, FC, ProviderProps, useContext } from 'react'; +import { IChatHistoryState } from './common/IChatHistoryState'; +import { IRoomHistoryState } from './common/IRoomHistoryState'; + +export interface IChatHistoryContext +{ + chatHistoryState: IChatHistoryState; + roomHistoryState: IRoomHistoryState; +} + +const ChatHistoryContext = createContext({ + chatHistoryState: null, + roomHistoryState: null +}); + +export const ChatHistoryContextProvider: FC> = props => +{ + return { props.children } +} + +export const useChatHistoryContext = () => useContext(ChatHistoryContext); diff --git a/src/views/chat-history/ChatHistoryMessageHandler.tsx b/src/components/chat-history/ChatHistoryMessageHandler.tsx similarity index 91% rename from src/views/chat-history/ChatHistoryMessageHandler.tsx rename to src/components/chat-history/ChatHistoryMessageHandler.tsx index a482a36a..89d38a12 100644 --- a/src/views/chat-history/ChatHistoryMessageHandler.tsx +++ b/src/components/chat-history/ChatHistoryMessageHandler.tsx @@ -2,9 +2,14 @@ import { GetGuestRoomResultEvent, RoomSessionChatEvent, RoomSessionEvent } from import { FC, useCallback, useState } from 'react'; import { GetRoomSession } from '../../api'; import { CreateMessageHook, useRoomSessionManagerEvent } from '../../hooks'; -import { useChatHistoryContext } from './context/ChatHistoryContext'; -import { ChatEntryType, CHAT_HISTORY_MAX, IChatEntry, IRoomHistoryEntry, ROOM_HISTORY_MAX } from './context/ChatHistoryContext.types'; -import { currentDate } from './utils/Utilities'; +import { useChatHistoryContext } from './ChatHistoryContext'; +import { ChatEntryType } from './common/ChatEntryType'; +import { IChatEntry } from './common/IChatEntry'; +import { IRoomHistoryEntry } from './common/IRoomHistoryEntry'; +import { currentDate } from './common/Utilities'; + +const CHAT_HISTORY_MAX = 1000; +const ROOM_HISTORY_MAX = 10; export const ChatHistoryMessageHandler: FC<{}> = props => { diff --git a/src/components/chat-history/ChatHistoryView.scss b/src/components/chat-history/ChatHistoryView.scss new file mode 100644 index 00000000..8c3838e4 --- /dev/null +++ b/src/components/chat-history/ChatHistoryView.scss @@ -0,0 +1,8 @@ +.nitro-chat-history { + width: $chat-history-width; + height: $chat-history-height; + + .content-area { + min-height: 200px; + } +} diff --git a/src/components/chat-history/ChatHistoryView.tsx b/src/components/chat-history/ChatHistoryView.tsx new file mode 100644 index 00000000..a048826c --- /dev/null +++ b/src/components/chat-history/ChatHistoryView.tsx @@ -0,0 +1,155 @@ +import { ILinkEventTracker } from '@nitrots/nitro-renderer'; +import { FC, useCallback, useEffect, useMemo, useRef, useState } from 'react'; +import { AutoSizer, CellMeasurer, CellMeasurerCache, List, ListRowProps, ListRowRenderer, Size } from 'react-virtualized'; +import { RenderedRows } from 'react-virtualized/dist/es/List'; +import { AddEventLinkTracker, LocalizeText, RemoveLinkEventTracker } from '../../api'; +import { Flex, Text } from '../../common'; +import { BatchUpdates } from '../../hooks'; +import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../layout'; +import { ChatHistoryContextProvider } from './ChatHistoryContext'; +import { ChatHistoryMessageHandler } from './ChatHistoryMessageHandler'; +import { ChatEntryType } from './common/ChatEntryType'; +import { ChatHistoryState } from './common/ChatHistoryState'; +import { SetChatHistory } from './common/GetChatHistory'; +import { RoomHistoryState } from './common/RoomHistoryState'; + +export const ChatHistoryView: FC<{}> = props => +{ + const [ isVisible, setIsVisible ] = useState(false); + const [ needsScroll, setNeedsScroll ] = useState(false); + const [ chatHistoryUpdateId, setChatHistoryUpdateId ] = useState(-1); + const [ roomHistoryUpdateId, setRoomHistoryUpdateId ] = useState(-1); + const [ chatHistoryState, setChatHistoryState ] = useState(new ChatHistoryState()); + const [ roomHistoryState, setRoomHistoryState ] = useState(new RoomHistoryState()); + const elementRef = useRef(null); + + const cache = useMemo(() => new CellMeasurerCache({ defaultHeight: 25, fixedWidth: true }), []); + + const RowRenderer: ListRowRenderer = (props: ListRowProps) => + { + const item = chatHistoryState.chats[props.index]; + + const isDark = (props.index % 2 === 0); + + return ( + + + { item.timestamp } + { (item.type === ChatEntryType.TYPE_CHAT) && + <> + + { item.message } + } + { (item.type === ChatEntryType.TYPE_ROOM_INFO) && + <> + + { item.name } + } + + + ); + }; + + const onResize = (info: Size) => cache.clearAll(); + + const onRowsRendered = (info: RenderedRows) => + { + if(elementRef && elementRef.current && isVisible && needsScroll) + { + elementRef.current.scrollToRow(chatHistoryState.chats.length); + + setNeedsScroll(false); + } + } + + const linkReceived = useCallback((url: string) => + { + const parts = url.split('/'); + + if(parts.length < 2) return; + + switch(parts[1]) + { + case 'show': + setIsVisible(true); + return; + case 'hide': + setIsVisible(false); + return; + case 'toggle': + setIsVisible(prevValue => !prevValue); + return; + } + }, []); + + useEffect(() => + { + const linkTracker: ILinkEventTracker = { + linkReceived, + eventUrlPrefix: 'chat-history/' + }; + + AddEventLinkTracker(linkTracker); + + return () => RemoveLinkEventTracker(linkTracker); + }, [ linkReceived ]); + + useEffect(() => + { + const chatState = new ChatHistoryState(); + const roomState = new RoomHistoryState(); + + SetChatHistory(chatState); + + chatState.notifier = () => setChatHistoryUpdateId(prevValue => (prevValue + 1)); + roomState.notifier = () => setRoomHistoryUpdateId(prevValue => (prevValue + 1)); + + BatchUpdates(() => + { + setChatHistoryState(chatState); + setRoomHistoryState(roomState); + }); + + return () => + { + chatState.notifier = null; + roomState.notifier = null; + }; + }, []); + + useEffect(() => + { + if(elementRef && elementRef.current && isVisible) elementRef.current.scrollToRow(chatHistoryState.chats.length); + + setNeedsScroll(true); + }, [ isVisible, chatHistoryState.chats, chatHistoryUpdateId ]); + + return ( + + + { isVisible && + + setIsVisible(false) }/> + + + { ({ height, width }) => + { + return ( + + ) + } } + + + } + + ); +} diff --git a/src/components/chat-history/common/ChatEntryType.ts b/src/components/chat-history/common/ChatEntryType.ts new file mode 100644 index 00000000..c49cd0ea --- /dev/null +++ b/src/components/chat-history/common/ChatEntryType.ts @@ -0,0 +1,5 @@ +export class ChatEntryType +{ + public static TYPE_CHAT = 1; + public static TYPE_ROOM_INFO = 2; +} diff --git a/src/views/chat-history/common/ChatHistoryState.ts b/src/components/chat-history/common/ChatHistoryState.ts similarity index 79% rename from src/views/chat-history/common/ChatHistoryState.ts rename to src/components/chat-history/common/ChatHistoryState.ts index 895c00a1..53c96ef4 100644 --- a/src/views/chat-history/common/ChatHistoryState.ts +++ b/src/components/chat-history/common/ChatHistoryState.ts @@ -1,4 +1,5 @@ -import { IChatEntry, IChatHistoryState } from '../context/ChatHistoryContext.types'; +import { IChatEntry } from './IChatEntry'; +import { IChatHistoryState } from './IChatHistoryState'; export class ChatHistoryState implements IChatHistoryState { @@ -10,6 +11,11 @@ export class ChatHistoryState implements IChatHistoryState this._chats = []; } + public notify(): void + { + if(this._notifier) this._notifier(); + } + public get chats(): IChatEntry[] { return this._chats; @@ -24,9 +30,4 @@ export class ChatHistoryState implements IChatHistoryState { this._notifier = notifier; } - - notify(): void - { - if(this._notifier) this._notifier(); - } } diff --git a/src/views/chat-history/common/GetChatHistory.ts b/src/components/chat-history/common/GetChatHistory.ts similarity index 72% rename from src/views/chat-history/common/GetChatHistory.ts rename to src/components/chat-history/common/GetChatHistory.ts index d39ef584..dbf546b1 100644 --- a/src/views/chat-history/common/GetChatHistory.ts +++ b/src/components/chat-history/common/GetChatHistory.ts @@ -1,4 +1,4 @@ -import { IChatHistoryState } from '../context/ChatHistoryContext.types'; +import { IChatHistoryState } from './IChatHistoryState'; let GLOBAL_CHATS: IChatHistoryState = null; diff --git a/src/components/chat-history/common/IChatEntry.ts b/src/components/chat-history/common/IChatEntry.ts new file mode 100644 index 00000000..472a5dbe --- /dev/null +++ b/src/components/chat-history/common/IChatEntry.ts @@ -0,0 +1,12 @@ +export interface IChatEntry +{ + id: number; + entityId: number; + name: string; + look?: string; + message?: string; + entityType?: number; + roomId: number; + timestamp: string; + type: number; +} diff --git a/src/components/chat-history/common/IChatHistoryState.ts b/src/components/chat-history/common/IChatHistoryState.ts new file mode 100644 index 00000000..4fecbae8 --- /dev/null +++ b/src/components/chat-history/common/IChatHistoryState.ts @@ -0,0 +1,8 @@ +import { IChatEntry } from './IChatEntry'; + +export interface IChatHistoryState +{ + chats: IChatEntry[]; + notifier: () => void + notify(): void; +} diff --git a/src/components/chat-history/common/IRoomHistoryEntry.ts b/src/components/chat-history/common/IRoomHistoryEntry.ts new file mode 100644 index 00000000..19e6f917 --- /dev/null +++ b/src/components/chat-history/common/IRoomHistoryEntry.ts @@ -0,0 +1,4 @@ +export interface IRoomHistoryEntry { + id: number; + name: string; +} diff --git a/src/components/chat-history/common/IRoomHistoryState.ts b/src/components/chat-history/common/IRoomHistoryState.ts new file mode 100644 index 00000000..64192f88 --- /dev/null +++ b/src/components/chat-history/common/IRoomHistoryState.ts @@ -0,0 +1,8 @@ +import { IRoomHistoryEntry } from './IRoomHistoryEntry'; + +export interface IRoomHistoryState +{ + roomHistory: IRoomHistoryEntry[]; + notifier: () => void; + notify: () => void; +} diff --git a/src/views/chat-history/common/RoomHistoryState.ts b/src/components/chat-history/common/RoomHistoryState.ts similarity index 83% rename from src/views/chat-history/common/RoomHistoryState.ts rename to src/components/chat-history/common/RoomHistoryState.ts index d3002b81..c59ac73e 100644 --- a/src/views/chat-history/common/RoomHistoryState.ts +++ b/src/components/chat-history/common/RoomHistoryState.ts @@ -1,4 +1,5 @@ -import { IRoomHistoryEntry, IRoomHistoryState } from '../context/ChatHistoryContext.types'; +import { IRoomHistoryEntry } from './IRoomHistoryEntry'; +import { IRoomHistoryState } from './IRoomHistoryState'; export class RoomHistoryState implements IRoomHistoryState { diff --git a/src/views/chat-history/utils/Utilities.ts b/src/components/chat-history/common/Utilities.ts similarity index 100% rename from src/views/chat-history/utils/Utilities.ts rename to src/components/chat-history/common/Utilities.ts diff --git a/src/components/help/common/IHelpReportState.ts b/src/components/help/common/IHelpReportState.ts index eba3d2b6..26aba823 100644 --- a/src/components/help/common/IHelpReportState.ts +++ b/src/components/help/common/IHelpReportState.ts @@ -1,6 +1,7 @@ -import { IChatEntry } from '../../../views/chat-history/context/ChatHistoryContext.types'; +import { IChatEntry } from '../../chat-history/common/IChatEntry'; -export interface IHelpReportState { +export interface IHelpReportState +{ reportedUserId: number; reportedChats: IChatEntry[]; cfhCategory: number; diff --git a/src/components/help/views/SelectReportedChatsView.tsx b/src/components/help/views/SelectReportedChatsView.tsx index 2adb4930..489a7e3a 100644 --- a/src/components/help/views/SelectReportedChatsView.tsx +++ b/src/components/help/views/SelectReportedChatsView.tsx @@ -2,8 +2,9 @@ import { RoomObjectType } from '@nitrots/nitro-renderer'; import { FC, useMemo, useState } from 'react'; import { LocalizeText } from '../../../api'; import { Button, Column, Flex, Grid, LayoutGridItem, Text } from '../../../common'; -import { GetChatHistory } from '../../../views/chat-history/common/GetChatHistory'; -import { ChatEntryType, IChatEntry } from '../../../views/chat-history/context/ChatHistoryContext.types'; +import { ChatEntryType } from '../../chat-history/common/ChatEntryType'; +import { GetChatHistory } from '../../chat-history/common/GetChatHistory'; +import { IChatEntry } from '../../chat-history/common/IChatEntry'; import { useHelpContext } from '../HelpContext'; export const SelectReportedChatsView: FC<{}> = props => diff --git a/src/components/help/views/SelectReportedUserView.tsx b/src/components/help/views/SelectReportedUserView.tsx index fbb627f5..6cd25281 100644 --- a/src/components/help/views/SelectReportedUserView.tsx +++ b/src/components/help/views/SelectReportedUserView.tsx @@ -2,8 +2,8 @@ import { RoomObjectType } from '@nitrots/nitro-renderer'; import { FC, useMemo, useState } from 'react'; import { GetSessionDataManager, LocalizeText } from '../../../api'; import { Button, Column, Flex, Grid, LayoutGridItem, Text } from '../../../common'; -import { GetChatHistory } from '../../../views/chat-history/common/GetChatHistory'; -import { ChatEntryType } from '../../../views/chat-history/context/ChatHistoryContext.types'; +import { ChatEntryType } from '../../chat-history/common/ChatEntryType'; +import { GetChatHistory } from '../../chat-history/common/GetChatHistory'; import { IReportedUser } from '../common/IReportedUser'; import { useHelpContext } from '../HelpContext'; diff --git a/src/components/index.scss b/src/components/index.scss index 3fe69a2c..2409d2d6 100644 --- a/src/components/index.scss +++ b/src/components/index.scss @@ -2,6 +2,7 @@ @import './avatar-editor/AvatarEditorView'; @import './camera/CameraWidgetView'; @import './catalog/CatalogView'; +@import './chat-history/ChatHistoryView'; @import './groups/GroupView'; @import './help/HelpView'; @import './inventory/InventoryView'; diff --git a/src/events/chat-history/ChatHistoryEvent.ts b/src/events/chat-history/ChatHistoryEvent.ts deleted file mode 100644 index e038f22e..00000000 --- a/src/events/chat-history/ChatHistoryEvent.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { NitroEvent } from '@nitrots/nitro-renderer'; - -export class ChatHistoryEvent extends NitroEvent -{ - public static SHOW_CHAT_HISTORY: string = 'CHE_SHOW_CHAT_HISTORY'; - public static HIDE_CHAT_HISTORY: string = 'CHE_HIDE_CHAT_HISTORY'; - public static TOGGLE_CHAT_HISTORY: string = 'CHE_TOGGLE_CHAT_HISTORY'; -} diff --git a/src/views/Styles.scss b/src/views/Styles.scss index da73febb..197b1e05 100644 --- a/src/views/Styles.scss +++ b/src/views/Styles.scss @@ -8,7 +8,6 @@ @import "./right-side/RightSideView"; @import "./room/RoomView"; @import "./room-host/RoomHostView"; -@import "./chat-history/ChatHistoryView"; @import "./floorplan-editor/FloorplanEditorView"; @import "./nitropedia/NitropediaView"; @import "./hc-center/HcCenterView.scss"; diff --git a/src/views/chat-history/ChatHistoryView.scss b/src/views/chat-history/ChatHistoryView.scss deleted file mode 100644 index 00f046ae..00000000 --- a/src/views/chat-history/ChatHistoryView.scss +++ /dev/null @@ -1,30 +0,0 @@ -.nitro-chat-history { - width: $chat-history-width; - height: $chat-history-height; - - background-color: #1C323F; - border: 2px solid rgba(255, 255, 255, 0.5); - - .nitro-card-header-container { - background-color: #3d5f6e; - color: #fff; - } - - .chat-history-content { - .chat-history-container { - min-height: 200px; - - .chat-history-list { - .chathistory-entry { - .light { - background-color: #121f27; - } - - .dark { - background-color: #0d171d; - } - } - } - } - } -} diff --git a/src/views/chat-history/ChatHistoryView.tsx b/src/views/chat-history/ChatHistoryView.tsx deleted file mode 100644 index f4528732..00000000 --- a/src/views/chat-history/ChatHistoryView.tsx +++ /dev/null @@ -1,167 +0,0 @@ -import { FC, useCallback, useEffect, useMemo, useRef, useState } from 'react'; -import { AutoSizer, CellMeasurer, CellMeasurerCache, List, ListRowProps, ListRowRenderer, Size } from 'react-virtualized'; -import { RenderedRows } from 'react-virtualized/dist/es/List'; -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'; - -export const ChatHistoryView: FC<{}> = props => -{ - const [ isVisible, setIsVisible ] = useState(false); - const [ needsScroll, setNeedsScroll ] = useState(false); - const [ chatHistoryUpdateId, setChatHistoryUpdateId ] = useState(-1); - const [ roomHistoryUpdateId, setRoomHistoryUpdateId ] = useState(-1); - const [ chatHistoryState, setChatHistoryState ] = useState(new ChatHistoryState()); - const [ roomHistoryState, setRoomHistoryState ] = useState(new RoomHistoryState()); - const elementRef = useRef(null); - - useEffect(() => - { - const chatState = new ChatHistoryState(); - const roomState = new RoomHistoryState(); - - SetChatHistory(chatState); - - chatState.notifier = () => setChatHistoryUpdateId(prevValue => (prevValue + 1)); - roomState.notifier = () => setRoomHistoryUpdateId(prevValue => (prevValue + 1)); - - setChatHistoryState(chatState); - setRoomHistoryState(roomState); - - return () => {chatState.notifier = null; roomState.notifier = null;}; - }, []); - - const onChatHistoryEvent = useCallback((event: ChatHistoryEvent) => - { - switch(event.type) - { - case ChatHistoryEvent.SHOW_CHAT_HISTORY: - setIsVisible(true); - break; - case ChatHistoryEvent.HIDE_CHAT_HISTORY: - setIsVisible(false); - break; - case ChatHistoryEvent.TOGGLE_CHAT_HISTORY: - setIsVisible(!isVisible); - break; - } - }, [isVisible]); - - useUiEvent(ChatHistoryEvent.HIDE_CHAT_HISTORY, onChatHistoryEvent); - useUiEvent(ChatHistoryEvent.SHOW_CHAT_HISTORY, onChatHistoryEvent); - useUiEvent(ChatHistoryEvent.TOGGLE_CHAT_HISTORY, onChatHistoryEvent); - - const cache = useMemo(() => - { - return new CellMeasurerCache({ - defaultHeight: 25, - fixedWidth: true, - //keyMapper: (index) => chatHistoryState.chats[index].id - }); - }, []); - - const RowRenderer: ListRowRenderer = (props: ListRowProps) => - { - const item = chatHistoryState.chats[props.index]; - - const isDark = (props.index % 2 === 0); - - return ( - -
- {(item.type === ChatEntryType.TYPE_CHAT) && -
-
{item.timestamp}
-
-
{item.message}
-
- } - {(item.type === ChatEntryType.TYPE_ROOM_INFO) && -
-
{item.timestamp}
- -
{item.name}
-
- } - -
- - ); - }; - - const onResize = useCallback((info: Size) => - { - cache.clearAll(); - }, [cache]); - - const onRowsRendered = useCallback((info: RenderedRows) => - { - if(elementRef && elementRef.current && isVisible && needsScroll) - { - console.log('stop ' + info.stopIndex); - //if(chatHistoryState.chats.length > 0) elementRef.current.measureAllRows(); - elementRef.current.scrollToRow(chatHistoryState.chats.length); - console.log('scroll') - setNeedsScroll(false); - } - }, [chatHistoryState.chats.length, isVisible, needsScroll]); - - useEffect(() => - { - - if(elementRef && elementRef.current && isVisible) - { - //if(chatHistoryState.chats.length > 0) elementRef.current.measureAllRows(); - elementRef.current.scrollToRow(chatHistoryState.chats.length); - } - //console.log(chatHistoryState.chats.length); - - setNeedsScroll(true); - }, [chatHistoryState.chats, isVisible, chatHistoryUpdateId]); - - return ( - - - {isVisible && - - setIsVisible(false) } theme={'dark'}/> - -
- - {({ height, width }) => - { - return ( - - ) - } - } - -
-
-
- } -
- ); -} diff --git a/src/views/chat-history/context/ChatHistoryContext.tsx b/src/views/chat-history/context/ChatHistoryContext.tsx deleted file mode 100644 index 981d6007..00000000 --- a/src/views/chat-history/context/ChatHistoryContext.tsx +++ /dev/null @@ -1,14 +0,0 @@ -import { createContext, FC, useContext } from 'react'; -import { ChatHistoryContextProps, IChatHistoryContext } from './ChatHistoryContext.types'; - -const ChatHistoryContext = createContext({ - chatHistoryState: null, - roomHistoryState: null -}); - -export const ChatHistoryContextProvider: FC = props => -{ - return { props.children } -} - -export const useChatHistoryContext = () => useContext(ChatHistoryContext); diff --git a/src/views/chat-history/context/ChatHistoryContext.types.ts b/src/views/chat-history/context/ChatHistoryContext.types.ts deleted file mode 100644 index 51cd19cf..00000000 --- a/src/views/chat-history/context/ChatHistoryContext.types.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { ProviderProps } from 'react'; - -export interface IChatHistoryContext -{ - chatHistoryState: IChatHistoryState; - roomHistoryState: IRoomHistoryState; -} - -export interface IChatHistoryState { - chats: IChatEntry[]; - notifier: () => void - notify(): void; -} - -export interface IRoomHistoryState { - roomHistory: IRoomHistoryEntry[]; - notifier: () => void - notify(): void; -} - -export interface IChatEntry { - id: number; - entityId: number; - name: string; - look?: string; - message?: string; - entityType?: number; - roomId: number; - timestamp: string; - type: number; -} - -export interface IRoomHistoryEntry { - id: number; - name: string; -} - -export class ChatEntryType -{ - public static TYPE_CHAT = 1; - public static TYPE_ROOM_INFO = 2; -} - -export const CHAT_HISTORY_MAX = 1000; -export const ROOM_HISTORY_MAX = 10; - -export interface ChatHistoryContextProps extends ProviderProps -{ - -} diff --git a/src/views/main/MainView.tsx b/src/views/main/MainView.tsx index dff40edb..34bd9ac3 100644 --- a/src/views/main/MainView.tsx +++ b/src/views/main/MainView.tsx @@ -5,6 +5,7 @@ import { AchievementsView } from '../../components/achievements/AchievementsView import { AvatarEditorView } from '../../components/avatar-editor/AvatarEditorView'; import { CameraWidgetView } from '../../components/camera/CameraWidgetView'; import { CatalogView } from '../../components/catalog/CatalogView'; +import { ChatHistoryView } from '../../components/chat-history/ChatHistoryView'; import { GroupsView } from '../../components/groups/GroupsView'; import { HelpView } from '../../components/help/HelpView'; import { InventoryView } from '../../components/inventory/InventoryView'; @@ -17,7 +18,6 @@ import { WiredView } from '../../components/wired/WiredView'; import { useRoomSessionManagerEvent } from '../../hooks/events/nitro/session/room-session-manager-event'; import { TransitionAnimation, TransitionAnimationTypes } from '../../layout'; import { CampaignView } from '../campaign/CampaignView'; -import { ChatHistoryView } from '../chat-history/ChatHistoryView'; import { FloorplanEditorView } from '../floorplan-editor/FloorplanEditorView'; import { FriendsView } from '../friends/FriendsView'; import { HcCenterView } from '../hc-center/HcCenterView';