diff --git a/web/pages/chat.tsx b/web/pages/chat.tsx index 992e7e59e..22a4080ff 100644 --- a/web/pages/chat.tsx +++ b/web/pages/chat.tsx @@ -1,16 +1,14 @@ import React, { useState, useEffect } from "react"; -import { Table, Typography, Tooltip, Switch, Button } from "antd"; -import { CheckCircleFilled, ExclamationCircleFilled } from "@ant-design/icons"; +import { Table, Typography, Tooltip, Button } from "antd"; +import { CheckCircleFilled, ExclamationCircleFilled, StopOutlined } from "@ant-design/icons"; +import classNames from 'classnames'; import { RowSelectionType } from "antd/es/table/interface"; import { ColumnsType } from 'antd/es/table'; import format from 'date-fns/format' -import MessageVisiblityToggle from './components/message-visiblity-toggle'; - import { CHAT_HISTORY, fetchData, UPDATE_CHAT_MESSGAE_VIZ } from "../utils/apis"; import { MessageType } from '../types/chat'; - const { Title } = Typography; function createUserNameFilters(messages: MessageType[]) { @@ -41,9 +39,9 @@ export const OUTCOME_TIMEOUT = 3000; export default function Chat() { const [messages, setMessages] = useState([]); const [selectedRowKeys, setSelectedRows] = useState([]); - const [bulkVisibility, setBulkVisibility] = useState(false); const [bulkProcessing, setBulkProcessing] = useState(false); const [bulkOutcome, setBulkOutcome] = useState(null); + const [bulkAction, setBulkAction] = useState(''); let outcomeTimeout = null; const getInfo = async () => { @@ -55,12 +53,6 @@ export default function Chat() { } }; - const updateMessage = message => { - const messageIndex = messages.findIndex(m => m.id === message.id); - messages.splice(messageIndex, 1, message) - setMessages([...messages]); - }; - useEffect(() => { getInfo(); return () => { @@ -77,13 +69,14 @@ export default function Chat() { }, }; - const handleBulkToggle = checked => { - setBulkVisibility(checked); - }; + const resetBulkOutcome = () => { - outcomeTimeout = setTimeout(() => { setBulkOutcome(null)}, OUTCOME_TIMEOUT); + outcomeTimeout = setTimeout(() => { + setBulkOutcome(null); + setBulkAction(''); + }, OUTCOME_TIMEOUT); }; - const handleSubmitBulk = async () => { + const handleSubmitBulk = async (bulkVisibility) => { setBulkProcessing(true); const result = await fetchData(UPDATE_CHAT_MESSGAE_VIZ, { auth: true, @@ -113,9 +106,15 @@ export default function Chat() { resetBulkOutcome(); } setBulkProcessing(false); - } - + const handleSubmitBulkShow = () => { + setBulkAction('show'); + handleSubmitBulk(true); + } + const handleSubmitBulkHide = () => { + setBulkAction('hide'); + handleSubmitBulk(false); + } const chatColumns: ColumnsType = [ { @@ -129,7 +128,7 @@ export default function Chat() { return format(dateObject, 'PP pp'); }, sorter: (a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime(), - width: 80, + width: 90, }, { title: 'User', @@ -146,57 +145,61 @@ export default function Chat() { {author} ), - width: 80, + width: 110, }, { title: 'Message', dataIndex: 'body', key: 'body', className: 'message-col', - width: 230, + width: 320, }, { - title: 'Show / Hide', + title: '', dataIndex: 'visible', key: 'visible', - filters: [{ text: 'visible', value: true }, { text: 'hidden', value: false }], + className: 'toggle-col', + filters: [{ text: 'Visible messages', value: true }, { text: 'Hidden messages', value: false }], onFilter: (value, record) => record.visible === value, - render: (visible, record) => ( - - ), - width: 60, + render: visible => visible ? null : , + width: 30, }, ]; + const bulkDivClasses = classNames({ + 'bulk-editor': true, + active: selectedRowKeys.length, + }); return (
Chat Messages -
+
Check multiple messages to change their visibility to: - - +
void, -}; - - -export default function MessageVisiblityToggle({ isVisible, message, setMessage }: MessageToggleProps) { - let outcomeTimeout = null; - const [outcome, setOutcome] = useState(0); - - const { id: messageId } = message; - - const resetOutcome = () => { - outcomeTimeout = setTimeout(() => { setOutcome(0)}, OUTCOME_TIMEOUT); - }; - - useEffect(() => { - return () => { - clearTimeout(outcomeTimeout); - }; - }); - - - const updateChatMessage = async () => { - clearTimeout(outcomeTimeout); - setOutcome(0); - const result = await fetchData(UPDATE_CHAT_MESSGAE_VIZ, { - auth: true, - method: 'POST', - data: { - visible: !isVisible, - idArray: [messageId], - }, - }); - - if (result.success && result.message === "changed") { - setMessage({ ...message, visible: !isVisible }); - setOutcome(1); - } else { - setMessage({ ...message, visible: isVisible }); - setOutcome(-1); - } - resetOutcome(); - } - - - let outcomeIcon = ; - if (outcome) { - outcomeIcon = outcome > 0 ? - : - ; - } - - return ( -
- {outcomeIcon} - -
- ); -} \ No newline at end of file diff --git a/web/styles/chat.scss b/web/styles/chat.scss index f9c1e94ee..e2c28d76c 100644 --- a/web/styles/chat.scss +++ b/web/styles/chat.scss @@ -6,6 +6,12 @@ .ant-table-tbody > tr > td { transition: background 0.15s; } + .ant-table-row.hidden { + .ant-table-cell { + color: #444450; + } + + } .ant-table-cell { font-size: 12px; @@ -13,6 +19,11 @@ text-overflow: ellipsis; overflow: hidden; } + &.toggle-col { + label { + font-size: 11px; + } + } } .bulk-editor { @@ -23,14 +34,23 @@ flex-direction: row; align-items: center; justify-content: flex-end; + border-radius: 4px; + + &.active { + .label { + color: #ccc; + } + } .label { font-size: .75rem; color: #666; + margin-right: .5rem; } - .toggler { - margin: 0 1rem 0 .5rem; + button { + margin: 0 .2rem; + font-size: .75rem; } } @@ -49,4 +69,4 @@ .outcome-icon { margin-right: .5rem; } -} \ No newline at end of file +}