From 2d2604cdc9b5e00e7b5a401c9e33fd023391c8b2 Mon Sep 17 00:00:00 2001 From: dank074 Date: Fri, 15 Oct 2021 21:34:36 -0500 Subject: [PATCH] created chatlog component --- src/views/mod-tools/ModToolsView.scss | 3 +- src/views/mod-tools/ModToolsView.tsx | 8 +- .../mod-tools/views/chatlog/ChatlogView.scss | 28 +++++++ .../mod-tools/views/chatlog/ChatlogView.tsx | 57 +++++++++++++ .../views/chatlog/ChatlogView.types.ts | 6 ++ .../views/chatlog/ModToolsChatlogView.scss | 26 ------ .../views/chatlog/ModToolsChatlogView.tsx | 84 ------------------- .../room-chatlog/ModToolsChatlogView.scss | 3 + .../room-chatlog/ModToolsChatlogView.tsx | 62 ++++++++++++++ .../ModToolsChatlogView.types.ts | 0 10 files changed, 164 insertions(+), 113 deletions(-) create mode 100644 src/views/mod-tools/views/chatlog/ChatlogView.scss create mode 100644 src/views/mod-tools/views/chatlog/ChatlogView.tsx create mode 100644 src/views/mod-tools/views/chatlog/ChatlogView.types.ts delete mode 100644 src/views/mod-tools/views/chatlog/ModToolsChatlogView.scss delete mode 100644 src/views/mod-tools/views/chatlog/ModToolsChatlogView.tsx create mode 100644 src/views/mod-tools/views/room-chatlog/ModToolsChatlogView.scss create mode 100644 src/views/mod-tools/views/room-chatlog/ModToolsChatlogView.tsx rename src/views/mod-tools/views/{chatlog => room-chatlog}/ModToolsChatlogView.types.ts (100%) diff --git a/src/views/mod-tools/ModToolsView.scss b/src/views/mod-tools/ModToolsView.scss index 9f5554e9..66fe1306 100644 --- a/src/views/mod-tools/ModToolsView.scss +++ b/src/views/mod-tools/ModToolsView.scss @@ -2,5 +2,6 @@ width: 200px; } -@import './views/chatlog/ModToolsChatlogView'; +@import './views/room-chatlog/ModToolsChatlogView'; @import './views/room/ModToolsRoomView'; +@import './views/chatlog/ChatlogView'; diff --git a/src/views/mod-tools/ModToolsView.tsx b/src/views/mod-tools/ModToolsView.tsx index b6591d92..60fc1ba3 100644 --- a/src/views/mod-tools/ModToolsView.tsx +++ b/src/views/mod-tools/ModToolsView.tsx @@ -9,6 +9,7 @@ import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../ import { ModToolsContextProvider } from './context/ModToolsContext'; import { ModToolsViewProps } from './ModToolsView.types'; import { initialModTools, ModToolsActions, ModToolsReducer } from './reducers/ModToolsReducer'; +import { ModToolsChatlogView } from './views/room-chatlog/ModToolsChatlogView'; import { ModToolsRoomView } from './views/room/ModToolsRoomView'; import { ModToolsTicketsView } from './views/tickets/ModToolsTicketsView'; import { ModToolsUserView } from './views/user/ModToolsUserView'; @@ -22,6 +23,7 @@ export const ModToolsView: FC = props => const [ isRoomVisible, setIsRoomVisible ] = useState(false); const [ isUserVisible, setIsUserVisible ] = useState(false); const [ isTicketsVisible, setIsTicketsVisible ] = useState(false); + const [ isChatlogVisible, setChatlogVisible ] = useState(false); const onModToolsEvent = useCallback((event: ModToolsEvent) => { @@ -166,7 +168,7 @@ export const ModToolsView: FC = props => setIsVisible(false) } /> - + @@ -174,10 +176,12 @@ export const ModToolsView: FC = props => { openRooms && openRooms.map(roomId => { return handleClick('close_room', roomId.toString()) } />; - }) } + }) + } { isUserVisible && } { isTicketsVisible && setIsTicketsVisible(false) } /> } + { isChatlogVisible && setChatlogVisible(false) }/>} ); } diff --git a/src/views/mod-tools/views/chatlog/ChatlogView.scss b/src/views/mod-tools/views/chatlog/ChatlogView.scss new file mode 100644 index 00000000..332ccc31 --- /dev/null +++ b/src/views/mod-tools/views/chatlog/ChatlogView.scss @@ -0,0 +1,28 @@ +.chatlog-messages { + color: $black; + + $username-col-width: 100px; + + .username-label { + width: $username-col-width; + } + + .chatlog { + min-height: 200px; + min-width: 400px; + + .chatlog-container { + color: $black; + + div.chatlog-entry { + border-bottom: 1px solid rgba(0, 0, 0, 0.2); + + .username { + color: #1E7295; + text-decoration: underline; + width: $username-col-width; + } + } + } + } +} diff --git a/src/views/mod-tools/views/chatlog/ChatlogView.tsx b/src/views/mod-tools/views/chatlog/ChatlogView.tsx new file mode 100644 index 00000000..b56a9b86 --- /dev/null +++ b/src/views/mod-tools/views/chatlog/ChatlogView.tsx @@ -0,0 +1,57 @@ +import { UserProfileComposer } from '@nitrots/nitro-renderer'; +import { FC } from 'react'; +import { AutoSizer, CellMeasurerCache, List, ListRowProps, ListRowRenderer } from 'react-virtualized'; +import { SendMessageHook } from '../../../../hooks'; +import { ChatlogViewProps } from './ChatlogView.types'; + +export const ChatlogView: FC = props => +{ + const { record = null } = props; + + const cache = new CellMeasurerCache({ + defaultHeight: 20, + fixedWidth: true + }); + + const rowRenderer: ListRowRenderer = (props: ListRowProps) => + { + const item = record.chatlog[props.index]; + + return ( +
+
{item.timestamp}
+
SendMessageHook(new UserProfileComposer(item.userId))}>{item.userName}
+
{item.message}
+
+ ); + } + + return ( + <> + {record &&
+
+
Time
+
User
+
Message
+
+
+ + {({ height, width }) => + { + return ( + + ) + } + } + +
+
} + + ); +} diff --git a/src/views/mod-tools/views/chatlog/ChatlogView.types.ts b/src/views/mod-tools/views/chatlog/ChatlogView.types.ts new file mode 100644 index 00000000..edf5ed3e --- /dev/null +++ b/src/views/mod-tools/views/chatlog/ChatlogView.types.ts @@ -0,0 +1,6 @@ +import { ChatRecordData } from '@nitrots/nitro-renderer'; + +export interface ChatlogViewProps +{ + record: ChatRecordData; +} diff --git a/src/views/mod-tools/views/chatlog/ModToolsChatlogView.scss b/src/views/mod-tools/views/chatlog/ModToolsChatlogView.scss deleted file mode 100644 index 7a2ddc8a..00000000 --- a/src/views/mod-tools/views/chatlog/ModToolsChatlogView.scss +++ /dev/null @@ -1,26 +0,0 @@ -.nitro-mod-tools-chatlog { - width: 480px; - - .chatlog-messages { - height: 300px; - max-height: 300px; - - .table { - color: $black; - - > :not(caption) > * > * { - box-shadow: none; - border-bottom: 1px solid rgba(0, 0, 0, .2); - } - - &.table-striped > tbody > tr:nth-of-type(odd) { - color: $black; - background: rgba(0, 0, 0, .05); - } - - td { - padding: 0px 5px; - } - } - } -} diff --git a/src/views/mod-tools/views/chatlog/ModToolsChatlogView.tsx b/src/views/mod-tools/views/chatlog/ModToolsChatlogView.tsx deleted file mode 100644 index 18f20609..00000000 --- a/src/views/mod-tools/views/chatlog/ModToolsChatlogView.tsx +++ /dev/null @@ -1,84 +0,0 @@ -import { ModtoolRequestRoomChatlogComposer, ModtoolRoomChatlogEvent, ModtoolRoomChatlogLine } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useState } from 'react'; -import { TryVisitRoom } from '../../../../api'; -import { CreateMessageHook, SendMessageHook } from '../../../../hooks/messages'; -import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../../../layout'; -import { ModToolsChatlogViewProps } from './ModToolsChatlogView.types'; - -export const ModToolsChatlogView: FC = props => -{ - const { roomId = null, onCloseClick = null } = props; - - const [ roomName, setRoomName ] = useState(null); - const [ messages, setMessages ] = useState(null); - const [ loadedRoomId, setLoadedRoomId ] = useState(null); - - const [ messagesRequested, setMessagesRequested ] = useState(false); - - useEffect(() => - { - if(messagesRequested) return; - - SendMessageHook(new ModtoolRequestRoomChatlogComposer(roomId)); - setMessagesRequested(true); - }, [ roomId, messagesRequested, setMessagesRequested ]); - - const onModtoolRoomChatlogEvent = useCallback((event: ModtoolRoomChatlogEvent) => - { - const parser = event.getParser(); - - setRoomName(parser.data.roomName); - setMessages(parser.data.chatlog); - setLoadedRoomId(parser.data.roomId); - }, [ setRoomName, setMessages ]); - - CreateMessageHook(ModtoolRoomChatlogEvent, onModtoolRoomChatlogEvent); - - const handleClick = useCallback((action: string, value?: string) => - { - if(!action) return; - - switch(action) - { - case 'close': - onCloseClick(); - return; - case 'visit_room': - TryVisitRoom(loadedRoomId); - return; - } - }, [ onCloseClick, loadedRoomId ]); - - return ( - - handleClick('close') } /> - -
- - -
-
- { messages && - - - - - - - - - { messages.map((message, index) => - { - return - - - - ; - }) } - -
TimeUserMessage
{ message.timestamp }{ message.userName }{ message.message }
} -
-
-
- ); -} diff --git a/src/views/mod-tools/views/room-chatlog/ModToolsChatlogView.scss b/src/views/mod-tools/views/room-chatlog/ModToolsChatlogView.scss new file mode 100644 index 00000000..cf1d0dca --- /dev/null +++ b/src/views/mod-tools/views/room-chatlog/ModToolsChatlogView.scss @@ -0,0 +1,3 @@ +.nitro-mod-tools-room-chatlog { + +} diff --git a/src/views/mod-tools/views/room-chatlog/ModToolsChatlogView.tsx b/src/views/mod-tools/views/room-chatlog/ModToolsChatlogView.tsx new file mode 100644 index 00000000..dbf902c6 --- /dev/null +++ b/src/views/mod-tools/views/room-chatlog/ModToolsChatlogView.tsx @@ -0,0 +1,62 @@ +import { ChatRecordData, ModtoolRequestRoomChatlogComposer, ModtoolRoomChatlogEvent } from '@nitrots/nitro-renderer'; +import { FC, useCallback, useEffect, useState } from 'react'; +import { TryVisitRoom } from '../../../../api'; +import { CreateMessageHook, SendMessageHook } from '../../../../hooks/messages'; +import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../../../layout'; +import { ChatlogView } from '../chatlog/ChatlogView'; +import { ModToolsChatlogViewProps } from './ModToolsChatlogView.types'; + +export const ModToolsChatlogView: FC = props => +{ + const { roomId = null, onCloseClick = null } = props; + + const [roomChatlog, setRoomChatlog] = useState(null); + + useEffect(() => + { + SendMessageHook(new ModtoolRequestRoomChatlogComposer(roomId)); + }, [roomId]); + + const onModtoolRoomChatlogEvent = useCallback((event: ModtoolRoomChatlogEvent) => + { + const parser = event.getParser(); + + if(!parser) return; + + setRoomChatlog(parser.data); + }, [setRoomChatlog]); + + CreateMessageHook(ModtoolRoomChatlogEvent, onModtoolRoomChatlogEvent); + + const handleClick = useCallback((action: string, value?: string) => + { + if(!action) return; + + switch(action) + { + case 'close': + onCloseClick(); + return; + case 'visit_room': + TryVisitRoom(roomChatlog.roomId); + return; + } + }, [onCloseClick, roomChatlog]); + + return ( + + handleClick('close')} /> + + {roomChatlog && + <> +
+ + +
+ + + } +
+
+ ); +} diff --git a/src/views/mod-tools/views/chatlog/ModToolsChatlogView.types.ts b/src/views/mod-tools/views/room-chatlog/ModToolsChatlogView.types.ts similarity index 100% rename from src/views/mod-tools/views/chatlog/ModToolsChatlogView.types.ts rename to src/views/mod-tools/views/room-chatlog/ModToolsChatlogView.types.ts